-
Notifications
You must be signed in to change notification settings - Fork 6
359 lines (317 loc) · 17.4 KB
/
release.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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
name: Deploy and Create Release
# example: gh workflow run release.yml -f tag_name=v1.1.4 -f deploy_to_wordpress=true
on:
workflow_dispatch:
inputs:
tag_name:
type: string
required: true
deploy_to_wordpress:
type: boolean
description: Deploy to WordPress
default: true
required: true
permissions:
contents: write
env:
# Allow ddev get to use a GitHub token to prevent rate limiting by tests
DDEV_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG_NAME: ${{ github.event.inputs.tag_name }}
jobs:
deploy-create-release:
name: Deploy and create release
runs-on: ubuntu-latest
steps:
- name: Check naming convention
run: |
VERIF=$(echo ${{ env.TAG_NAME }} | grep -E "^v([0-9]{1,}\.)([0-9]{1,}\.)([0-9]{1,})(-(alpha|beta)\.[0-9]{1,})?$")
if [ ! ${VERIF} ]
then
echo "Tag name '${{ env.TAG_NAME }}' does not comply with naming convention vX.Y.Z"
exit 1
fi
- name: Set version number without v
id: set-version-number
run: |
echo "version_number=$(echo ${{ github.event.inputs.tag_name }} | sed 's/v//g' )" >> $GITHUB_OUTPUT
- name: Clone sources
uses: actions/checkout@v4
- name: Check version consistency in files
# Check crowdsec.php (2), readme.txt (1), inc/Constants.php (1) and CHANGELOG.md (3)
run: |
CURRENT_DATE=$(date +'%Y-%m-%d')
CHANGELOG_VERSION=$(grep -o -E "## \[(.*)\].* - $CURRENT_DATE" CHANGELOG.md | head -1 | sed 's/ //g')
echo $CURRENT_DATE
echo $CHANGELOG_VERSION
echo "##[${{ steps.set-version-number.outputs.version_number }}]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/tag/${{ env.TAG_NAME }})-$CURRENT_DATE"
if [[ $CHANGELOG_VERSION == "##[${{ steps.set-version-number.outputs.version_number }}]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/tag/${{ env.TAG_NAME }})-$CURRENT_DATE" ]]
then
echo "Version in CHANGELOG.md: OK"
else
echo "Version in CHANGELOG.md: KO"
exit 1
fi
COMPARISON=$(grep -oP "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/compare/\K(.*)$" CHANGELOG.md | head -1)
LAST_TAG=$(curl -Ls -o /dev/null -w %{url_effective} $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/latest | grep -oP "\/tag\/\K(.*)$")
if [[ $COMPARISON == "$LAST_TAG...${{ env.TAG_NAME }})" ]]
then
echo "VERSION COMPARISON OK"
else
echo "VERSION COMPARISON KO"
echo $COMPARISON
echo "$LAST_TAG...${{ env.TAG_NAME }})"
exit 1
fi
VERSION=$(grep -E "Version: (.*)" crowdsec.php | sed 's/ //g')
echo $VERSION
echo "*Version:${{ steps.set-version-number.outputs.version_number }}"
if [[ $VERSION == "*Version:${{ steps.set-version-number.outputs.version_number}}" ]]
then
echo "Version in crowdsec.php: OK"
else
echo "Version in crowdsec.php: KO"
exit 1
fi
CROWDSEC_STABLE=$(grep -E "Stable tag: (.*)" crowdsec.php | sed 's/ //g')
echo $CROWDSEC_STABLE
echo "*Stabletag:${{ steps.set-version-number.outputs.version_number }}"
if [[ $CROWDSEC_STABLE == "*Stabletag:${{ steps.set-version-number.outputs.version_number }}" ]]
then
echo "Stable tag in crowdsec.php: OK"
else
echo "Stable tag in crowdsec.php: KO"
exit 1
fi
README_STABLE=$(grep -E "Stable tag: (.*)" readme.txt | sed 's/ //g')
echo $README_STABLE
echo "Stabletag:${{ steps.set-version-number.outputs.version_number }}"
if [[ $README_STABLE == "Stabletag:${{ steps.set-version-number.outputs.version_number }}" ]]
then
echo "Stable tag in readme.txt: OK"
else
echo "Stable tag in readme.txt: KO"
exit 1
fi
CONSTANT_VERSION=$(grep -E "VERSION = 'v(.*)" inc/Constants.php | sed 's/[\x27(),/ ]//g')
echo $CONSTANT_VERSION
echo "publicconstVERSION=${{ env.TAG_NAME }};"
if [[ $CONSTANT_VERSION == "publicconstVERSION=${{ env.TAG_NAME }};" ]]
then
echo "Version in inc/Constants.php: OK"
else
echo "Version in inc/Constants.php: KO"
exit 1
fi
- name: Create Tag
uses: actions/github-script@v7
with:
github-token: ${{ github.token }}
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: "refs/tags/${{ env.TAG_NAME }}",
sha: context.sha
})
- name: WordPress Plugin Deploy
if: github.event.inputs.deploy_to_wordpress == 'true'
id: deploy
uses: 10up/action-wordpress-plugin-deploy@2.2.2
with:
generate-zip: true
env:
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
SLUG: crowdsec
VERSION: ${{ steps.set-version-number.outputs.version_number }}
- name: Prepare release notes
run: |
VERSION_RELEASE_NOTES=$(awk -v ver="[${{ steps.set-version-number.outputs.version_number }}]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/tag/${{ env.TAG_NAME }})" '/^## / { if (p) { exit }; if ($2 == ver) { p=1; next} } p && NF' CHANGELOG.md | sed ':a;N;$!ba;s/\n---/ /g')
echo "$VERSION_RELEASE_NOTES" >> CHANGELOG.txt
cat CHANGELOG.txt
- name: Create release with Wordpress zip
if: github.event.inputs.deploy_to_wordpress == 'true'
uses: softprops/action-gh-release@v2
with:
files: crowdsec.zip
body_path: CHANGELOG.txt
name: ${{ steps.set-version-number.outputs.version_number }}
tag_name: ${{ env.TAG_NAME }}
draft: false
prerelease: false
- name: Create release without Wordpress zip
if: github.event.inputs.deploy_to_wordpress != 'true'
uses: softprops/action-gh-release@v2
with:
body_path: CHANGELOG.txt
name: ${{ steps.set-version-number.outputs.version_number }}
tag_name: ${{ env.TAG_NAME }}
draft: false
prerelease: false
end-to-end-release-zip-test:
strategy:
fail-fast: false
matrix:
wp-version: [ "4.9", "5.0", "5.9", "6.0", "6.6" ]
php-version: [ "7.2", "7.4", "8.0" ]
exclude:
- { php-version: "7.4", wp-version: "4.9" }
- { php-version: "8.0", wp-version: "4.9" }
- { php-version: "7.4", wp-version: "5.0" }
- { php-version: "8.0", wp-version: "5.0" }
name: End-to-end release test suite
runs-on: ubuntu-latest
if: success()
needs: [ deploy-create-release ]
env:
EXTENSION_NAME: "CrowdSec_Bouncer"
EXTENSION_PATH: "wp-content/plugins/crowdsec"
GITHUB_ORIGIN: "crowdsecurity/cs-wordpress-bouncer"
steps:
- name: Install DDEV
# @see https://ddev.readthedocs.io/en/stable/#installationupgrade-script-linux-and-macos-armarm64-and-amd64-architectures
run: |
curl -fsSL https://apt.fury.io/drud/gpg.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/ddev.gpg > /dev/null
echo "deb [signed-by=/etc/apt/trusted.gpg.d/ddev.gpg] https://apt.fury.io/drud/ * *" | sudo tee /etc/apt/sources.list.d/ddev.list
sudo apt-get -q update
sudo apt-get -q -y install libnss3-tools ddev
mkcert -install
ddev config global --instrumentation-opt-in=false --omit-containers=ddev-ssh-agent
- name: Set WP_VERSION_CODE env
# used in some directory path and conventional file naming
# Example : 5.6.5 => wp565
id: set-wp-version-code
run: |
echo "wp_version_code=$(echo wp${{ matrix.wp-version }} | sed 's/\.//g' )" >> $GITHUB_OUTPUT
- name: Create empty WordPress DDEV project (with Apache)
run: ddev config --project-type=wordpress --project-name=${{ steps.set-wp-version-code.outputs.wp_version_code }} --php-version=${{ matrix.php-version }} --webserver-type=apache-fpm
- name: Disable automatic update
run: |
# @see https://wordpress.org/documentation/article/configuring-automatic-background-updates/#constant-to-disable-all-updates
sed -i -e 's/#ddev-generated//g' wp-config-ddev.php
echo "define( 'AUTOMATIC_UPDATER_DISABLED', true );" >> wp-config-ddev.php
- name: Add Redis, Memcached, Crowdsec and Playwright
run: |
ddev get ddev/ddev-redis
ddev get ddev/ddev-memcached
ddev get julienloizelet/ddev-playwright
# override redis.conf
ddev get julienloizelet/ddev-tools
ddev get julienloizelet/ddev-crowdsec-php
- name: Start DDEV
uses: nick-fields/retry@v3
with:
timeout_minutes: 5
max_attempts: 3
shell: bash
command: |
ddev start
- name: Download WordPress
run: ddev wp core download --version=${{ matrix.wp-version }}
- name: Setup WordPress ${{ matrix.wp-version }} with PHP ${{ matrix.php-version }}
run: |
ddev exec wp core install --url='https://${{ steps.set-wp-version-code.outputs.wp_version_code }}.ddev.site' --title='WordPress' --admin_user='admin' --admin_password='admin123' --admin_email='admin@admin.com'
- name: Set LAST_TAG env
id: set-last-tag
run: |
echo "last_tag=$(curl -Ls -o /dev/null -w %{url_effective} https://github.com/${{ env.GITHUB_ORIGIN }}/releases/latest | grep -oP "\/tag\/v\K(.*)$")" >> $GITHUB_OUTPUT
- name: Clone files from last release
uses: actions/checkout@v4
with:
path: raw_sources
ref: "v${{ steps.set-last-tag.outputs.last_tag }}"
repository: "${{ env.GITHUB_ORIGIN }}"
- name: Retrieve last stable release zip
run: |
curl -fL https://downloads.wordpress.org/plugin/crowdsec.${{ steps.set-last-tag.outputs.last_tag }}.zip -o crowdsec.$LAST_TAG.zip
unzip crowdsec.${{ steps.set-last-tag.outputs.last_tag }}.zip -d ${{ github.workspace }}/wp-content/plugins
- name: Copy needed tests files
run: |
cp -r raw_sources/tests wp-content/plugins/crowdsec
cp -r raw_sources/.github wp-content/plugins/crowdsec
- name: Prepare for playwright test
run: |
ddev exec -s crowdsec apk add iproute2
cp .ddev/okaeli-add-on/wordpress/custom_files/crowdsec/php/wp_appsec_custom_upload.php wp_appsec_custom_upload.php
cat .ddev/okaeli-add-on/wordpress/custom_files/crowdsec/html/appsec-upload.html | ddev wp post create --post_type=page --post_status=publish --post_title="AppSec Upload" -
cat .ddev/okaeli-add-on/wordpress/custom_files/crowdsec/html/appsec-post.html | ddev wp post create --post_type=page --post_status=publish --post_title="AppSec" -
ddev wp rewrite structure "/%postname%/"
mkdir -p crowdsec/tls
mkdir -p crowdsec/geolocation
cp .ddev/okaeli-add-on/wordpress/custom_files/crowdsec/php/cache-actions-with-wordpress-load.php cache-actions.php
cp -r .ddev/okaeli-add-on/custom_files/crowdsec/cfssl/* crowdsec/tls
ddev maxmind-download DEFAULT GeoLite2-City crowdsec/geolocation
ddev maxmind-download DEFAULT GeoLite2-Country crowdsec/geolocation
cd crowdsec/geolocation
sha256sum -c GeoLite2-Country.tar.gz.sha256.txt
sha256sum -c GeoLite2-City.tar.gz.sha256.txt
tar -xf GeoLite2-Country.tar.gz
tar -xf GeoLite2-City.tar.gz
rm GeoLite2-Country.tar.gz GeoLite2-Country.tar.gz.sha256.txt GeoLite2-City.tar.gz GeoLite2-City.tar.gz.sha256.txt
cd ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev/__scripts__
chmod +x test-init.sh
./test-init.sh
chmod +x run-tests.sh
- name: Some DEBUG information
run: |
ddev --version
ddev exec php -v
ddev exec -s crowdsec crowdsec -version
- name: Run Plugin activation tests
uses: ./wp-content/plugins/crowdsec/.github/workflows/end-to-end/run-single-test
with:
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
file_path: 1-activate-plugin.js
- name: Configure CrowdSec and Wordpress bouncer plugin
run: |
ddev crowdsec-config
- name: Run Live mode remediation tests
uses: ./wp-content/plugins/crowdsec/.github/workflows/end-to-end/run-single-test
with:
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
file_path: 2-live-mode-remediations.js
- name: Run more Live mode remediation tests
uses: ./wp-content/plugins/crowdsec/.github/workflows/end-to-end/run-single-test
with:
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
file_path: 3-live-mode-more.js
- name: Run Live mode cache tests
uses: ./wp-content/plugins/crowdsec/.github/workflows/end-to-end/run-single-test
with:
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
file_path: 4-live-mode-cache.js
- name: Prepare cron usage
run: |
sed -i 's/fastcgi_finish_request/\/\/fastcgi_finish_request/g' wp-cron.php
- name: Run Stream mode tests
uses: ./wp-content/plugins/crowdsec/.github/workflows/end-to-end/run-single-test
with:
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
file_path: 5-stream-mode.js
- name: Run Redis tests
uses: ./wp-content/plugins/crowdsec/.github/workflows/end-to-end/run-single-test
with:
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
file_path: 6-redis.js
- name: Run Memcached tests
uses: ./wp-content/plugins/crowdsec/.github/workflows/end-to-end/run-single-test
with:
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
file_path: 7-memcached.js
- name: Run Geolocation tests
uses: ./wp-content/plugins/crowdsec/.github/workflows/end-to-end/run-single-test
with:
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
file_path: 8-geolocation.js
- name: Run AppSec tests
uses: ./wp-content/plugins/crowdsec/.github/workflows/end-to-end/run-single-test
with:
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
file_path: 11-appsec.js
- name: tmate debugging session
uses: mxschmitt/action-tmate@v3
with:
limit-access-to-actor: true
github-token: ${{ secrets.GITHUB_TOKEN }}
timeout-minutes: 30
if: failure()