Skip to content
activity

GitHub Action

check-version-changed-rust

v1 Latest version

check-version-changed-rust

activity

check-version-changed-rust

Checks if the version has changed since last release

Installation

Copy and paste the following snippet into your .yml file.

              

- name: check-version-changed-rust

uses: radumarias/action-check-version-changed-rust@v1

Learn more about this action in radumarias/action-check-version-changed-rust

Choose a version

Checks if the version in Cargo.toml has changed since last time the job runned for a Rust project

Tests

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 as artifact, url used in PKGBUILD to distribute the binaries
            • publish to AUR
            • publish to crates.io
      • build docker image
        • if version changed push it to Docker Hub

workflow

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.

Usage

Outputs

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

Example

    - 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 }}"

Conditional step

    - 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 }}"

Conditional job

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 }}"

Contribute

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.

How to contribute

Please see CONTRIBUTING.md.