Skip to content

Commit e6deb21

Browse files
committed
Test
1 parent 437d6ed commit e6deb21

3 files changed

Lines changed: 152 additions & 92 deletions

File tree

.github/files/test-plugin-update/prepare-zips.sh

Lines changed: 52 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -7,68 +7,65 @@ jq -e '.' <<<"$BETAJSON" &>/dev/null
77

88
mkdir work
99
mkdir zips
10-
while IFS=$'\t' read -r SRC MIRROR SLUG; do
11-
if [[ "$SLUG" == wpcomsh ]]; then
12-
echo "Skipping $SLUG, doesn't work on self-hosted sites."
13-
continue
14-
fi
1510

16-
echo "::group::Creating $SLUG-dev.zip"
17-
mv "build/$MIRROR" "work/$SLUG"
18-
touch "work/$SLUG/ci-flag.txt"
19-
(cd work && zip -r "../zips/${SLUG}-dev.zip" "$SLUG")
20-
rm -rf "work/$SLUG"
21-
echo "::endgroup::"
11+
if [[ "$PLUGIN_SLUG" == wpcomsh ]]; then
12+
echo "Skipping $PLUGIN_SLUG, doesn't work on self-hosted sites."
13+
exit 0
14+
fi
15+
16+
echo "::group::Creating $PLUGIN_SLUG-dev.zip"
17+
mv "build/$PLUGIN_MIRROR" "work/$PLUGIN_SLUG"
18+
touch "work/$PLUGIN_SLUG/ci-flag.txt"
19+
(cd work && zip -r "../zips/${PLUGIN_SLUG}-dev.zip" "$PLUGIN_SLUG")
20+
rm -rf "work/$PLUGIN_SLUG"
21+
echo "::endgroup::"
2222

23-
echo "::group::Fetching $SLUG-trunk.zip..."
24-
BETASLUG="$(jq -r '.extra["beta-plugin-slug"] // .extra["wp-plugin-slug"] // ""' "commit/$SRC/composer.json")"
25-
if [[ -z "$BETASLUG" ]]; then
26-
echo "No beta-plugin-slug or wp-plugin-slug in composer.json, skipping"
23+
echo "::group::Fetching $PLUGIN_SLUG-trunk.zip..."
24+
BETASLUG="$(jq -r '.extra["beta-plugin-slug"] // .extra["wp-plugin-slug"] // ""' "commit/$PLUGIN_SRC/composer.json")"
25+
if [[ -z "$BETASLUG" ]]; then
26+
echo "No beta-plugin-slug or wp-plugin-slug in composer.json, skipping"
27+
else
28+
URL="$(jq -r --arg slug "$BETASLUG" '.[$slug].manifest_url // ""' <<<"$BETAJSON")"
29+
if [[ -z "$URL" ]]; then
30+
echo "Beta slug $BETASLUG is not in plugins.json, skipping"
2731
else
28-
URL="$(jq -r --arg slug "$BETASLUG" '.[$slug].manifest_url // ""' <<<"$BETAJSON")"
29-
if [[ -z "$URL" ]]; then
30-
echo "Beta slug $BETASLUG is not in plugins.json, skipping"
31-
else
32-
JSON="$(curl -L --fail --url "$URL")"
33-
if jq -e '.' <<<"$JSON" &>/dev/null; then
34-
URL="$(jq -r '.trunk.download_url // .master.download_url // ""' <<<"$JSON")"
35-
if [[ -z "$URL" ]]; then
36-
echo "Plugin has no trunk build."
37-
else
38-
curl -L --fail --url "$URL" --output "work/tmp.zip" 2>&1
39-
(cd work && unzip -q tmp.zip)
40-
mv "work/$BETASLUG-dev" "work/$SLUG"
41-
(cd work && zip -qr "../zips/${SLUG}-trunk.zip" "$SLUG")
42-
rm -rf "work/$SLUG" "work/tmp.zip"
43-
fi
32+
JSON="$(curl -L --fail --url "$URL")"
33+
if jq -e '.' <<<"$JSON" &>/dev/null; then
34+
URL="$(jq -r '.trunk.download_url // .master.download_url // ""' <<<"$JSON")"
35+
if [[ -z "$URL" ]]; then
36+
echo "Plugin has no trunk build."
4437
else
45-
echo "::error::Unexpected response from betadownload.jetpack.me for $SLUG"
46-
echo "$JSON"
47-
echo "info=❌ Unexpected response from betadownload.jetpack.me for $SLUG" >> "$GITHUB_OUTPUT"
48-
exit 1
38+
curl -L --fail --url "$URL" --output "work/tmp.zip" 2>&1
39+
(cd work && unzip -q tmp.zip)
40+
mv "work/$BETASLUG-dev" "work/$PLUGIN_SLUG"
41+
(cd work && zip -qr "../zips/${PLUGIN_SLUG}-trunk.zip" "$PLUGIN_SLUG")
42+
rm -rf "work/$PLUGIN_SLUG" "work/tmp.zip"
4943
fi
44+
else
45+
echo "::error::Unexpected response from betadownload.jetpack.me for $PLUGIN_SLUG"
46+
echo "$JSON"
47+
echo "❌ Unexpected response from betadownload.jetpack.me for $PLUGIN_SLUG" >> "$GITHUB_STEP_SUMMARY"
48+
exit 1
5049
fi
5150
fi
52-
echo "::endgroup::"
51+
fi
52+
echo "::endgroup::"
5353

