GitHub Actions で特定 OS の時だけ処理をスキップする

March 26, 2023

github-actions

GitHub Actions で特定 OS 上でのビルド時だけ処理を変更する

例えば、Windows OS 上での実行時に特定処理をスキップさせる場合は以下の例のように if: runner.os != 'Windows' を使えば良い。if: matrix.os != 'windows-latest'if: matrix.runs-os != 'windows-latest' という書き方もできるらしいが、私の手元ではスキップさせることができなかったので runner.os を使用している。

name: Release
on:
  push:
    tags:
      - '[0-9]+.[0-9]+.[0-9]+'
jobs:
  compile:
    name: dart compile exe
    strategy:
      matrix:
        include:
          - runs-on: ubuntu-latest
            binary-name: dartcli_linux_amd64
          - runs-on: macos-latest
            binary-name: dartcli_macos_amd64
          - runs-on: windows-latest
            binary-name: dartcli_windows.exe
    runs-on: ${{ matrix.runs-on }}
    steps:
      - uses: actions/checkout@v3
      - uses: dart-lang/setup-dart@v1
      - run: dart pub get
      - run: dart pub global activate completion
      - run: mkdir ${{ matrix.runs-on }}
      - run: dart compile exe bin/dartcli.dart -o ${{ matrix.runs-on }}/${{ matrix.binary-name }}
      - if: runner.os != 'Windows'
        run: cd ${{ matrix.runs-on }} && shell_completion_generator ${{ matrix.binary-name }} > ${{ matrix.binary-name }}_completion.sh && cd ..

以上。