I'm setting up a reusable workflow using GitHub actions: https://docs.github.com/en/actions/learn-github-actions/reusing-workflows
Since the calling workflow and called workflow are both in the same repo, I want to reference the latest commit of the called workflow inside my calling workflow's uses
statement.
Example:
uses: owner/repo/.github/workflows/called-workflow.yml@${{GITHUB_SHA}}
That ${{GITHUB_SHA}}
doesn't get interpolated, so I get the following error:
Invalid workflow file : .github/workflows/calling-workflow.yml#L1
handling usage of workflow "owner/repo/.github/workflows/called-workflow.yml@${{GITHUB_SHA}}": can't obtain workflow file: reference to workflow should be either a valid branch, tag, or commit
How can I set the ref
to the latest commit when calling a workflow within a workflow?
If you have a reusable workflow in a private repository, only other workflows in that private repository can use it. Reusable workflows can't be stacked on top of one another. You can only have a reusable workflow call another reusable workflow, but you can't have it reference more than one.
You call a reusable workflow by using the uses keyword. Unlike when you are using actions within a workflow, you call reusable workflows directly within a job, and not from within job steps. You reference reusable workflow files using one of the following syntaxes: {owner}/{repo}/.
To run jobs sequentially, you can define dependencies on other jobs using the jobs. <job_id>. needs keyword. Each job runs in a runner environment specified by runs-on .
As of February 2022.
First in January: https://github.blog/changelog/2022-01-25-github-actions-reusable-workflows-can-be-referenced-locally/
Up until today-ish though (2022-Feb-10), there was a bug that prevented it from working on pull_request
events; that has now been fixed:
https://github.community/t/ref-head-in-reusable-workflows/203690/74?u=briantist
Example usage:
jobs:
call-workflow-in-local-repo:
uses: ./.github/workflows/workflow-2.yml
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With