GitHub Action
check-version-changed-rust
Useful in cases when you you want to automatically perform additional steps like creating a release and deploying/publishing the app if version is changed.
Not useful when you create releases manualy and trigger deploy/publish from the release or manually.
When the step runs, at the end, it saves in the cache the last commit in repo as since_commit
and the next time it runs it checks for version change since that commit.
Warning
If version is changed and you have 2 workflows that triger on push that inside are using this action, only first one that runs the check version step will see the version change, the second one will NOT, please keep this in mind when you design your workflows.
When running the step for the first time, as we dont' have since_commit
saved, it will compare the verison with latest release tag.
An example of such a workflow could be this:
- on
push
- run tests
- build
AUR
image (cargo aur)- if version changed
- create
release
, attach binaries asartifact
, url used inPKGBUILD
to distribute the binaries- publish to
AUR
- publish to
crates.io
- publish to
- create
- if version changed
- build docker image
- if version changed push it to
Docker Hub
- if version changed push it to
- build
- run tests
Warning
GITHUB_TOKEN
need to have Workflow Write permission
. For that got here (change OWNER
and REPO
) https://github.com/OWNER/REPO/settings/actions Actions -> General
and at the bottom in the Workflow permissions
section check Read and write permissions
.
This is needed because it saves the since_commit
in the cache between runs.
Name | Type | Description |
---|---|---|
changed | string | If the version has changed ('true' / 'false') |
version | string | The current version in version file |
prev_version | string | Last release version |
- id: check_version
uses: radumarias/action-check-version-changed-rust@v1
- run: |
echo "Prev version ${{ steps.check_version.outputs.prev_version }}"
echo "Version ${{ steps.check_version.outputs.version }}"
echo "Version has changed ${{ steps.check_version.outputs.changed }}"
- id: check_version
uses: radumarias/action-check-version-changed-rust@v1
- name: Execute if version has changed
if: steps.check_version.outputs.changed = 'true'
run: echo "Version has changed from ${{ steps.check_version.outputs.prev_version }} to ${{ steps.check_version.outputs.version }}"
jobs:
check_version:
name: Check version
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.check_version.outputs.changed }}
version: ${{ steps.check_version.outputs.version }}
prev_version: ${{ steps.check_version.outputs.prev_version }}
steps:
- uses: actions/checkout@v4
- id: check_version
uses: radumarias/action-check-version-changed-rust@v1
conditional_job:
name: Conditonal
needs: [check_version]
if: steps.check_version.outputs.changed = 'true'
runs-on: ubuntu-latest
steps:
- name: Version changed
run: echo "Version has changed from ${{ steps.check_version.outputs.prev_version }} to ${{ steps.check_version.outputs.version }}"
Feel free to fork it, change and use it in any way that you want. If you build something interesting and feel like sharing pull requests are always appreciated.
Please see CONTRIBUTING.md.