Skip to content

Commit 685727f

Browse files
chore: support release branches in CI workflows (#111)
- publish-npm.yml: trigger on release-* branches, publish with branch name as npm dist-tag so `latest` stays on main - pr-build-and-check.yml: accept PRs targeting release-* branches, use dynamic base ref instead of hardcoded origin/main Assisted-by: Claude Code Co-Authored-By: Claude Code
1 parent 4434981 commit 685727f

2 files changed

Lines changed: 38 additions & 14 deletions

File tree

.github/workflows/pr-build-and-check.yml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
pull_request:
55
branches:
66
- main
7+
- release-*
78

89
jobs:
910
build:
@@ -48,8 +49,10 @@ jobs:
4849
- name: Check for docs changes
4950
id: docs-changes
5051
working-directory: .
52+
env:
53+
BASE_REF: origin/${{ github.base_ref }}
5154
run: |
52-
DOCS_CHANGED=$(git diff --name-only origin/main...HEAD -- docs/ | grep '\.md$' || true)
55+
DOCS_CHANGED=$(git diff --name-only "$BASE_REF"...HEAD -- docs/ | grep '\.md$' || true)
5356
if [ -z "$DOCS_CHANGED" ]; then
5457
echo "skip=true" >> "$GITHUB_OUTPUT"
5558
echo "No markdown changes in docs/"
@@ -99,8 +102,10 @@ jobs:
99102

100103
- name: Check for source changes requiring version bump
101104
id: changes
105+
env:
106+
BASE_REF: origin/${{ github.base_ref }}
102107
run: |
103-
CHANGED_FILES=$(git diff --name-only origin/main...HEAD)
108+
CHANGED_FILES=$(git diff --name-only "$BASE_REF"...HEAD)
104109
echo "Changed files:"
105110
echo "$CHANGED_FILES"
106111
@@ -113,7 +118,7 @@ jobs:
113118
;;
114119
package.json)
115120
# Check if anything other than "version" changed
116-
OTHER_CHANGES=$(git diff origin/main...HEAD -- package.json | grep -E '^[+-]\s' | grep -v -E '^\+\+\+|^---' | grep -v '"version"' || true)
121+
OTHER_CHANGES=$(git diff "$BASE_REF"...HEAD -- package.json | grep -E '^[+-]\s' | grep -v -E '^\+\+\+|^---' | grep -v '"version"' || true)
117122
if [ -n "$OTHER_CHANGES" ]; then
118123
NEEDS_BUMP=true
119124
break
@@ -126,32 +131,34 @@ jobs:
126131
127132
- name: Verify version bump and changelog
128133
if: steps.changes.outputs.needs_bump == 'true'
134+
env:
135+
BASE_REF: origin/${{ github.base_ref }}
129136
run: |
130137
PR_VERSION=$(node -p "require('./package.json').version")
131-
MAIN_VERSION=$(git show origin/main:package.json | node -p "JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')).version")
138+
BASE_VERSION=$(git show "$BASE_REF":package.json | node -p "JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')).version")
132139
133-
echo "Main version: $MAIN_VERSION"
140+
echo "Base version: $BASE_VERSION"
134141
echo "PR version: $PR_VERSION"
135142
136-
if [ "$PR_VERSION" = "$MAIN_VERSION" ]; then
143+
if [ "$PR_VERSION" = "$BASE_VERSION" ]; then
137144
echo "::error::Source files or dependencies changed but package version was not bumped. Please update the version in package.json."
138145
exit 1
139146
fi
140147
141148
HIGHER=$(node -e "
142-
const [a, b] = ['$PR_VERSION', '$MAIN_VERSION'].map(v => v.split('.').map(Number));
149+
const [a, b] = ['$PR_VERSION', '$BASE_VERSION'].map(v => v.split('.').map(Number));
143150
const isHigher = a[0] > b[0] || (a[0] === b[0] && a[1] > b[1]) || (a[0] === b[0] && a[1] === b[1] && a[2] > b[2]);
144151
process.exit(isHigher ? 0 : 1);
145152
" && echo "true" || echo "false")
146153
147154
if [ "$HIGHER" != "true" ]; then
148-
echo "::error::PR version ($PR_VERSION) must be higher than main version ($MAIN_VERSION)."
155+
echo "::error::PR version ($PR_VERSION) must be higher than base version ($BASE_VERSION)."
149156
exit 1
150157
fi
151158
152-
echo "Version bumped from $MAIN_VERSION to $PR_VERSION"
159+
echo "Version bumped from $BASE_VERSION to $PR_VERSION"
153160
154-
CHANGELOG_CHANGED=$(git diff --name-only origin/main...HEAD -- docs/changelog.md)
161+
CHANGELOG_CHANGED=$(git diff --name-only "$BASE_REF"...HEAD -- docs/changelog.md)
155162
if [ -z "$CHANGELOG_CHANGED" ]; then
156163
echo "::error::Version was bumped but docs/changelog.md was not updated. Please add a changelog entry for version $PR_VERSION."
157164
exit 1

.github/workflows/publish-npm.yml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- main
7+
- release-*
78
paths:
89
- "package.json"
910
workflow_dispatch:
@@ -14,6 +15,7 @@ jobs:
1415
runs-on: ubuntu-latest
1516
outputs:
1617
should_publish: ${{ steps.version-check.outputs.should_publish }}
18+
npm_tag: ${{ steps.version-check.outputs.npm_tag }}
1719
steps:
1820
- name: Checkout Repo
1921
uses: actions/checkout@v4
@@ -22,17 +24,31 @@ jobs:
2224
id: version-check
2325
run: |
2426
CURRENT_VERSION=$(node -p "require('./package.json').version")
25-
PUBLISHED_VERSION=$(npm view @red-hat-developer-hub/e2e-test-utils version 2>/dev/null || echo "0.0.0")
27+
BRANCH="${GITHUB_REF#refs/heads/}"
28+
29+
if [[ "$BRANCH" != "main" && "$BRANCH" != release-* ]]; then
30+
echo "::error::Publishing is only allowed from main or release-* branches (got: $BRANCH)"
31+
exit 1
32+
fi
33+
34+
if [[ "$BRANCH" == release-* ]]; then
35+
NPM_TAG="${BRANCH#release-}"
36+
PUBLISHED_VERSION=$(npm view @red-hat-developer-hub/e2e-test-utils version --tag "$NPM_TAG" 2>/dev/null || echo "0.0.0")
37+
else
38+
NPM_TAG="latest"
39+
PUBLISHED_VERSION=$(npm view @red-hat-developer-hub/e2e-test-utils version 2>/dev/null || echo "0.0.0")
40+
fi
2641
2742
echo "Current version: $CURRENT_VERSION"
28-
echo "Published version: $PUBLISHED_VERSION"
43+
echo "Published version ($NPM_TAG): $PUBLISHED_VERSION"
44+
echo "npm_tag=$NPM_TAG" >> "$GITHUB_OUTPUT"
2945
3046
if [ "$CURRENT_VERSION" = "$PUBLISHED_VERSION" ]; then
3147
echo "should_publish=false" >> "$GITHUB_OUTPUT"
3248
echo "Version $CURRENT_VERSION is already published. Skipping."
3349
else
3450
echo "should_publish=true" >> "$GITHUB_OUTPUT"
35-
echo "New version $CURRENT_VERSION will be published."
51+
echo "New version $CURRENT_VERSION will be published (tag: $NPM_TAG)."
3652
fi
3753
3854
publish:
@@ -65,7 +81,8 @@ jobs:
6581
run: yarn config set npmPublishRegistry "https://registry.npmjs.org"
6682

6783
- name: Publish
68-
run: yarn npm publish
84+
run: yarn npm publish --tag "$NPM_TAG"
6985
env:
86+
NPM_TAG: ${{ needs.check-version.outputs.npm_tag }}
7087
NODE_AUTH_TOKEN: ${{ secrets.RHDH_NPM_TOKEN }}
7188
YARN_NPM_AUTH_TOKEN: ${{ secrets.RHDH_NPM_TOKEN }}

0 commit comments

Comments
 (0)