@@ -22,47 +22,77 @@ outputs:
2222runs :
2323 using : composite
2424 steps :
25- - name : " Process changelog for changelog.txt"
26- id : process_changelog
25+ - name : " Verify the action type"
26+ id : verify_action_type
27+ if : ${{ inputs.action-type == 'generate' }}
2728 shell : bash
2829 env :
29- ACTION_TYPE : ${{ inputs.action-type }}
3030 RELEASE_VERSION : ${{ inputs.release-version }}
3131 RELEASE_DATE : ${{ inputs.release-date }}
32+ ACTION_TYPE : ${{ inputs.action-type }}
3233 run : |
33- # Install this dev package globally to gather changelog entries while not including it into the release package
34- composer global require automattic/jetpack-changelogger:^3.0.7
34+ FINAL_RELEASE_VERSION=$(echo "$RELEASE_VERSION" | grep -Po '\d.\d.\d(.*?)') # Keep only x.y.z from x.y.z(-test-n)
35+ CURRENT_RELEASE_VERSION=$(jq '.version' package.json -r)
3536
36- if ${{ env.ACTION_TYPE == 'generate' }}; then
37- CHANGELOG_FLAG=""
38- echo "Generating the changelog entries." >> $GITHUB_STEP_SUMMARY
37+ # If the changelog directory is empty (except .gitkeep) and the final release version is already defined in package.json, we need to switch to amend
38+ # This use case is mainly for the last test package created from the release branch, to avoid an empty changelog
39+ if [ "$(ls -A changelog | wc -l)" -eq 1 ] && [[ "$FINAL_RELEASE_VERSION" == "$CURRENT_RELEASE_VERSION" ]]; then
40+ echo "ACTION_TYPE=amend-version" >> $GITHUB_OUTPUT
41+ echo "CURRENT_VERSION=$CURRENT_RELEASE_VERSION" >> $GITHUB_OUTPUT
3942 else
40- CHANGELOG_FLAG="--amend"
41- echo "Amending the changelog entries." >> $GITHUB_STEP_SUMMARY
43+ echo "ACTION_TYPE=$ACTION_TYPE" >> $GITHUB_OUTPUT
4244 fi
45+
46+ - name : " Process changelog for changelog.txt"
47+ id : process_changelog
48+ shell : bash
49+ env :
50+ ACTION_TYPE : ${{ steps.verify_action_type.outputs.ACTION_TYPE }}
51+ CURRENT_VERSION : ${{ steps.verify_action_type.outputs.CURRENT_VERSION }}
52+ RELEASE_VERSION : ${{ inputs.release-version }}
53+ RELEASE_DATE : ${{ inputs.release-date }}
54+ run : |
55+ if ${{ env.ACTION_TYPE == 'amend-version' }}; then
56+ sed -i "s/^= $CURRENT_VERSION - .* =$/= $RELEASE_VERSION - $RELEASE_DATE =/" changelog.txt
57+ else
58+ # Install this dev package globally to gather changelog entries while not including it into the release package
59+ composer global require automattic/jetpack-changelogger:^3.0.7
4360
44- ~/.composer/vendor/bin/changelogger write --use-version="$RELEASE_VERSION" --release-date="$RELEASE_DATE" $CHANGELOG_FLAG --no-interaction --yes
61+ if ${{ env.ACTION_TYPE == 'generate' }}; then
62+ CHANGELOG_FLAG=""
63+ echo "Generating the changelog entries." >> $GITHUB_STEP_SUMMARY
64+ else
65+ CHANGELOG_FLAG="--amend"
66+ echo "Amending the changelog entries." >> $GITHUB_STEP_SUMMARY
67+ fi
68+
69+ ~/.composer/vendor/bin/changelogger write --use-version="$RELEASE_VERSION" --release-date="$RELEASE_DATE" $CHANGELOG_FLAG --no-interaction --yes
70+ fi
4571
46- echo "Picking up changelog for version '$RELEASE_VERSION'..."
4772 CHANGELOG=$(awk '/^= / { if (p) { exit }; p=1; next } p && NF' changelog.txt)
48- echo "$CHANGELOG"
4973
5074 # Escape backslash, new line and ampersand characters. The order is important.
5175 CHANGELOG=${CHANGELOG//\\/\\\\}
5276 CHANGELOG=${CHANGELOG//$'\n'/\\n}
5377 CHANGELOG=${CHANGELOG//&/\\&}
78+
5479 echo "CHANGELOG=$CHANGELOG" >> $GITHUB_OUTPUT
5580
5681 - name : " Process changelog for readme.txt"
5782 shell : bash
5883 env :
59- ACTION_TYPE : ${{ inputs.action-type }}
84+ ACTION_TYPE : ${{ steps.verify_action_type.outputs.ACTION_TYPE }}
85+ CURRENT_VERSION : ${{ steps.verify_action_type.outputs.CURRENT_VERSION }}
6086 RELEASE_VERSION : ${{ inputs.release-version }}
6187 RELEASE_DATE : ${{ inputs.release-date }}
6288 CHANGELOG : ${{ steps.process_changelog.outputs.CHANGELOG }}
6389 run : |
64- if ${{ env.ACTION_TYPE == 'amend' }}; then
65- perl -i -p0e "s/= $RELEASE_VERSION.*?(\n){2}//s" readme.txt # Delete the existing changelog for the release version first
66- fi
90+ if ${{ env.ACTION_TYPE == 'amend-version' }}; then
91+ sed -i "s/^= $CURRENT_VERSION - .* =$/= $RELEASE_VERSION - $RELEASE_DATE =/" readme.txt
92+ else
93+ if ${{ env.ACTION_TYPE == 'amend' }}; then
94+ perl -i -p0e "s/= $RELEASE_VERSION.*?(\n){2}//s" readme.txt # Delete the existing changelog for the release version first
95+ fi
6796
68- sed -ri "s|(== Changelog ==)|\1\n\n= $RELEASE_VERSION - $RELEASE_DATE =\n$CHANGELOG|" readme.txt
97+ sed -ri "s|(== Changelog ==)|\1\n\n= $RELEASE_VERSION - $RELEASE_DATE =\n$CHANGELOG|" readme.txt
98+ fi
0 commit comments