GitHub Actions Reusable Workflows
GitHub Actionsでworkflowを再利用できる
ただし再利用できるのは以下のみ
public repositoryのworkflow
同一repositoryの別workflow
同一organizationまたはuserのprivate repositoryのworkflow (2022-12-14~)l
https://docs.github.com/en/actions/learn-github-actions/reusing-workflows
再利用方法
再利用したいworkflowに以下を記述
code:yaml
on:
workflow_call:
inputsやsecretsを受け取り、workflow内で使える
code:yaml
on:
workflow_call:
inputs:
username:
required: true
type: string
secrets:
envPAT:
required: true
jobs:
reusable_workflow_job:
runs-on: ubuntu-latest
environment: production
steps:
- uses: ./.github/actions/my-action@v1
with:
username: ${{ inputs.username }}
token: ${{ secrets.envPAT }}
呼び出す側は対象のrepositoryとYAMLへのパスを指定するだけでよい
code:yaml
jobs:
call-workflow-passing-data:
uses: octo-org/example-repo/.github/workflows/reusable-workflow.yml@main
with:
username: mona
secrets:
envPAT: ${{ secrets.envPAT }}
参考
https://github.blog/changelog/2022-12-14-github-actions-sharing-actions-and-reusable-workflows-from-private-repositories-is-now-ga/
https://github.blog/changelog/2021-11-24-github-actions-reusable-workflows-are-generally-available/
github actions Reusable workflowsが実装されたのでざっとまとめ