Skip to content

feat: CE-882 versioning on prod releases #6

feat: CE-882 versioning on prod releases

feat: CE-882 versioning on prod releases #6

Workflow file for this run

name: PR Bump Version Workflow
on:
pull_request:
types: [opened]
branches:
- release/**
concurrency:
# Cancel in progress for PR open and close
group: ${{ github.event.number }}
cancel-in-progress: true
jobs:
bump_version:
name: Bump Version for Release Branch
runs-on: ubuntu-22.04
strategy:
matrix:
package: [backend, frontend, webeoc]
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Install jq (JSON parser)
run: sudo apt-get install -y jq
# Check if it's the first PR into the release branch (no existing tags)
- name: Check for existing tags
id: check_tag
run: |
git fetch --tags
latest_tag=$(git describe --tags --abbrev=0 --match "v*.*.*" || echo "none")
echo "::set-output name=latest_tag::$latest_tag"
# Bump minor version and reset patch for first PR
- name: Bump minor version and reset patch for first PR
if: ${{ steps.check_tag.outputs.latest_tag == 'none' }}
run: |
cd ${{ matrix.package }}
current_version=$(jq -r '.version' package.json)
new_version=$(echo $current_version | awk -F. '{$2+=1; $3=0; print $1"."$2"."$3}')
jq --arg v "$new_version" '.version = $v' package.json > package.json.tmp && mv package.json.tmp package.json
echo "First PR: Resetting patch and bumping minor. New version: $new_version"
# Bump patch version for subsequent PRs
- name: Bump patch version for subsequent PRs
if: ${{ steps.check_tag.outputs.latest_tag != 'none' }}
run: |
cd ${{ matrix.package }}
current_version=$(jq -r '.version' package.json)
new_version=$(echo $current_version | awk -F. '{$3+=1; print $1"."$2"."$3}')
jq --arg v "$new_version" '.version = $v' package.json > package.json.tmp && mv package.json.tmp package.json
echo "Subsequent PR: Bumping patch. New version: $new_version"
- name: Set Git Identity
run: |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
# Commit and push version bump
- name: Commit and push version bump
run: |
git add ${{ matrix.package }}/package.json
git commit -m "chore(${{ matrix.package }}): bump version."
git push origin HEAD:refs/heads/${{ github.head_ref }} # Push to the branch associated with the PR
# Pull the latest changes with rebase before pushing
- name: Pull latest changes with rebase before pushing
run: |
git pull --rebase origin ${{ github.head_ref }}
# Push the rebased version bump with retry on failure
- name: Push rebased version bump with retry
run: |
git push origin HEAD:refs/heads/${{ github.head_ref }} || (
echo "Push failed, retrying..." &&
git pull --rebase origin ${{ github.head_ref }} &&
git push origin HEAD:refs/heads/${{ github.head_ref }}
)