Skip to content

Commit 90eecbf

Browse files
committed
feat: support trb project node version bump
1 parent 6173ab3 commit 90eecbf

File tree

7 files changed

+149
-14
lines changed

7 files changed

+149
-14
lines changed

.github/actions/npm-publish/action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
name: 'NPM Publish'
22
description: 'Publish package to npm registry.'
33

4+
45
inputs:
56
node-version:
67
description: 'Node.js version to use.'
78
required: false
89
default: '20'
10+
911
package-dir:
1012
description: 'Directory containing package.json.'
1113
required: false
1214
default: '.'
15+
1316
deploy-command:
1417
description: 'Publish command to execute.'
1518
required: false
1619
default: 'npm run deploy'
20+
1721
access-token:
1822
description: 'NPM auth token.'
1923
required: true
2024

25+
2126
runs:
2227
using: 'composite'
2328
steps:
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: 'TRB Project Node Version Bump'
2+
description: 'Trigger TRB bump project node version workflow dispatch.'
3+
4+
5+
inputs:
6+
trb-repository:
7+
description: 'Target TRB repository.'
8+
required: true
9+
10+
project-node-name:
11+
description: 'The description (name) of TRB node.'
12+
required: true
13+
14+
release-version:
15+
description: 'Release version from the current publish tag without the v prefix (for example, 1.0.0).'
16+
required: true
17+
18+
release-at:
19+
description: 'UTC timestamp of the tagged commit in ISO 8601 format (YYYY-MM-DDTHH:mm:ss.000Z).'
20+
required: true
21+
22+
access-token:
23+
description: 'GitHub token with workflow dispatch permission.'
24+
required: true
25+
26+
27+
runs:
28+
using: 'composite'
29+
steps:
30+
- name: 🔍 Verify TRB Repository
31+
shell: bash
32+
run: |
33+
if [ -z '${{ inputs.trb-repository }}' ]; then
34+
echo '❌ TRB Repository is required.'
35+
exit 1
36+
fi
37+
38+
- name: 🔍 Verify TRB Repository Ref
39+
id: repository_ref
40+
shell: bash
41+
env:
42+
GH_TOKEN: ${{ inputs.access-token }}
43+
run: |
44+
REPOSITORY_REF=$(gh api "repos/${{ inputs.trb-repository }}" --jq '.default_branch')
45+
if [ -z "$REPOSITORY_REF" ] || [ "$REPOSITORY_REF" = 'null' ]; then
46+
echo '❌ Failed to resolve TRB default branch.'
47+
exit 1
48+
fi
49+
50+
printf 'value=%s\n' "$REPOSITORY_REF" >> "$GITHUB_OUTPUT"
51+
52+
- name: 🚀 Trigger TRB Workflow Dispatch
53+
shell: bash
54+
env:
55+
GH_TOKEN: ${{ inputs.access-token }}
56+
run: |
57+
gh workflow run 'Bump Node Version' \
58+
--repo '${{ inputs.trb-repository }}' \
59+
--ref '${{ steps.repository_ref.outputs.value }}' \
60+
-f node-description='${{ inputs.project-node-name }}' \
61+
-f release-version='${{ inputs.release-version }}' \
62+
-f release-at='${{ inputs.release-at }}'

.github/workflows/prepare-release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
name: Prepare Release
22

3+
34
on:
45
push:
56
tags:
67
- 'v*'
78

9+
810
permissions:
911
contents: write
1012
pull-requests: write
1113

14+
1215
jobs:
1316
call-prepare:
1417
uses: leoweyr/github-release-workflow/.github/workflows/reusable-prepare-release.yml@develop

.github/workflows/publish-release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
name: Publish Release
22

3+
34
on:
45
pull_request:
56
types: [closed]
67

8+
79
permissions:
810
contents: write
911

12+
1013
jobs:
1114
call-publish:
1215
uses: leoweyr/github-release-workflow/.github/workflows/reusable-publish-release.yml@develop

.github/workflows/reusable-prepare-release.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: Prepare Release
22

