iT邦幫忙

2023 iThome 鐵人賽

DAY 23
0
自我挑戰組

自己的 Leak, 自己抓(swift)系列 第 23

繼續導入 github action

  • 分享至 

  • xImage
  •  

於是我們繼續導入 github ation

預期的期望是在 PR 時,能夠執行一次並留下紀錄


An option to highlight a "Note" and "Warning" using blockquote (Beta)

> [!WARNING]
> Line: 24

PR 預覽

https://github.com/yume190/LeakDetector/blob/a9a4eddeb0c9f9aee6ebd7643f4971af39b02e1d/LeakDetectorDemo/Leak/Animate/AnimatorViewController.swift#L22-L26

預覽參數

這邊我們缺的參數只剩下 commit, repo

  • repo: yume190/LeakDetector
  • commit: a9a4eddeb0c9f9aee6ebd7643f4971af39b02e1d
  • path: LeakDetectorDemo/Leak/Animate/AnimatorViewController.swift
  • position: #L22-L26
    • from: L22
    • to: L26

預覽效果

https://ithelp.ithome.com.tw/upload/images/20231007/201580307nWMq5fVcL.png


action.yml

所以我們可以在 action.yml 定義 inputs

並且有些參數可以事先定義預設值(直接從 github action 取得)

可以參考 Context, 如 ${{github.repository}}

最後可以在 runs: 定義 action

name: Leak Detect
description: Detect Potential Leaks.
inputs:
  sha:
    description: 'The commit you test'
    required: true
    default: ${{github.event.after}}

  repo:
    description: 'The repo you test'
    required: true
    default: ${{github.repository}}

  token:
    description: 'Github token'
    required: true

  issue:
    description: 'Github issue id'
    required: true
    default: ${{github.event.number}}

  sdk:
    description: '[macosx|appletvos|watchsimulator|iphonesimulator|appletvsimulator|iphoneos|watchos]'
    required: true
    default: ''

  module:
    description: 'XCode Scheme Name/SPM Target name'
    required: true
    default: ''

  file:
    description: 'xxx.xcworkspace/xxx.xcodeproj/xxx.swift'
    required: true
    default: ''

  skip:
    description: 'skip list'
    required: true
    default: '.leakdetect.yml'

runs:
  using: 'composite'
  steps:
    - name: Download LeakDectect
      shell: bash
      run: |
        # TEMP_DIR=$(mktemp -d)
        curl -sSL \
          "https://github.com/yume190/LeakDetect/releases/download/0.0.8/leakDetect" \
          -o leakDetect
        chmod +x leakDetect

    - name: Detect Single File
      if: ${{ inputs.sdk != '' }}
      env:
          sha: ${{ inputs.sha }}
          repository: ${{ inputs.repo }}
          auth: ${{ inputs.token }}
          issue: ${{ inputs.issue }}
      shell: bash
      run: |
        ./leakDetect \
          --reporter custom \
          --github \
          --skip ${{inputs.skip}} \
          --sdk ${{inputs.sdk}} \
          --file ${{inputs.file}}

    - name: Detect Module
      if: ${{ inputs.module != '' }}
      env:
          sha: ${{ inputs.sha }}
          repository: ${{ inputs.repo }}
          auth: ${{ inputs.token }}
          issue: ${{ inputs.issue }}
      shell: bash
      run: |
        ./leakDetect \
          --reporter custom \
          --github \
          --skip ${{inputs.skip}} \
          --module ${{inputs.module}} \
          --file ${{inputs.file}}

使用 Custom github action

# This workflow will build a Swift project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift

name: Swift

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  build:

    runs-on: macos-latest

    steps:
    - uses: actions/checkout@v3
    - uses: yume190/LeakDetect@0.0.8
      with:
        module: LeakDetectorDemo
        file: LeakDetectorDemo.xcworkspace
        token: ${{secrets.GITHUB_TOKEN}}

上一篇
導入 Danger?
下一篇
番外: swift demangle
系列文
自己的 Leak, 自己抓(swift)30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言