feat: CE-882 versioning on prod releases #8
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 the 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 | |
# Pull the latest changes from the release branch before version bump | |
- name: Pull latest changes with rebase | |
run: git pull --rebase origin ${{ github.base_ref }} | |
# Get the latest global tag (from previous releases) | |
- name: Get latest global tag | |
id: check_tag | |
run: | | |
git fetch --tags | |
latest_tag=$(git tag --sort=-creatordate | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1 || echo "none") | |
echo "::set-output name=latest_tag::$latest_tag" | |
echo "Latest global tag: $latest_tag" | |
# Get the current version from package.json | |
- name: Get version from package.json | |
id: get_version | |
run: | | |
cd ${{ matrix.package }} | |
current_version=$(jq -r '.version' package.json) | |
echo "::set-output name=current_version::$current_version" | |
echo "Current version in package.json: $current_version" | |
# Compare current version with the latest tag to determine if it's the first PR | |
- name: Determine if it's the first PR | |
id: compare_version | |
run: | | |
current_version=${{ steps.get_version.outputs.current_version }} | |
latest_tag=${{ steps.check_tag.outputs.latest_tag }} | |
if [[ "$current_version" == "$latest_tag" ]]; then | |
echo "First PR for this release branch" | |
echo "::set-output name=first_pr::true" | |
else | |
echo "Subsequent PR" | |
echo "::set-output name=first_pr::false" | |
fi | |
# Bump minor version and reset patch for first PR into release branch | |
- name: Bump minor version and reset patch for first PR | |
if: ${{ steps.compare_version.outputs.first_pr == 'true' }} | |
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 into release branch | |
- name: Bump patch version for subsequent PRs | |
if: ${{ steps.compare_version.outputs.first_pr == 'false' }} | |
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" | |
# Upload the updated package.json file | |
- name: Upload updated package.json | |
uses: actions/upload-artifact@v3 | |
with: | |
name: updated-package-${{ matrix.package }} | |
path: ${{ matrix.package }}/package.json | |
commit_and_push: | |
name: Commit and Push All Changes | |
runs-on: ubuntu-22.04 | |
needs: bump_version # Wait for the bump_version job to complete | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.head_ref }} | |
# Download all updated package.json files from the matrix jobs | |
- name: Download updated package.json files | |
uses: actions/download-artifact@v3 | |
with: | |
name: updated-package-backend | |
path: backend/ | |
- name: Download updated frontend package.json | |
uses: actions/download-artifact@v3 | |
with: | |
name: updated-package-frontend | |
path: frontend/ | |
- name: Download updated webeoc package.json | |
uses: actions/download-artifact@v3 | |
with: | |
name: updated-package-webeoc | |
path: webeoc/ | |
# Set Git Identity | |
- 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 all changes at once | |
- name: Commit and push all changes | |
run: | | |
git add backend/package.json frontend/package.json webeoc/package.json | |
git commit -m "chore: bump versions for backend, frontend, and webeoc" | |
git push origin HEAD:refs/heads/${{ github.head_ref }} # Push to the same branch |