-
Notifications
You must be signed in to change notification settings - Fork 32
251 lines (225 loc) · 9.09 KB
/
release-plugin.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
name: Release wp-parsely
run-name: Release wp-parsely ${{ github.event.inputs.version }}${{ 'true' == github.event.inputs.dry_run && ' (dry-run)' || '' }}
on:
workflow_dispatch:
inputs:
branch:
description: 'Built branch to release'
required: false
default: 'trunk-built'
version:
description: 'Version to release (eg. 3.16.0)'
required: true
skip_tests:
description: 'Skip tests'
required: false
type: boolean
default: false
dry_run:
description: 'Dry-run the release'
required: false
type: boolean
default: true
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
env:
SOURCE_REF: ${{ github.event.inputs.branch }}
DRY_RUN: ${{ github.event.inputs.dry_run == 'true' }}
SKIP_TESTS: ${{ github.event.inputs.skip_tests == 'true' }}
VERSION: ${{ github.event.inputs.version }}
jobs:
validate_version:
name: Validate Version and Branch
runs-on: ubuntu-latest
steps:
- name: Output Inputs
run: |
echo "Branch: ${{ env.SOURCE_REF }}"
echo "Dry Run: ${{ env.DRY_RUN }}"
echo "Skip Tests: ${{ env.SKIP_TESTS }}"
echo "Version: ${{ env.VERSION }}"
- name: Check if version is semver
run: |
if [[ ! "${{ env.VERSION }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Version `${{ env.VERSION }}` is not a valid semver version."
echo "::error title=Validate Version::Version `${{ env.VERSION }}` is not a valid semver version."
exit 1
fi
- name: Checkout the specific branch/ref
uses: actions/checkout@v4
with:
ref: ${{ env.SOURCE_REF }}
fetch-depth: 0
- name: Validate if the branch is built by checking if the vendor/autoload.php file exists
run: |
if [[ ! -f vendor/autoload.php ]]; then
echo "The branch '${{ env.SOURCE_REF }}' is not a built branch."
echo "::error title=Validate Branch::The branch '${{ env.SOURCE_REF }}' is not a built branch."
exit 1
fi
- name: Check if the version matches the version in wp-parsely.php and package.json
if: ${{ env.DRY_RUN == 'false' }}
run: |
PHP_VERSION=$(grep -E "^ \* Version:" wp-parsely.php | awk '{print $3}')
JSON_VERSION=$(jq -r '.version' package.json)
if [[ "${{ env.VERSION }}" != "${PHP_VERSION}" ]]; then
echo "Version '${{ env.VERSION }}' does not match the version in wp-parsely.php."
echo "Did you mean '${PHP_VERSION}'?"
echo "::error file=wp-parsely.php,title=Validate Version::Version '${{ env.VERSION }}' does not match the version in wp-parsely.php (${PHP_VERSION})."
exit 1
fi
if [[ "${{ env.VERSION }}" != "${JSON_VERSION}" ]]; then
echo "Version '${{ env.VERSION }}' does not match the version in package.json."
echo "Did you mean '${JSON_VERSION}'?"
echo "::error file=package.json,title=Validate Version::Version '${{ env.VERSION }}' does not match the version in package.json (${JSON_VERSION})."
exit 1
fi
- name: Check if the version is in the CHANGELOG.md file
run: |
if ! grep -q "## \[${{ env.VERSION }}\]" CHANGELOG.md; then
echo "Version '${{ env.VERSION }}' is not in the CHANGELOG.md file."
if ${{ env.DRY_RUN }}; then
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."
else
echo "::error file=CHANGELOG.md,title=Validate Version::Version '${{ env.VERSION }}' is not in the CHANGELOG.md file."
exit 1
fi
fi
- name: Check if the version was already released
if: ${{ env.DRY_RUN == 'false' }}
run: |
if git tag --list | grep -q "${{ env.VERSION }}"; then
echo "Version '${{ env.VERSION }}' has already been released."
echo "::error title=Validate Version::Version '${{ env.VERSION }}' has already been released."
exit 1
fi
integration_tests:
name: Integration Tests
needs: validate_version
if: ${{ github.event.inputs.skip_tests == 'false' }}
uses: ./.github/workflows/integration-tests.yml
e2e_tests:
name: End-to-end Tests
needs: validate_version
if: ${{ github.event.inputs.skip_tests == 'false' }}
uses: ./.github/workflows/e2e-tests.yml
tag_and_release:
name: Tag and Release
needs: [ validate_version, integration_tests, e2e_tests ]
if: ${{ !failure() && !cancelled() }}
runs-on: ubuntu-latest
outputs:
tag_name: ${{ steps.tag.outputs.tag_name }}
steps:
- name: Configure Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Checkout the specific branch/ref
uses: actions/checkout@v4
with:
ref: ${{ env.SOURCE_REF }}
fetch-depth: 0
- name: Tag the release
id: tag
run: |
TAG_NAME="${{ env.VERSION }}"
if ${{ env.DRY_RUN }}; then
TAG_NAME="dry-run-${{ env.VERSION }}"
# If the tag already exists, delete the tag
if git tag --list | grep -q "${TAG_NAME}"; then
git tag -d "${TAG_NAME}"
fi
fi
# Set the tag name as an output
echo "TAG_NAME=${TAG_NAME}" >> $GITHUB_ENV
echo "TAG_NAME=${TAG_NAME}" >> $GITHUB_OUTPUT
git tag "${TAG_NAME}"
git push origin "${TAG_NAME}"
echo "Tagged release with tag '${TAG_NAME}'"
- name: Print changelog
run: |
cat CHANGELOG.md
- name: Extract Changelog
id: extract_changelog
run: |
set -e
VERSION=${{ env.VERSION }}
START_LINE=$(grep -n "## \[${VERSION}\]" CHANGELOG.md | cut -d: -f1 || true)
if [ -z "$START_LINE" ]; then
if ${{ env.DRY_RUN }}; then
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."
echo -e "\nThere is no available changelog entry for the dry-run." > release_notes.md
exit 0
else
echo "::error file=CHANGELOG.md,title=Extract Changelog::Version '${VERSION}' not found in CHANGELOG.md"
exit 1
fi
fi
TAIL_LINE=$(tail -n +$((START_LINE + 1)) CHANGELOG.md | grep -n "^## " | head -n 1 | cut -d: -f1 || true)
if [ -z "$TAIL_LINE" ]; then
END_LINE=$(wc -l < CHANGELOG.md)
else
END_LINE=$((START_LINE + TAIL_LINE - 1))
fi
sed -n "${START_LINE},${END_LINE}p" CHANGELOG.md | sed '$d' > release_notes.md
cat release_notes.md
shell: bash
- name: Format Changelog
id: format_changelog
run: |
cat release_notes.md
sed -i '1d' release_notes.md # Remove the first line
sed -i 's/###/##/g' release_notes.md # Change headers from ### to ##
shell: bash
- name: Create a GitHub release
id: github_release
uses: ncipollo/release-action@v1
with:
tag: ${{ steps.tag.outputs.tag_name }}
name: ${{ env.VERSION }}
bodyFile: ./release_notes.md
draft: true
prerelease: false
allowUpdates: true
omitBodyDuringUpdate: false
deploy:
name: Deploy to WordPress.org
needs: tag_and_release
if: ${{ !failure() && !cancelled() }}
runs-on: ubuntu-20.04
steps:
- name: Deploy Details
run: |
echo "Tag Name: ${{ needs.tag_and_release.outputs.tag_name }}"
echo "Dry Run: ${{ env.DRY_RUN }}"
echo "Skip Tests: ${{ env.SKIP_TESTS }}"
echo "Version: ${{ env.VERSION }}"
- uses: actions/checkout@v4
with:
ref: ${{ needs.tag_and_release.outputs.tag_name }}
- name: WordPress Plugin Deploy
id: wporg_deploy
uses: 10up/action-wordpress-plugin-deploy@stable
with:
dry-run: ${{ env.DRY_RUN }}
generate-zip: true
env:
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
VERSION: ${{ needs.tag_and_release.outputs.tag_name }}
- name: Update release with ZIP file
uses: ncipollo/release-action@v1
with:
tag: ${{ needs.tag_and_release.outputs.tag_name }}
allowUpdates: true
omitBodyDuringUpdate: true
omitNameDuringUpdate: true
omitDraftDuringUpdate: true
omitPrereleaseDuringUpdate: true
removeArtifacts: true
updateOnlyUnreleased: true
draft: ${{ env.DRY_RUN }}
artifacts: ${{ steps.wporg_deploy.outputs.zip-path }}
artifactContentType: application/zip