GitHub reusable workflow: use latest commit

Viewed 2353

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?

3 Answers

Unfortunatelly, it's not possible to use expressions with uses now.

One possible workaround (that I used for myself) is to push reusable workflow(s) to one of the stable branches (main/master/develop/etc.) and use SHA as a ref.

Additional benefit here is that using SHA is actually the recommended way described here.

Related