diff --git a/.github/workflows/merge-main.yml b/.github/workflows/merge-main.yml index 8dc582826..9fce4d334 100644 --- a/.github/workflows/merge-main.yml +++ b/.github/workflows/merge-main.yml @@ -36,6 +36,36 @@ jobs: - name: Set PR Output run: echo "pr=${{ steps.pr.outputs.pr }}" >> $GITHUB_OUTPUT + create_release: + name: Create GitHub Release (Keep Version) + runs-on: ubuntu-22.04 + strategy: + matrix: + package: [backend, frontend, webeoc] + steps: + - uses: actions/checkout@v4 + + # Retrieve the latest tag (from the release branch) + - name: Get Latest Tag + id: tag + run: | + git fetch --tags + latest_tag=$(git describe --tags --abbrev=0 --match "v*.*.*") + echo "::set-output name=latest_tag::$latest_tag" + echo "Latest tag: $latest_tag" + + # Create GitHub Release using the last tag + - name: Create GitHub Release + uses: softprops/action-gh-release@v1 + with: + tag_name: ${{ steps.tag.outputs.latest_tag }} + name: Release ${{ steps.tag.outputs.latest_tag }} + body: | + ## Changes in this release: + - New features and bug fixes. + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # https://github.com/bcgov/quickstart-openshift-helpers deploy-prod: name: Deploy (prod) diff --git a/.github/workflows/pr-open.yml b/.github/workflows/pr-open.yml index 3bb7b6ba6..8e387ad7d 100644 --- a/.github/workflows/pr-open.yml +++ b/.github/workflows/pr-open.yml @@ -1,8 +1,12 @@ name: PR on: - pull_request: - + workflow_run: + workflows: ["PR Bump Version Workflow"] + types: + - completed + branches: + - release/** concurrency: # Cancel in progress for PR open and close group: ${{ github.event.number }} @@ -20,7 +24,6 @@ jobs: steps: - uses: bcgov-nr/action-builder-ghcr@v2.0.2 with: - keep_versions: 50 package: ${{ matrix.package }} tag: ${{ github.event.number }} tag_fallback: latest diff --git a/.github/workflows/pr-version-bump.yml b/.github/workflows/pr-version-bump.yml new file mode 100644 index 000000000..7e3f2dfa4 --- /dev/null +++ b/.github/workflows/pr-version-bump.yml @@ -0,0 +1,71 @@ +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]" + + - name: Pull latest changes before pushing + run: | + git pull --rebase origin ${{ github.head_ref }} + + # 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 diff --git a/backend/package.json b/backend/package.json index 5fa883561..920d5bd83 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "nr-compliance-enforcement", - "version": "0.0.1", + "version": "0.26.0", "description": "BCGov devops quickstart. For reference, testing and new projects.", "main": "index.js", "scripts": { diff --git a/frontend/package.json b/frontend/package.json index cce62e34f..8ff5c48d5 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { - "name": "nr-sample-natcomplaints", - "version": "1.0.1", + "name": "nr-natcomplaints", + "version": "0.26.0", "private": true, "dependencies": { "@faker-js/faker": "^8.0.2", diff --git a/webeoc/package.json b/webeoc/package.json index 325e71e99..0acdb5c04 100644 --- a/webeoc/package.json +++ b/webeoc/package.json @@ -1,6 +1,6 @@ { "name": "webeoc", - "version": "0.0.1", + "version": "0.26.0", "description": "", "author": "", "private": true,