11name : Publish Release
22
3+
34on :
45 workflow_call :
56 inputs :
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+
2744jobs :
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 }}
0 commit comments