Skip to content

Commit 73d866e

Browse files
authored
Merge pull request #1302 from CDLUC3/chore/271/JS-automate-versioning
Added Github Action workflows to automate versioning
2 parents 2e337d0 + 8050390 commit 73d866e

4 files changed

Lines changed: 158 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Validate Version Label
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
types:
8+
- opened
9+
- synchronize
10+
- reopened
11+
- labeled
12+
- unlabeled
13+
14+
jobs:
15+
validate:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Validate version label
20+
env:
21+
LABELS: ${{ join(github.event.pull_request.labels.*.name, ',') }}
22+
run: |
23+
24+
HAS_MAJOR=0
25+
HAS_MINOR=0
26+
HAS_PATCH=0
27+
28+
[[ "$LABELS" == *"version:major"* ]] && HAS_MAJOR=1
29+
[[ "$LABELS" == *"version:minor"* ]] && HAS_MINOR=1
30+
[[ "$LABELS" == *"version:patch"* ]] && HAS_PATCH=1
31+
32+
COUNT=$((HAS_MAJOR + HAS_MINOR + HAS_PATCH))
33+
34+
echo "Version labels found:"
35+
echo " major=$HAS_MAJOR"
36+
echo " minor=$HAS_MINOR"
37+
echo " patch=$HAS_PATCH"
38+
39+
if [ "$COUNT" -eq 0 ]; then
40+
echo "::error::No version label found. Add exactly one of: version:major, version:minor, or version:patch"
41+
exit 1
42+
fi
43+
44+
if [ "$COUNT" -gt 1 ]; then
45+
echo "::error::PR contains multiple version labels. Select exactly one of: version:major, version:minor, or version:patch"
46+
exit 1
47+
fi
48+
49+
echo "Valid version label found."

.github/workflows/versioning.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Automated Versioning
2+
on:
3+
pull_request:
4+
types:
5+
- closed
6+
branches:
7+
- main
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
version:
14+
if: github.event.pull_request.merged == true
15+
#GitHub-hosted runner with Ubuntu
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
with:
22+
ref: ${{ github.event.pull_request.base.ref }}
23+
fetch-depth: 0
24+
token: ${{ secrets.GITHUB_TOKEN }}
25+
26+
- name: Setup Node
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: 22
30+
31+
- name: Determine version bump
32+
id: bump
33+
env:
34+
LABELS: ${{ join(github.event.pull_request.labels.*.name, ',') }}
35+
36+
run: |
37+
if [[ "$LABELS" == *"version:major"* ]]; then
38+
echo "type=major" >> $GITHUB_OUTPUT
39+
elif [[ "$LABELS" == *"version:minor"* ]]; then
40+
echo "type=minor" >> $GITHUB_OUTPUT
41+
elif [[ "$LABELS" == *"version:patch"* ]]; then
42+
echo "type=patch" >> $GITHUB_OUTPUT
43+
else
44+
echo "type=patch" >> $GITHUB_OUTPUT
45+
fi
46+
47+
- name: Bump version
48+
run: |
49+
npm version ${{ steps.bump.outputs.type }} --no-git-tag-version
50+
51+
- name: Get new version
52+
id: version
53+
run: |
54+
VERSION=$(node -p "require('./package.json').version")
55+
echo "version=$VERSION" >> $GITHUB_OUTPUT
56+
57+
- name: Update changelog
58+
run: |
59+
VERSION="${{ steps.version.outputs.version }}"
60+
61+
{
62+
echo "## v${VERSION}"
63+
echo ""
64+
echo "### Added"
65+
echo ""
66+
echo "### Updated"
67+
echo ""
68+
echo "### Fixed"
69+
echo ""
70+
echo "### Removed"
71+
echo ""
72+
echo "### Chore"
73+
echo ""
74+
cat CHANGELOG.md
75+
} > CHANGELOG.tmp
76+
77+
mv CHANGELOG.tmp CHANGELOG.md
78+
79+
- name: Commit changes
80+
run: |
81+
git config user.name "github-actions"
82+
git config user.email "github-actions@github.com"
83+
84+
git add package.json CHANGELOG.md
85+
86+
git commit -m "chore: release v${{ steps.version.outputs.version }}" || exit 0
87+
88+
git tag -f "v${{ steps.version.outputs.version }}"
89+
90+
git push origin HEAD:${{ github.event.pull_request.base.ref }}
91+
git push --tags --force

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
- Fixed issue with Feedback Notification headers displaying for any collaborator on the Plan Overview, Section and Question pages. It should only display to Org Admins and Super Admins. Added shared isOrgAdmin hook for pages. [#249]
5151

5252
## Chore
53+
- Added Github Action workflows `versioning.yml` and `validation-version-label.yml` to automate versioning when merging from `development` into `stage`. [#271]
5354
- Addressed `shell-quote` vulnerability by running `npm audit fix` to update `package-lock.json` [#278]
5455
- Updated `tinymce` to `v7.9.3` due to high vulnerabilities [#276]
5556
- Updated `@apollo/client` to `v4.2.0`, `dompurify` to `v3.4.6`, `@types/react` to `v18.3.29`, `react` to `v19.2.6`, `react-dom` to `v19.2.6`, `@types/node` to `v24.12.4`, `@dmptool/types` to `v3.1.5`, `postcss` to `v8.5.15`, and `tmp` to `v0.2.7`. Removed `@eslint-plugin-kit` override, and added `qs` override to address security vulnerability. Updated `zod` to `v4.4.3` to match the version in updated `@dmptool/types`, otherwise I get errors.

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
- [Testing](#testing)
2121
- [API Routes](#api-routes)
2222
- [Working with GraphQL](#working-with-graphql)
23+
- [Automated Versioning](#automated-versioning)
2324
- [Contributing](#contributing)
2425
- [Contributors](#contributors)
2526
- [License](#license)
@@ -341,6 +342,22 @@ We use the `@apollo/client` package to manage the connection with Apollo Server.
341342

342343
The `lib/graphql/graphqlHelper.ts` file provides logic for handling retries and processing GraphQL errors from Apollo Server.
343344

345+
## Automated Versioning
346+
This project uses GitHub Actions to automatically manage version bumping and changelog updates whenever a pull request is merged from `development` into `stage`.
347+
348+
### How It Works
349+
Two workflows handle versioning:
350+
1. Validate Version Label - Runs on every PR opened or updated against `stage`. If there is a version label applied, it will use that to determine the new version. If no label is applied, it will automatically do a `patch` version update.
351+
2. Automated Versioning - Runs when a PR is merged into `stage`. It reads the version label, bumps `package.json` using `npm version`, prepends a new section to `CHANGELOG.md`, commits both files, and pushes a Git tag. The command and tag are pushed directly to the `stage` branch by `github-actions`.
352+
353+
### PR Labels
354+
When opening a PR from `development` to `stage`, you can apply one of the following labels. Labels can be found in the "Labels" dropdown on the PR page's right sidebar.
355+
356+
| Label | When to use |
357+
|---------------|-------------------------------------------------------------------------|
358+
| version:major | Breaking changes or significant new features (e.g., 1.0.0 -> 2.0.0) |
359+
| version:minor | New backwards-compatible functionality (e.g., 1.0.0 -> 1.1.0) |
360+
| version:patch | Bug fixes and minor backwards-compatible changes (e.g., 1.0.0 -> 1.0.1) |
344361

345362
## Contributing
346363
1. Clone the repo from github (`git clone git@github.com:CDLUC3/dmsp_frontend_prototype.git`)

0 commit comments

Comments
 (0)