Skip to content

Commit c9816e9

Browse files
committed
feat(ci): add interim release workflow copied from Community Plugins
Copies `.github/workflows/release_workspace_version.yml` from the Community Plugins repository to handle maintenance releases. Upstream documentation: - https://github.com/backstage/community-plugins/blob/main/docs/plugin-maintainers-guide.md#maintaining-and-patching-an-older-release-line Signed-off-by: Beth Griggs <bethanyngriggs@gmail.com> chore(ci): update secrets and bot username for RHDH release workflow - Replace `backstage-service` with `rhdh-bot` for PR author validation - Use `RHDH_BOT_TOKEN` instead of `GH_SERVICE_ACCOUNT_TOKEN` for GitHub auth - Use `RHDH_NPM_TOKEN` instead of `NPM_TOKEN` for npm publish steps Signed-off-by: Beth Griggs <bethanyngriggs@gmail.com>
1 parent 54dcb42 commit c9816e9

1 file changed

Lines changed: 183 additions & 0 deletions

File tree

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
name: Prior Version Release Workspace
2+
3+
on:
4+
# ADDED: Only trigger on PR closed event on workspace/** branch.
5+
# The assumption is that branch protection rules and CODEOWNERS are configured.
6+
7+
pull_request:
8+
types:
9+
- closed
10+
branches:
11+
- 'workspace/**'
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
16+
jobs:
17+
# ADDED: Checks if PR is a Version Packages PR on workspace/** branch
18+
# and validates PR title, author, branch and merged status.
19+
check-merged-pr:
20+
name: Check if PR is a Version Packages PR on workspace/** branch
21+
runs-on: ubuntu-latest
22+
outputs:
23+
is_version_pr: ${{ steps.check_pr.outputs.is_version_pr }}
24+
workspace_name: ${{ steps.extract_workspace.outputs.workspace_name }}
25+
steps:
26+
- name: Check PR title, author, branch and merged status
27+
id: check_pr
28+
run: |
29+
if [[ "${{ github.event.pull_request.title }}" == Version*Packages* \
30+
&& "${{ github.event.pull_request.user.login }}" == "rhdh-bot" ]] \
31+
&& [[ "${{ github.event.pull_request.head.ref }}" == maintenance-changesets-release/* ]] \
32+
&& [[ "${{ github.event.pull_request.merged }}" == "true" ]]; then
33+
echo "is_version_pr=true" >> $GITHUB_OUTPUT
34+
else
35+
echo "is_version_pr=false" >> $GITHUB_OUTPUT
36+
fi
37+
38+
# ADDED: Extracts workspace name from branch, ensuring it is a workspace/** branch
39+
- name: Extract Workspace name from branch
40+
id: extract_workspace
41+
run: |
42+
WORKSPACE_NAME=$(echo "${{ github.event.pull_request.base.ref }}" | cut -d'/' -f2)
43+
echo "workspace_name=$WORKSPACE_NAME" >> $GITHUB_OUTPUT
44+
45+
changesets-pr:
46+
name: Update Version Packages PR for ${{ needs.check-merged-pr.outputs.workspace_name }} on branch ${{ github.ref }}
47+
runs-on: ubuntu-latest
48+
needs: check-merged-pr
49+
if: needs.check-merged-pr.outputs.is_version_pr == 'false'
50+
defaults:
51+
run:
52+
working-directory: ./workspaces/${{ needs.check-merged-pr.outputs.workspace_name }}
53+
env:
54+
CI: true
55+
NODE_OPTIONS: --max-old-space-size=4096
56+
outputs:
57+
needs_release: ${{ steps.release_check.outputs.needs_release }}
58+
steps:
59+
- name: Checkout
60+
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4
61+
with:
62+
ref: ${{ github.ref }}
63+
64+
- name: Verify maintenance-changesets-release branch does not exist
65+
run: |
66+
if git ls-remote --exit-code origin "refs/heads/maintenance-changesets-release/${{ needs.check-merged-pr.outputs.workspace_name }}"; then
67+
echo "Error: maintenance-changesets-release/${{ needs.check-merged-pr.outputs.workspace_name }} branch already exists. Please clean up the branch before proceeding."
68+
exit 1
69+
fi
70+
71+
- name: Set up Node
72+
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4
73+
with:
74+
node-version: 20
75+
registry-url: https://registry.npmjs.org/ # Needed for auth
76+
77+
- name: Get yarn cache directory path
78+
id: yarn-cache-dir-path
79+
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
80+
81+
- uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
82+
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
83+
with:
84+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
85+
key: ${{ runner.os }}-yarn-${{ hashFiles(format('workspaces/${0}/**/yarn.lock', needs.check-merged-pr.outputs.workspace_name)) }}
86+
restore-keys: |
87+
${{ runner.os }}-yarn-
88+
89+
- name: yarn install
90+
run: yarn install --immutable
91+
92+
- name: Fetch previous commit for release check
93+
run: git fetch origin '${{ github.event.pull_request.base.sha }}'
94+
95+
- name: Fetch the commit that triggered the workflow (used by backstage/changesets-action)
96+
run: git fetch origin ${{ github.sha }}
97+
continue-on-error: true
98+
99+
- name: Check if release
100+
id: release_check
101+
run: |
102+
yarn install
103+
node scripts/ci/check-if-release.js
104+
working-directory: ./
105+
env:
106+
WORKSPACE_NAME: ${{ needs.check-merged-pr.outputs.workspace_name }}
107+
COMMIT_SHA_BEFORE: '${{ github.event.pull_request.base.sha }}'
108+
TARGET_BRANCH: ${{ github.ref }}
109+
110+
- name: Update Version Packages (${{ needs.check-merged-pr.outputs.workspace_name }}) PR
111+
id: changesets-pr
112+
if: steps.release_check.outputs.needs_release != 'true'
113+
uses: backstage/changesets-action@291bfc1f76d1dcfbf967f5810dc0423592eae09a # v2.3.1
114+
with:
115+
title: Version Packages (${{ needs.check-merged-pr.outputs.workspace_name }})
116+
cwd: workspaces/${{ needs.check-merged-pr.outputs.workspace_name }}
117+
version: yarn changeset version
118+
versionBranch: maintenance-changesets-release/${{ needs.check-merged-pr.outputs.workspace_name }}
119+
skipRootChangelogUpdate: true
120+
env:
121+
GITHUB_TOKEN: ${{ secrets.RHDH_BOT_TOKEN }}
122+
123+
release:
124+
name: Prior Version Release workspace ${{ needs.check-merged-pr.outputs.workspace_name }} on branch ${{ github.ref }}
125+
runs-on: ubuntu-latest
126+
needs: check-merged-pr
127+
if: needs.check-merged-pr.outputs.is_version_pr == 'true'
128+
defaults:
129+
run:
130+
working-directory: ./workspaces/${{ needs.check-merged-pr.outputs.workspace_name }}
131+
env:
132+
CI: true
133+
NODE_OPTIONS: --max-old-space-size=4096
134+
135+
steps:
136+
- name: Checkout
137+
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4
138+
with:
139+
ref: ${{ github.ref }}
140+
- name: Set up Node
141+
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4
142+
with:
143+
node-version: 20
144+
registry-url: https://registry.npmjs.org/ # Needed for auth
145+
146+
- name: Install root dependencies
147+
run: yarn install --immutable
148+
working-directory: ${{ github.workspace }}
149+
150+
- name: Get yarn cache directory path
151+
id: yarn-cache-dir-path
152+
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
153+
154+
- uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
155+
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
156+
with:
157+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
158+
key: ${{ runner.os }}-yarn-${{ hashFiles(format('workspaces/${0}/**/yarn.lock', needs.check-merged-pr.outputs.workspace_name)) }}
159+
restore-keys: |
160+
${{ runner.os }}-yarn-
161+
- name: yarn install
162+
run: yarn install --immutable
163+
164+
- name: Compile TypeScript
165+
run: yarn tsc:full
166+
167+
- name: Build all packages
168+
run: yarn build:all
169+
170+
# CHANGED: Publish with tag "maintenance" to avoid overwriting the latest npm tag
171+
- name: publish
172+
run: |
173+
yarn config set -H 'npmAuthToken' "${{secrets.RHDH_NPM_TOKEN}}"
174+
yarn workspaces foreach -v --no-private npm publish --access public --tolerate-republish --tag "maintenance"
175+
env:
176+
NODE_AUTH_TOKEN: ${{ secrets.RHDH_NPM_TOKEN }}
177+
178+
- name: Create tag
179+
working-directory: ${{ github.workspace }}/scripts/ci
180+
run: node create-tag.js
181+
env:
182+
WORKSPACE_NAME: ${{ needs.check-merged-pr.outputs.workspace_name }}
183+
GITHUB_TOKEN: ${{ secrets.RHDH_BOT_TOKEN }}

0 commit comments

Comments
 (0)