@@ -10,7 +10,7 @@ name: Create Release
1010# 4. Create the official release by removing pre-release tags.
1111
1212# - The package is published to npm at each stage of the release process.
13- # - A GitHub tag is created at each stage of the process.
13+ # - A GitHub tag is created at each stage of the process.
1414# - A GitHub Release is ONLY created for official release (not beta or rc).
1515
1616# Release Steps:
4242 # Manually triggered
4343 workflow_dispatch :
4444 inputs :
45- releaseTitle : # Release title shows in GitHub Releases tab.
46- description : ' The title of the release'
47- required : false # Only required if versionTag === 'release'
4845 versionChange : # How much to increment the version number by.
4946 description : ' Increment version by...'
5047 required : true
6966 version_change :
7067 runs-on : ubuntu-latest
7168 steps :
72- # Validate release input for release title
73- - name : Validate release input for release title
74- if : ${{ github.event.inputs.versionTag == 'release' && !github.event.inputs.releaseTitle }}
75- run : |
76- echo "Error: 'releaseTitle' is required when 'versionTag' == 'release'."
77- exit 1
78-
7969 # Checkout code
8070 - name : Checkout repository
8171 uses : actions/checkout@v4
@@ -130,7 +120,7 @@ jobs:
130120 git remote set-url origin https://x-access-token:${{ secrets.GIT_PERSONAL_ACCESS_TOKEN }}@github.com/${{ github.repository }}
131121 git push origin main
132122
133- # UNPUBLISHING NOTE:
123+ # UNPUBLISHING NOTE:
134124 # If you need to unpublish a package version for any reason, you must do so within 72 hours
135125 # of the version being published. To do so, use 'npm login' to login to the 'citzcodemvp' account
136126 # and then run 'npm unpublish @bcgov/<package-name>@<version>' where <package-name> and <version>
@@ -168,7 +158,7 @@ jobs:
168158 with :
169159 token : ${{ secrets.NPM_TOKEN }}
170160 access : public
171-
161+
172162 create_github_release :
173163 runs-on : ubuntu-latest
174164 needs : npm_publish
@@ -209,7 +199,7 @@ jobs:
209199 run : |
210200 sudo apt-get update
211201 sudo apt-get install -y gh
212-
202+
213203 # Install JQ for use in changelog step
214204 - name : Install jq
215205 if : ${{ github.event.inputs.versionTag == 'release' }}
@@ -228,43 +218,47 @@ jobs:
228218
229219 # Get the previous official version
230220 PREV_VERSION=${{ steps.previous_version.outputs.PREV_VERSION }}
231-
221+
232222 # Generate comparison link
233223 if [ -n "$PREV_VERSION" ]; then
234224 COMPARISON_URL="https://github.com/${{ github.repository }}/compare/$PREV_VERSION...$VERSION"
235225 else
236226 COMPARISON_URL=""
237227 fi
238-
228+
239229 # Generate technical documentation link
240230 TECH_DOCS_URL="https://github.com/${{ github.repository }}/tree/$VERSION/techdocs/docs"
241-
242- # List all tags for the current version that have 'beta' or 'rc' in their names
243- TAGS=$(git tag --list "${VERSION}-beta*" "${VERSION}-rc*")
244-
231+
245232 CHANGELOG=""
246-
247- # Loop through each tag to get merged pull requests
248- for TAG in $TAGS; do
249- # Use GitHub CLI to list pull requests merged into the tag
250- PRS=$(gh pr list --search "merged:${TAG}" --json title,url)
251-
252- # Loop through each pull request to construct the changelog
253- for PR in $(echo "$PRS" | jq -c '.[]'); do
254- TITLE=$(echo "$PR" | jq -r '.title')
255- URL=$(echo "$PR" | jq -r '.url')
256- CHANGELOG="${CHANGELOG}\n- ${TITLE} (${URL})"
257- done
233+
234+ # Get the list of commits for current version
235+ COMMITS=$(git log $VERSION-beta..HEAD --pretty=format:"%s %b")
236+
237+ # Extract pull request numbers from the commit messages
238+ PR_NUMBERS=$(echo "$COMMITS" | grep -oE "#[0-9]+" | sort | uniq)
239+
240+ for PR_NUMBER in $PR_NUMBERS; do
241+ # Get the pull request details
242+ PR=$(gh pr view $PR_NUMBER --json title,url)
243+ TITLE=$(echo "$PR" | jq -r '.title')
244+ URL=$(echo "$PR" | jq -r '.url')
245+ CHANGELOG="${CHANGELOG}\n- ${TITLE} (${URL}) "
258246 done
259-
247+
248+ # Escape changelog content for GitHub Actions without encoding newlines
249+ ESCAPED_CHANGELOG=$(echo -e "$CHANGELOG" | sed 's/%/%25/g; s/\r/%0D/g; s/\n/%0A/g')
250+
260251 # Set the CHANGELOG environment variable with the constructed changelog, comparison link, and technical documentation link
261- echo "CHANGELOG<<EOF" >> $GITHUB_ENV
262- echo "<details><summary>Pull Requests</summary>\n$CHANGELOG\n</details>" >> $GITHUB_ENV
263- if [ -n "$COMPARISON_URL" ]; then
264- echo "\n[Compare changes since last version]($COMPARISON_URL)" >> $GITHUB_ENV
265- fi
266- echo "\n[Documentation]($TECH_DOCS_URL)" >> $GITHUB_ENV
267- echo "EOF" >> $GITHUB_ENV
252+ {
253+ echo "CHANGELOG<<EOF"
254+ echo "<details><summary>Pull Requests</summary>"
255+ echo "$ESCAPED_CHANGELOG"
256+ echo "</details>"
257+ echo ""
258+ [ -n "$COMPARISON_URL" ] && echo "[Compare changes since last version]($COMPARISON_URL)"
259+ echo "[Documentation]($TECH_DOCS_URL)"
260+ echo "EOF"
261+ } >> $GITHUB_ENV
268262
269263 # Create new release in GitHub (only official releases)
270264 - name : Create GitHub Release
@@ -275,5 +269,5 @@ jobs:
275269 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
276270 with :
277271 tag_name : ${{ steps.package_version.outputs.VERSION }}
278- name : ${{ github.event.inputs.releaseTitle }}
272+ name : ${{ steps.package_version.outputs.VERSION }}
279273 body : ${{ env.CHANGELOG }}
0 commit comments