Open3
GitHub Actions Syntax
if always() の挙動について実験
needs
でJobを直列にしているとき、
if: always() && (needs.first_job.result == 'success' || needs.first_job.result == 'failure')
だとJobがスキップされる。
name: Check GitHub Actions Syntax
on:
workflow_dispatch:
jobs:
first_job:
name: First Job
runs-on: ubuntu-latest
if: false
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- name: Run
run: echo "Hello World"
second_job:
name: Second Job
runs-on: ubuntu-latest
needs: [first_job]
if: always() && (needs.first_job.result == 'success' || needs.first_job.result == 'failure')
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- name: Run
run: echo "Hello World"
needs
でJobを直列しているとき、
if: always() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled')
だとJobが実行された。
name: Check GitHub Actions Syntax
on:
workflow_dispatch:
jobs:
first_job:
name: First Job
runs-on: ubuntu-latest
if: false
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- name: Run
run: echo "Hello World"
second_job:
name: Second Job
runs-on: ubuntu-latest
needs: [first_job]
if: always() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled')
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- name: Run
run: echo "Hello World"
結論
-
always()
はneeds
で指定しているJobがスキップされてもそれは無視して突破する力を持つ - ただし、
needs
で指定しているJobの結果をちゃんと待ってくれる
if failure() の挙動について実験
Jobレベルでif: !failure()
をしたときにひとつ前のJobまでが範囲なのかそれまでのJob全てが範囲なのかを検証したい。
name: Check GitHub Actions Syntax
on:
workflow_dispatch:
jobs:
first_job:
name: First Job
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- name: Run
run: exit 1
second_job:
name: Second Job
runs-on: ubuntu-latest
needs: [first_job]
if: always()
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- name: Run
run: echo "Hello World"
third_job:
name: Third Job
runs-on: ubuntu-latest
needs: [second_job]
if: ${{ !failure() }}
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- name: Run
run: echo "Hello World"
こうすると
- first_job: ❌ failure
- second_job: ✅ success
- third_job: 🚫 skipped
となるので、範囲はそれまでのJob全てである
if failure() の挙動について実験2
needs
で指定しているJobがSkippedだったとしてもJobが動くかどうか検証。
name: Check GitHub Actions Syntax
on:
workflow_dispatch:
jobs:
first_job:
name: First Job
runs-on: ubuntu-latest
if: false
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- name: Run
run: echo "Hello World"
second_job:
name: Second Job
runs-on: ubuntu-latest
if: false
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- name: Run
run: echo "Hello World"
third_job:
name: Third Job
runs-on: ubuntu-latest
needs: [first_job, second_job]
if: ${{ !failure() && !cancelled() }}
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- name: Run
run: echo "Hello World"
- first_job: 🚫 skipped
- second_job: 🚫 skipped
- third_job: ✅ success
となったので、always()
を使わなくても十分効果を発揮できそう。