3+
34
on:
45
workflow_call:
56
inputs:
@@ -8,26 +9,31 @@ on:
89
required: false
910
type: string
1011
default: '20'
12+
1113
base-branch:
1214
description: 'Base branch name for release pull requests.'
1315
required: false
1416
type: string
1517
default: 'master'
18+
1619
commit-user-name:
1720
description: 'Git user name for commit'
1821
required: false
1922
type: string
2023
default: 'github-actions[bot]'
24+
2125
commit-user-email:
2226
description: 'Git user email for commit.'
2327
required: false
2428
type: string
2529
default: 'github-actions[bot]@users.noreply.github.com'
30+
2631
secrets:
2732
ACCESS_TOKEN:
2833
required: true
2934
description: 'GitHub Token for authentication.'
3035

36+
3137
jobs:
3238
prepare-release:
3339
runs-on: ubuntu-latest

.github/workflows/reusable-publish-release.yml

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: Publish Release
22

3+
34
on:
45
workflow_call:
56
inputs:
@@ -8,22 +9,38 @@ on:
89
required: false
910
type: string
1011
default: '20'
12+
1113
npm-package-dir:
1214
description: 'Directory containing package.json for npm publish.'
1315
required: false
1416
type: string
1517
default: '.'
18+
1619
npm-deploy-command:
1720
description: 'Command used to publish npm package.'
1821
required: false
1922
type: string
2023
default: 'npm run deploy'
24+
25+
trb-repository:
26+
description: 'Target TRB repository.'
27+
required: false
28+
type: string
29+
default: ''
30+
31+
trb-project-node-name:
32+
description: 'The description (name) of TRB node.'
33+
required: false
34+
type: string
35+
default: ''
36+
2137
secrets:
2238
ACCESS_TOKEN:
2339
required: true
2440
NPM_TOKEN:
2541
required: false
2642

