Open2

GitHub Actions Tips

dehio3dehio3

終了コードにより後続のステップの実行可否を判断

例) masterブランチとのdevelopブランチに差分がある場合に、リリースブランチを作成する

jobs:
  create-release-branch:
    runs-on: ubuntu-latest
    steps:
      - name: checkout develop
        uses: actions/checkout@v2
        with:
          ref: develop

      - name: git diff
        id: git-diff
        run: |
          git fetch --quiet
          set +e
          git diff remotes/origin/master --exit-code
          exitCode=${?}
          set -e
          echo ${exitCode}
          echo ::set-output name=status_code::${exitCode}

      - name: create release branch
        if: steps.git-diff.outputs.status_code == 1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          git checkout -b "$RELEASE_BRANCH"
          git push origin "$RELEASE_BRANCH"

memo

dehio3dehio3

composite-action内でsteps-contextoutcomeconclusionがとれない

https://docs.github.com/en/actions/creating-actions/creating-a-composite-action

マニュアル上でのsteps-contextの値

  • steps.<step id>.outputs
  • steps.<step id>.conclusion
  • steps.<step id>.outcome
  • steps.<step id>.outputs.<output name>

https://docs.github.com/ja/actions/learn-github-actions/contexts#steps-context

検証

以下のステップを追加して確認

    - name: Dump steps context
      shell: bash
      env:
        STEPS_CONTEXT: ${{ toJSON(steps) }}
      run: echo "$STEPS_CONTEXT"

親のワークフローでの出力

  "plan": {
    "outputs": {
      "plan-stdout": "",
      "plan-stderr": "",
      "plan-exitcode": "0"
    },
    "outcome": "success",
    "conclusion": "success"
  }

steps-contextでの出力

  "plan": {
    "outputs": {
      "stdout": "",
      "stderr": "",
      "exitcode": "0"
    }
  }