Skip to content

Commit d7523e5

Browse files
committed
Improve release workflow validation and zip generation when dry-running
1 parent 002608b commit d7523e5

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

.github/workflows/release-plugin.yml

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Release wp-parsely
2-
run-name: Release wp-parsely ${{ github.event.inputs.version }}${{ github.event.inputs.dry_run && ' (dry-run)' || '' }}
2+
run-name: Release wp-parsely ${{ github.event.inputs.version }}${{ 'true' == github.event.inputs.dry_run && ' (dry-run)' || '' }}
33
on:
44
workflow_dispatch:
55
inputs:
@@ -26,10 +26,10 @@ concurrency:
2626
cancel-in-progress: true
2727

2828
env:
29-
SOURCE_REF: ${{ github.event.inputs.branch }}
30-
DRY_RUN: ${{ github.event.inputs.dry_run }}
31-
SKIP_TESTS: ${{ github.event.inputs.skip_tests }}
32-
VERSION: ${{ github.event.inputs.version }}
29+
SOURCE_REF: ${{ github.event.inputs.branch }}
30+
DRY_RUN: ${{ github.event.inputs.dry_run == 'true' }}
31+
SKIP_TESTS: ${{ github.event.inputs.skip_tests == 'true' }}
32+
VERSION: ${{ github.event.inputs.version }}
3333

3434
jobs:
3535
validate_version:
@@ -47,6 +47,7 @@ jobs:
4747
run: |
4848
if [[ ! "${{ env.VERSION }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
4949
echo "Version `${{ env.VERSION }}` is not a valid semver version."
50+
echo "::error title=Validate Version::Version `${{ env.VERSION }}` is not a valid semver version."
5051
exit 1
5152
fi
5253
@@ -60,37 +61,47 @@ jobs:
6061
run: |
6162
if [[ ! -f vendor/autoload.php ]]; then
6263
echo "The branch '${{ env.SOURCE_REF }}' is not a built branch."
64+
echo "::error title=Validate Branch::The branch '${{ env.SOURCE_REF }}' is not a built branch."
6365
exit 1
6466
fi
6567
6668
- name: Check if the version matches the version in wp-parsely.php and package.json
67-
if: ${{ env.DRY_RUN == false }}
69+
if: ${{ env.DRY_RUN == 'false' }}
6870
run: |
6971
PHP_VERSION=$(grep -E "^ \* Version:" wp-parsely.php | awk '{print $3}')
7072
JSON_VERSION=$(jq -r '.version' package.json)
7173
if [[ "${{ env.VERSION }}" != "${PHP_VERSION}" ]]; then
7274
echo "Version '${{ env.VERSION }}' does not match the version in wp-parsely.php."
7375
echo "Did you mean '${PHP_VERSION}'?"
76+
echo "::error file=wp-parsely.php,title=Validate Version::Version '${{ env.VERSION }}' does not match the version in wp-parsely.php (${PHP_VERSION})."
7477
exit 1
7578
fi
7679
if [[ "${{ env.VERSION }}" != "${JSON_VERSION}" ]]; then
7780
echo "Version '${{ env.VERSION }}' does not match the version in package.json."
7881
echo "Did you mean '${JSON_VERSION}'?"
82+
echo "::error file=package.json,title=Validate Version::Version '${{ env.VERSION }}' does not match the version in package.json (${JSON_VERSION})."
7983
exit 1
8084
fi
8185
8286
- name: Check if the version is in the CHANGELOG.md file
8387
run: |
8488
if ! grep -q "## \[${{ env.VERSION }}\]" CHANGELOG.md; then
8589
echo "Version '${{ env.VERSION }}' is not in the CHANGELOG.md file."
86-
exit 1
90+
91+
if ${{ env.DRY_RUN }}; then
92+
echo "::warning file=CHANGELOG.md,title=Validate Version::Version '${{ env.VERSION }}' is not in the CHANGELOG.md file. The dry-run will proceed with an empty changelog entry."
93+
else
94+
echo "::error file=CHANGELOG.md,title=Validate Version::Version '${{ env.VERSION }}' is not in the CHANGELOG.md file."
95+
exit 1
96+
fi
8797
fi
8898
8999
- name: Check if the version was already released
90-
if: ${{ env.DRY_RUN == false }}
100+
if: ${{ env.DRY_RUN == 'false' }}
91101
run: |
92102
if git tag --list | grep -q "${{ env.VERSION }}"; then
93103
echo "Version '${{ env.VERSION }}' has already been released."
104+
echo "::error title=Validate Version::Version '${{ env.VERSION }}' has already been released."
94105
exit 1
95106
fi
96107
@@ -155,10 +166,16 @@ jobs:
155166
run: |
156167
set -e
157168
VERSION=${{ env.VERSION }}
158-
START_LINE=$(grep -n "## \[${VERSION}\]" CHANGELOG.md | cut -d: -f1)
169+
START_LINE=$(grep -n "## \[${VERSION}\]" CHANGELOG.md | cut -d: -f1 || true)
159170
if [ -z "$START_LINE" ]; then
160-
echo "Version not found in CHANGELOG.md" >&2
161-
exit 1
171+
if ${{ env.DRY_RUN }}; then
172+
echo "::warning file=CHANGELOG.md,title=Extract Changelog::Version '${VERSION}' not found in CHANGELOG.md. The dry-run will proceed with an empty changelog entry."
173+
echo -e "\nThere is no available changelog entry for the dry-run." > release_notes.md
174+
exit 0
175+
else
176+
echo "::error file=CHANGELOG.md,title=Extract Changelog::Version '${VERSION}' not found in CHANGELOG.md"
177+
exit 1
178+
fi
162179
fi
163180
TAIL_LINE=$(tail -n +$((START_LINE + 1)) CHANGELOG.md | grep -n "^## " | head -n 1 | cut -d: -f1 || true)
164181
if [ -z "$TAIL_LINE" ]; then
@@ -173,6 +190,7 @@ jobs:
173190
- name: Format Changelog
174191
id: format_changelog
175192
run: |
193+
cat release_notes.md
176194
sed -i '1d' release_notes.md # Remove the first line
177195
sed -i 's/###/##/g' release_notes.md # Change headers from ### to ##
178196
shell: bash
@@ -187,6 +205,7 @@ jobs:
187205
draft: true
188206
prerelease: false
189207
allowUpdates: true
208+
omitBodyDuringUpdate: false
190209

191210
deploy:
192211
name: Deploy to WordPress.org
@@ -214,6 +233,7 @@ jobs:
214233
env:
215234
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
216235
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
236+
VERSION: ${{ needs.tag_and_release.outputs.tag_name }}
217237

218238
- name: Update release with ZIP file
219239
uses: ncipollo/release-action@v1

0 commit comments

Comments
 (0)