43+
2744
jobs:
2845
publish-release:
2946
if: github.event.pull_request.merged == true && startsWith(github.event.pull_request.title, 'release:')
@@ -44,22 +61,31 @@ jobs:
4461
id: extract_tag
4562
run: |
4663
TITLE="${{ github.event.pull_request.title }}"
47-
TAG_NAME=$(echo "$TITLE" | sed 's/release: //')
48-
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
49-
VERSION_TITLE=${TAG_NAME#v}
50-
echo "VERSION_TITLE=$VERSION_TITLE" >> $GITHUB_ENV
64+
ORIGINAL_TAG_NAME=$(printf '%s' "$TITLE" | sed 's/release: //')
65+
RELEASE_VERSION=${ORIGINAL_TAG_NAME#v}
66+
TAG_COMMIT_HASH=$(git rev-list -n 1 "$ORIGINAL_TAG_NAME")
67+
68+
if [ -z "$TAG_COMMIT_HASH" ]; then
69+
echo '❌ Tag commit hash not found.'
70+
exit 1
71+
fi
72+
73+
RELEASE_AT=$(TZ=UTC git show -s --format="%cd" --date=format-local:"%Y-%m-%dT%H:%M:%S.000Z" "$TAG_COMMIT_HASH")
74+
printf 'TAG_NAME=%s\n' "$ORIGINAL_TAG_NAME" >> "$GITHUB_ENV"
75+
printf 'RELEASE_VERSION=%s\n' "$RELEASE_VERSION" >> "$GITHUB_ENV"
76+
printf 'RELEASE_AT=%s\n' "$RELEASE_AT" >> "$GITHUB_ENV"
5177
5278
- name: 📝 Create Release Body File
5379
env:
5480
PR_BODY: ${{ github.event.pull_request.body }}
55-
run: echo "$PR_BODY" > release_body.md
81+
run: printf '%s\n' "$PR_BODY" > release_body.md
5682

5783
- name: 🚀 Deploy GitHub Release
5884
env:
5985
GH_TOKEN: ${{ secrets.ACCESS_TOKEN }}
6086
run: |
6187
gh release create ${{ env.TAG_NAME }} \
62-
--title "${{ env.VERSION_TITLE }}" \
88+
--title "${{ env.RELEASE_VERSION }}" \
6389
--notes-file release_body.md \
6490
--verify-tag
6591
@@ -74,13 +100,32 @@ jobs:
74100
75101
printf 'enabled=true\n' >> "$GITHUB_OUTPUT"
76102
77-
- name: 🔄 Sync NPM Publish Action
78-
if: steps.verify_npm_token.outputs.enabled == 'true'
103+
- name: 🔍 Verify TRB Inputs
104+
id: verify_trb_inputs
105+
run: |
106+
if [ -z "${{ inputs.trb-repository }}" ]; then
107+
echo '👻 trb-repository is not configured.'
108+
printf 'enabled=false\n' >> "$GITHUB_OUTPUT"
109+
exit 0
110+
fi
111+
112+
if [ -z "${{ inputs.trb-node-description }}" ]; then
113+
echo '👻 trb-node-description is not configured.'
114+
printf 'enabled=false\n' >> "$GITHUB_OUTPUT"
115+
exit 0
116+
fi
117+
118+
printf 'enabled=true\n' >> "$GITHUB_OUTPUT"
119+
120+
- name: 🔄 Sync Release Actions
121+
if: steps.verify_npm_token.outputs.enabled == 'true' || steps.verify_trb_inputs.outputs.enabled == 'true'
79122
uses: actions/checkout@v4
80123
with:
81124
repository: 'leoweyr/github-release-workflow'
82125
path: .release-workflow
83-
sparse-checkout: .github/actions/npm-publish
126+
sparse-checkout: |
127+
.github/actions/npm-publish
128+
.github/actions/trb-project-node-version-bump
84129
85130
- name: 🚀 Deploy NPM Package
86131
if: steps.verify_npm_token.outputs.enabled == 'true'
@@ -90,3 +135,13 @@ jobs:
90135
package-dir: ${{ inputs.npm-package-dir }}
91136
deploy-command: ${{ inputs.npm-deploy-command }}
92137
access-token: ${{ secrets.NPM_TOKEN }}
138+
139+
- name: 🚀 Bump TRB Project Node Version
140+
if: steps.verify_trb_inputs.outputs.enabled == 'true'
141+
uses: ./.release-workflow/.github/actions/trb-project-version-bump
142+
with:
143+
trb-repository: ${{ inputs.trb-repository }}
144+
project-node-name: ${{ inputs.trb-project-node-name }}
145+
release-version: ${{ env.RELEASE_VERSION }}
146+
release-at: ${{ env.RELEASE_AT }}
147+
access-token: ${{ secrets.ACCESS_TOKEN }}

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ This workflow streamlines your release process into a few simple steps:
4444

4545
> [!NOTE]
4646
>
47-
> If the required secret for the release target are not configured, publishing will not start.
47+
> If the required inputs or secrets for a release target are not configured, publishing for that target will not start.
4848

4949
Configure target publishing in your user-side entry workflow (`.github/workflows/publish-release.yml`):
5050

51-
| Release Target | Required Secret | User-Side Inputs (`with`) |
52-
|----------------|-----------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|
53-
| GitHub Release | `ACCESS_TOKEN` (Mapped from `secrets.GITHUB_TOKEN`) | None |
54-
| NPM | `NPM_TOKEN` | `npm-node-version` (Default `20`)<br/>`npm-package-dir` (Default `.`)<br/>`npm-deploy-command` (Default `npm run deploy`) |
51+
| Release Target | Required | User-Side Inputs (`with`) |
52+
|----------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|
53+
| GitHub Release | `ACCESS_TOKEN` (Mapped from `secrets.GITHUB_TOKEN`) | None |
54+
| npm | `NPM_TOKEN` | `npm-node-version` (Default `20`)<br/>`npm-package-dir` (Default `.`)<br/>`npm-deploy-command` (Default `npm run deploy`) |
55+
| [TODO Requirement Blueprint](https://github.com/leoweyr/todo-requirement-blueprint-spec) (Bump Project Node Version) | `trb-repository`<br/>`trb-project-node-name` | |

0 commit comments

Comments
 (0)