name: Update Version File on: push: branches: - main # Or whichever branch you want to monitor jobs: update-version: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v3 - name: Set up Git run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" - name: Get the latest tag id: get_latest_tag run: | latest_tag=$(git describe --tags --abbrev=0) echo "Latest tag is: $latest_tag" echo "::set-output name=tag::$latest_tag" - name: Get the latest commit hash id: get_commit_hash run: | commit_hash=$(git rev-parse --short HEAD) echo "Commit hash is: $commit_hash" echo "::set-output name=commit_hash::$commit_hash" - name: Update version file run: | latest_tag=${{ steps.get_latest_tag.outputs.tag }} commit_hash=${{ steps.get_commit_hash.outputs.commit_hash }} echo "package main" > version.go echo "" >> version.go echo "var version = \"${latest_tag}-${commit_hash}\"" >> version.go - name: Commit changes run: | git add version.go git commit -m "Update version to ${{ steps.get_latest_tag.outputs.tag }} and commit ${{ steps.get_commit_hash.outputs.commit_hash }}" git push origin main # Or the relevant branch