name: Bump version.txt on: push: branches: [ "main" ] # Avoid infinite loop when this workflow commits version.txt. paths-ignore: - "version.txt" concurrency: group: bump-version-${{ github.ref }} cancel-in-progress: true permissions: contents: write jobs: bump: if: github.actor != 'github-actions[bot]' runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 - name: Bump patch version in version.txt shell: bash run: | set -euo pipefail file="version.txt" if [[ ! -f "$file" ]]; then echo "0.0.1" > "$file" else v="$(tr -d '[:space:]' < "$file")" if [[ "$v" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then major="${BASH_REMATCH[1]}" minor="${BASH_REMATCH[2]}" patch="${BASH_REMATCH[3]}" patch="$((patch + 1))" echo "${major}.${minor}.${patch}" > "$file" else echo "version.txt has invalid format: '$v' (expected x.y.z)" >&2 exit 1 fi fi echo "New version: $(cat "$file")" - name: Commit and push shell: bash run: | set -euo pipefail git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" # If version didn't change for any reason, do nothing. git add version.txt if git diff --cached --quiet; then echo "No changes to commit." exit 0 fi git commit -m "chore: bump version [skip ci]" git push