54-
echo "::group::Fetching $SLUG-stable.zip..."
55-
JSON="$(curl "https://api.wordpress.org/plugins/info/1.0/$SLUG.json")"
56-
if jq -e --arg slug "$SLUG" '.slug == $slug' <<<"$JSON" &>/dev/null; then
57-
URL="$(jq -r '.download_link // ""' <<<"$JSON")"
58-
if [[ -z "$URL" ]]; then
59-
echo "Plugin has no stable release."
60-
else
61-
curl -L --fail --url "$URL" --output "zips/$SLUG-stable.zip" 2>&1
62-
fi
63-
elif jq -e '.error == "Plugin not found."' <<<"$JSON" &>/dev/null; then
64-
echo "Plugin is not published."
54+
echo "::group::Fetching $PLUGIN_SLUG-stable.zip..."
55+
JSON="$(curl "https://api.wordpress.org/plugins/info/1.0/$PLUGIN_SLUG.json")"
56+
if jq -e --arg slug "$PLUGIN_SLUG" '.slug == $slug' <<<"$JSON" &>/dev/null; then
57+
URL="$(jq -r '.download_link // ""' <<<"$JSON")"
58+
if [[ -z "$URL" ]]; then
59+
echo "Plugin has no stable release."
6560
else
66-
echo "::error::Unexpected response from WordPress.org API for $SLUG"
67-
echo "$JSON"
68-
echo "info=❌ Unexpected response from WordPress.org API for $SLUG" >> "$GITHUB_OUTPUT"
69-
exit 1
61+
curl -L --fail --url "$URL" --output "zips/$PLUGIN_SLUG-stable.zip" 2>&1
7062
fi
71-
echo "::endgroup::"
72-
done < build/plugins.tsv
73-
74-
echo 'info=' >> "$GITHUB_OUTPUT"
63+
elif jq -e '.error == "Plugin not found."' <<<"$JSON" &>/dev/null; then
64+
echo "Plugin is not published."
65+
else
66+
echo "::error::Unexpected response from WordPress.org API for $PLUGIN_SLUG"
67+
echo "$JSON"
68+
echo "❌ Unexpected response from WordPress.org API for $PLUGIN_SLUG" >> "$GITHUB_STEP_SUMMARY"
69+
exit 1
70+
fi
71+
echo "::endgroup::"

.github/files/test-plugin-update/test.sh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,17 @@ for ZIP in *-dev.zip; do
1414
done
1515

1616
FINISHED=false
17-
OUTPUT=()
1817

1918
function onexit {
2019
if ! "$FINISHED"; then
21-
OUTPUT+=( "💣 The testing script exited unexpectedly." )
20+
echo "💣 The testing script exited unexpectedly." >> "$GITHUB_STEP_SUMMARY"
2221
fi
23-
gh_set_output info "$( printf "%s\n" "${OUTPUT[@]}" )"
2422
}
2523
trap "onexit" EXIT
2624

