Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: CE-882 versioning on prod releases #642

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
dfbff2d
Added github actions for tags
barrfalk Sep 13, 2024
42da105
Update merge-main.yml
barrfalk Sep 13, 2024
ecb1d54
Restructured PR workflows
barrfalk Sep 16, 2024
32e2170
Update pr-version-bump.yml
barrfalk Sep 16, 2024
ecc5138
Update pr-version-bump.yml
barrfalk Sep 16, 2024
2209262
Update pr-version-bump.yml
barrfalk Sep 16, 2024
7972736
Update pr-version-bump.yml
barrfalk Sep 16, 2024
1bc5dbe
Update pr-version-bump.yml
barrfalk Sep 16, 2024
8d2937a
Update pr-version-bump.yml
barrfalk Sep 16, 2024
aae2ba8
Update pr-version-bump.yml
barrfalk Sep 16, 2024
9bc8761
chore(backend): bump version.
github-actions[bot] Sep 16, 2024
a80b2e4
Update pr-version-bump.yml
barrfalk Sep 16, 2024
d8dcf03
Update package.json
barrfalk Sep 16, 2024
176df47
Update pr-version-bump.yml
barrfalk Sep 16, 2024
9fa7dc0
Update pr-version-bump.yml
barrfalk Sep 16, 2024
e6ec706
chore(backend): bump version.
github-actions[bot] Sep 16, 2024
d6c67db
Retry pushing changes
barrfalk Sep 16, 2024
df595e6
chore(frontend): bump version.
github-actions[bot] Sep 16, 2024
af0517d
wip
barrfalk Sep 16, 2024
1a6209e
chore: bump versions for backend, frontend, and webeoc
github-actions[bot] Sep 16, 2024
0137f4a
Testing tag
barrfalk Sep 16, 2024
0d6aa9a
Update pr-open.yml
barrfalk Sep 16, 2024
1111ae0
Update pr-open.yml
barrfalk Sep 16, 2024
fbf1a84
Update pr-open.yml
barrfalk Sep 16, 2024
a2a9879
Update pr-open.yml
barrfalk Sep 16, 2024
c5da688
Update pr-open.yml
barrfalk Sep 16, 2024
4d0e59f
Update pr-version-bump.yml
barrfalk Sep 16, 2024
ce7eaf8
Update pr-version-bump.yml
barrfalk Sep 16, 2024
83c3f59
Merge branch 'release/lewis-moon-snail' into CE-882-Versioning-on-Pro…
barrfalk Sep 16, 2024
ee8f64c
Create release-branch-creation.yml
barrfalk Sep 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/merge-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/merge-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,34 @@ jobs:
- name: Set PR Output
run: echo "pr=${{ steps.pr.outputs.pr }}" >> $GITHUB_OUTPUT

create-tag:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4

- name: Install jq (JSON parser)
run: sudo apt-get install -y jq

# Get version from package.json
- name: Get version from package.json
id: get_version
run: |
version=$(jq -r '.version' backend/package.json) # Assuming all package.json files have the same version
echo "Version: $version"
echo "::set-output name=version::$version"

# Set Git Identity for tagging
- 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]"

# Create a tag based on the version from package.json
- name: Create Git Tag
run: |
git tag "v${{ steps.get_version.outputs.version }}"
git push origin "v${{ steps.get_version.outputs.version }}"

# https://github.com/bcgov/quickstart-openshift-helpers
deploy-test:
name: Deploy (test)
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/pr-open.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: PR

on:
pull_request:
branches:
- release/**

concurrency:
# Cancel in progress for PR open and close
Expand All @@ -20,7 +22,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
Expand Down
130 changes: 130 additions & 0 deletions .github/workflows/pr-version-bump.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: PR Bump Version Workflow

on:
pull_request:
types: [opened]
branches:
- release/**

concurrency:
# Cancel in progress for PR open and close
group: ${{ github.workflow }}-${{ 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
52 changes: 52 additions & 0 deletions .github/workflows/release-branch-creation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Create New Tag on Release Branch Creation

on:
create:

jobs:
bump_minor_version:
name: Bump Minor Version and Create New Tag
runs-on: ubuntu-22.04
# Only trigger for main release branches
if: startsWith(github.ref, 'refs/heads/release/') && !contains(github.ref, '/')
steps:
- uses: actions/checkout@v4

- name: Install npm
run: sudo apt-get install -y npm

# Fetch the latest tag (sort by creation date)
- name: Fetch latest tag
id: latest_tag
run: |
git fetch --tags
latest_tag=$(git tag --sort=-creatordate | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)
if [ -z "$latest_tag" ]; then
echo "No previous tags found, starting with v0.1.0"
latest_tag="v0.0.0"
fi
echo "::set-output name=latest_tag::$latest_tag"
echo "Latest tag: $latest_tag"

# Bump the minor version and reset the patch to 0
- name: Bump minor version
id: bump_version
run: |
latest_tag="${{ steps.latest_tag.outputs.latest_tag }}"
# Extract major, minor, and patch versions
version_array=(${latest_tag//./ })
major_version=${version_array[0]//v/}
minor_version=${version_array[1]}
patch_version=${version_array[2]}
# Increment minor version and reset patch
new_minor_version=$((minor_version + 1))
new_version="v${major_version}.${new_minor_version}.0"
echo "::set-output name=new_version::$new_version"
echo "New version: $new_version"

# Create a new tag with the bumped minor version
- name: Create and push the new tag
run: |
new_version="${{ steps.bump_version.outputs.new_version }}"
git tag "$new_version"
git push origin "$new_version"
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nr-compliance-enforcement",
"version": "0.0.1",
"version": "0.27.0",
"description": "BCGov devops quickstart. For reference, testing and new projects.",
"main": "index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nr-sample-natcomplaints",
"version": "1.0.1",
"name": "nr-natcomplaints",
"version": "0.27.0",
"private": true,
"dependencies": {
"@faker-js/faker": "^8.0.2",
Expand Down
2 changes: 1 addition & 1 deletion webeoc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webeoc",
"version": "0.0.1",
"version": "0.27.0",
"description": "",
"author": "",
"private": true,
Expand Down
Loading