Reputation: 4686
Is it possible to pass in a dynamic version to an action? Below [dynamic version]
is what I would want populated from either an input
or env
or some other way.
- name: Run action with dynamic version
uses: org1/repo1/.github/actions/my-action1@[dynamic version]
- name: Run action with dynamic version
uses: org1/repo1/.github/actions/my-action2@[dynamic version]
For more information, we have several internal actions where all the versions are the same (coming from same repo). We move the versions at the same time and thought it would be convenient to have some way to specify this once.
Upvotes: 5
Views: 3168
Reputation: 856
@rethab's answer, which recommends using major version tags (like @v1
instead of @v1.2.3
or @git-commit-hash
) is probably the most convenient way of doing things.
However, in the rare case you actually need to specify a dynamic version on a GitHub Action (e.g. you want to exact same version for both an action and a pip package, or you're testing your own GitHub Action), you can use the jenseng/dynamic-uses
action, like so:
- uses: jenseng/dynamic-uses@v1
with:
# now you can use expressions 🥳
uses: actions/setup-node@${{ inputs.version }}
# the `with` needs to be converted to a valid json string
with: '{ "node-version": 18 }'
There's some discussion from GitHub staff members on why steps.uses
doesn't support expressions in https://github.com/actions/runner/issues/895. If GitHub Actions ever does support expressions in steps.uses
, someone will probably comment it there, so subscribe to that thread if you want updates.
Upvotes: 6
Reputation: 8443
You probably want to use semantic versioning for your actions and create a major version for consumers to use.
Semantic versioning essentially allows all users of your actions to reference only the major version and profit from patches and new features as they are released. At the same time, your users need to manually update the reference on breaking changes as that would change the major tag.
In practice, this means:
v1.0.0
v1
that points to the same commitv1.0.1
v1
to point to the new commit (typically delete it & recreate)This is a clunky process, but this is what most authors do.
If this for some reason doesn't satisfy your requirements, you could also think about always using the @main
reference. This is generally not advised for public actions as changes might break your workflows, but in a controlled internal environment this might be fine.
Lastly, note that dependabot can create PRs in your repositories when there's a new version of actions you're using. I have detailed more on this in a previous answer: https://stackoverflow.com/a/70196496/1080523
Upvotes: 3