2725
function failed {
2826
ERRMSG="$1"
29-
OUTPUT+=( "$ERRMSG" )
27+
echo "$ERRMSG" >> "$GITHUB_STEP_SUMMARY"
3028
FAILED=1
3129
EXIT=1
3230
}
@@ -143,7 +141,7 @@ for SLUG in "${SLUGS[@]}"; do
143141
wp --allow-root --quiet option delete fake_plugin_update_url
144142

145143
if [[ -z "$FAILED" ]]; then
146-
OUTPUT+=( "✅ Upgrade of $SLUG from $FROM via $HOW succeeded!" )
144+
echo "✅ Upgrade of $SLUG from $FROM via $HOW succeeded!" >> "$GITHUB_STEP_SUMMARY"
147145
fi
148146
done
149147
done

.github/workflows/post-build.yml

Lines changed: 97 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,83 @@ jobs:
234234
Post-build run skipped because no plugins were built.
235235
token: ${{ steps.get_token.outputs.token }}
236236

237-
upgrade_test:
238-
name: Test plugin upgrades
237+
prepare_upgrade_test:
238+
name: Prepare plugin upgrades matrix
239239
runs-on: ubuntu-latest
240240
needs: [ setup, find_artifact ]
241241
if: needs.find_artifact.outputs.any_plugins == 'true'
242+
outputs:
243+
matrix: ${{ steps.matrix.outputs.matrix }}
244+
timeout-minutes: 5 # 2025-03-13: Should be just a few seconds.
245+
246+
steps:
247+
- uses: actions/checkout@v4
248+
249+
- name: Get token
250+
id: get_token
251+
uses: ./.github/actions/gh-app-token
252+
env:
253+
# Work around a weird node 16/openssl 3 issue in the docker env
254+
OPENSSL_CONF: '/dev/null'
255+
with:
256+
app_id: ${{ secrets.JP_LAUNCH_CONTROL_ID }}
257+
private_key: ${{ secrets.JP_LAUNCH_CONTROL_KEY }}
258+
259+
- name: Notify check in progress
260+
uses: ./.github/actions/check-run
261+
with:
262+
id: ${{ needs.setup.outputs.upgrade_check }}
263+
status: in_progress
264+
title: Test started...
265+
summary: |
266+
${{ env.SUMMARY }}
267+
268+
See run [#${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.
269+
token: ${{ steps.get_token.outputs.token }}
270+
271+
- name: Download build artifact
272+
env:
273+
TOKEN: ${{ github.token }}
274+
ZIPURL: ${{ needs.find_artifact.outputs.zip_url }}
275+
shell: bash
276+
run: |
277+
for (( i=1; i<=2; i++ )); do
278+
[[ $i -gt 1 ]] && sleep 10
279+
echo "::group::Downloading artifact (attempt $i/2)"
280+
curl -v -L --get \
281+
--header "Authorization: token $TOKEN" \
282+
--url "$ZIPURL" \
283+
--output "artifact.zip"
284+
echo "::endgroup::"
285+
if [[ -e "artifact.zip" ]] && zipinfo artifact.zip &>/dev/null; then
286+
break
287+
fi
288+
done
289+
[[ ! -e "artifact.zip" ]] && { echo "::error::Failed to download artifact."; exit 1; }
290+
unzip artifact.zip
291+
tar --xz -xvvf build.tar.xz build/plugins.tsv
292+
293+
- name: Prepare matrix
294+
id: matrix
295+
run: |
296+
RET=$( jq -c -s --raw-input 'split( "\n" )[0:-1] | map( split( "\t" ) | { src: .[0], mirror: .[1], slug: .[2] } )' build/plugins.tsv )
297+
jq '.' <<<"$RET"
298+
echo "matrix=$RET" >> "$GITHUB_OUTPUT"
299+
300+
upgrade_test:
301+
name: Test upgrades for ${{ matrix.slug }}
302+
runs-on: ubuntu-latest
303+
needs: [ setup, find_artifact, prepare_upgrade_test ]
304+
if: needs.find_artifact.outputs.any_plugins == 'true'
242305
timeout-minutes: 15 # 2022-08-26: Successful runs seem to take about 6 minutes, but give some extra time for the downloads.
306+
strategy:
307+
fail-fast: false
308+
matrix:
309+
include: ${{ fromJson( needs.prepare_upgrade_test.outputs.matrix ) }}
310+
env:
311+
PLUGIN_SRC: ${{ matrix.src }}
312+
PLUGIN_MIRROR: ${{ matrix.mirror }}
313+
PLUGIN_SLUG: ${{ matrix.slug }}
243314
services:
244315
db:
245316
image: mariadb:lts
@@ -263,6 +334,7 @@ jobs:
263334
HOST_PORT: 80
264335
ports:
265336
- 80:80
337+
266338
steps:
267339
- uses: actions/checkout@v4
268340
with:
@@ -272,28 +344,6 @@ jobs:
272344
ref: ${{ github.event.workflow_run.head_commit.id }}
273345
path: commit
274346

275-
- name: Get token
276-
id: get_token
277-
uses: ./trunk/.github/actions/gh-app-token
278-
env:
279-
# Work around a weird node 16/openssl 3 issue in the docker env
280-
OPENSSL_CONF: '/dev/null'
281-
with:
282-
app_id: ${{ secrets.JP_LAUNCH_CONTROL_ID }}
283-
private_key: ${{ secrets.JP_LAUNCH_CONTROL_KEY }}
284-
285-
- name: Notify check in progress
286-
uses: ./trunk/.github/actions/check-run
287-
with:
288-
id: ${{ needs.setup.outputs.upgrade_check }}
289-
status: in_progress
290-
title: Test started...
291-
summary: |
292-
${{ env.SUMMARY }}
293-
294-
See run [#${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.
295-
token: ${{ steps.get_token.outputs.token }}
296-
297347
- name: Download build artifact
298348
env:
299349
TOKEN: ${{ github.token }}
@@ -320,25 +370,40 @@ jobs:
320370
run: trunk/.github/files/test-plugin-update/setup.sh
321371

322372
- name: Prepare plugin zips
323-
id: zips
324373
run: trunk/.github/files/test-plugin-update/prepare-zips.sh
325374

326375
- name: Test upgrades
327-
id: tests
328376
run: trunk/.github/files/test-plugin-update/test.sh
329377

378+
post_upgrade_test:
379+
name: Finalize plugin test
380+
runs-on: ubuntu-latest
381+
needs: [ setup, find_artifact, upgrade_test ]
382+
if: always() && needs.find_artifact.outputs.any_plugins == 'true'
383+
timeout-minutes: 5 # 2025-03-13: Should be just a few seconds.
384+
385+
steps:
386+
- uses: actions/checkout@v4
387+
388+
- name: Get token
389+
id: get_token
390+
uses: ./.github/actions/gh-app-token
391+
env:
392+
# Work around a weird node 16/openssl 3 issue in the docker env
393+
OPENSSL_CONF: '/dev/null'
394+
with:
395+
app_id: ${{ secrets.JP_LAUNCH_CONTROL_ID }}
396+
private_key: ${{ secrets.JP_LAUNCH_CONTROL_KEY }}
397+
330398
- name: Notify final status
331-
if: always()
332-
uses: ./trunk/.github/actions/check-run
399+
uses: ./.github/actions/check-run
333400
with:
334401
id: ${{ needs.setup.outputs.upgrade_check }}
335-
conclusion: ${{ job.status }}
336-
title: ${{ job.status == 'success' && 'Tests passed' || job.status == 'cancelled' && 'Cancelled' || 'Tests failed' }}
402+
conclusion: ${{ needs.upgrade_test.result }}
403+
title: ${{ needs.upgrade_test.result == 'success' && 'Tests passed' || needs.upgrade_test.result == 'cancelled' && 'Cancelled' || 'Tests failed' }}
337404
summary: |
338405
${{ env.SUMMARY }}
339406
340-
${{ steps.zips.outputs.info }}${{ steps.tests.outputs.info }}
341-
342407
See run [#${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.
343408
token: ${{ steps.get_token.outputs.token }}
344409

0 commit comments

Comments
 (0)