Skip to content

Commit dc9cad8

Browse files
authored
Determine WordPress and WooCommerce plugin versions dynamically via GitHub Actions (#4289)
* Explore building plugin versions dynamically * Get get-wordpress-plugin-versions action working * Wire version fetch into php-tests workflow * Remove test-matrix workflow * Clean up plugin versions * Add WordPress version action; wire into php-tests * Switch order for WordPress versions * Update jq filters to work with jq 1.6 * Changelog * Remove debugging action * Ensure we pick highest WordPress minor version * Try adding an hourly cache * Restore changelog entry * Prevent plugin name injections * Fix typo in variable * Try wrap using " quotes
1 parent b032b5e commit dc9cad8

File tree

5 files changed

+160
-8
lines changed

5 files changed

+160
-8
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Get released versions for a WordPress plugin
2+
description: Action to return the released versions for a WordPress plugin
3+
4+
inputs:
5+
plugin-slug:
6+
description: The WordPress plugin slug
7+
type: string
8+
required: true
9+
version-count:
10+
description: The number of released versions to return
11+
type: number
12+
default: '3'
13+
outputs:
14+
versions-json:
15+
description: The released versions for the plugin as a JSON array
16+
value: ${{ steps.get-versions-json.outputs.versions-json }}
17+
versions-text:
18+
description: The released versions for the plugin as a newline-separated list
19+
value: ${{ steps.get-versions-text.outputs.versions-text }}
20+
21+
runs:
22+
using: "composite"
23+
steps:
24+
- name: Get plugin info
25+
id: get-plugin-info
26+
shell: bash
27+
env:
28+
WP_PLUGIN_SLUG: ${{ inputs.plugin-slug }}
29+
run: |
30+
if [[ ! "$WP_PLUGIN_SLUG" =~ ^[a-z]([a-z0-9]|-|_)*[a-z]$ ]];
31+
then
32+
echo "Invalid plugin slug: $WP_PLUGIN_SLUG"
33+
exit 1
34+
fi
35+
curl -s "https://api.wordpress.org/plugins/info/1.0/$WP_PLUGIN_SLUG.json" > "$WP_PLUGIN_SLUG.json"
36+
37+
- name: Get versions as JSON
38+
id: get-versions-json
39+
shell: bash
40+
# jq does the following:
41+
# - filters the versions to only include x.y.z versions, i.e. ignoring beta, rc, and dev versions etc
42+
# - groups the versions by the first two parts of the version number, i.e. major.minor
43+
# - reverses the order of the versions, so the highest major.minor versions are first
44+
# - limits the number of major.versions to the number specified in the version-count input
45+
# - returns the last version for each major.minor version
46+
run: |
47+
echo 'versions-json<<EOF' >> $GITHUB_OUTPUT
48+
cat ${{ inputs.plugin-slug }}.json | jq '.versions | keys | map( select( test("^\\d+\\.\\d+\\.\\d+$"; "s") ) ) | group_by( split( "." ) | .[0:2] | join( "." ) ) | reverse | .[0:${{ inputs.version-count }}] | [.[][-1]]' >> $GITHUB_OUTPUT
49+
echo 'EOF' >> $GITHUB_OUTPUT
50+
51+
- name: Get versions in text format
52+
id: get-versions-text
53+
shell: bash
54+
run: |
55+
echo 'versions-text<<EOF' >> $GITHUB_OUTPUT
56+
echo '${{ steps.get-versions-json.outputs.versions-json }}' | jq -r '.[]' >> $GITHUB_OUTPUT
57+
echo 'EOF' >> $GITHUB_OUTPUT
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Get released versions of WordPress
2+
description: Action to return the released versions of WordPress
3+
4+
inputs:
5+
version-count:
6+
description: The number of released versions to return
7+
type: number
8+
default: '3'
9+
10+
outputs:
11+
versions-json:
12+
description: The released WordPress versions as a JSON array
13+
value: ${{ steps.get-versions-json.outputs.versions-json }}
14+
versions-text:
15+
description: The released WordPress versions as a newline-separated list
16+
value: ${{ steps.get-versions-text.outputs.versions-text }}
17+
18+
19+
runs:
20+
using: "composite"
21+
steps:
22+
- name: Build cache key
23+
id: build-cache-key
24+
shell: bash
25+
run: |
26+
echo "cache-timestamp=$( date -u "+%Y%m%d%H" )" >> $GITHUB_OUTPUT
27+
28+
- name: Check WordPress version cache
29+
id: check-wordpress-version-cache
30+
uses: actions/cache@v4
31+
with:
32+
key: wordpress-versions-${{ steps.build-cache-key.outputs.cache-timestamp }}
33+
path: .wp-version-cache
34+
enableCrossOsArchive: true
35+
36+
- name: Get WordPress versions
37+
if: steps.check-wordpress-version-cache.outputs.cache-hit != 'true'
38+
id: fetch-all-wordpress-versions
39+
shell: bash
40+
run: |
41+
mkdir .wp-version-cache
42+
curl -s 'https://api.wordpress.org/core/version-check/1.7/' > .wp-version-cache/all-wordpress-versions.json
43+
44+
- name: Get WordPress versions as JSON
45+
id: get-versions-json
46+
shell: bash
47+
# The jq filtering does the following:
48+
# - extracts the offers array
49+
# - filters the offers to keep only the version field for each entry
50+
# - removes duplicate versions
51+
# - groups the versions by the first two parts of the version number, i.e. major.minor
52+
# - reverses the order of the versions, so the highest major.minor versions are first
53+
# - limits the number of major.minor versions to the number specified in the version-count input
54+
# - returns the last version for each major.minor version
55+
run: |
56+
echo 'versions-json<<EOF' >> $GITHUB_OUTPUT
57+
cat .wp-version-cache/all-wordpress-versions.json | jq '.offers | [.[].version] | unique | group_by( split( "." ) | .[0:2] | join( "." ) ) | reverse | .[0:${{ inputs.version-count }}] | [.[][-1]]' >> $GITHUB_OUTPUT
58+
echo 'EOF' >> $GITHUB_OUTPUT
59+
60+
- name: Get WordPress versions in text format
61+
id: get-versions-text
62+
shell: bash
63+
run: |
64+
echo 'versions-text<<EOF' >> $GITHUB_OUTPUT
65+
echo '${{ steps.get-versions-json.outputs.versions-json }}' | jq -r '.[]' >> $GITHUB_OUTPUT
66+
echo 'EOF' >> $GITHUB_OUTPUT

.github/workflows/php-tests.yml

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,37 @@ on:
44
pull_request
55

66
jobs:
7+
get-woocommerce-versions:
8+
runs-on: ubuntu-22.04
9+
outputs:
10+
woocommerce-versions-json: ${{ steps.get-released-woocommerce-versions.outputs.versions-json }}
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
15+
- name: Get WooCommerce plugin versions
16+
id: get-released-woocommerce-versions
17+
uses: ./.github/actions/get-wordpress-plugin-versions
18+
with:
19+
plugin-slug: woocommerce
20+
version-count: 3
21+
get-wordpress-versions:
22+
runs-on: ubuntu-22.04
23+
outputs:
24+
wordpress-versions-json: ${{ steps.get-wordpress-versions.outputs.versions-json }}
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v4
28+
29+
- name: Get WordPress versions
30+
id: get-wordpress-versions
31+
uses: ./.github/actions/get-wordpress-versions
32+
with:
33+
version-count: 3
34+
735
test:
836
runs-on: ubuntu-22.04
37+
needs: [ get-woocommerce-versions, get-wordpress-versions ]
938
strategy:
1039
fail-fast: false
1140
max-parallel: 16
@@ -16,20 +45,18 @@ jobs:
1645
include:
1746
# WooCommerce
1847
- woocommerce_support_policy: L
19-
woocommerce: '9.8.1'
48+
woocommerce: ${{ fromJson(needs.get-woocommerce-versions.outputs.woocommerce-versions-json)[0] }}
2049
- woocommerce_support_policy: L-1
21-
woocommerce: '9.7.1'
50+
woocommerce: ${{ fromJson(needs.get-woocommerce-versions.outputs.woocommerce-versions-json)[1] }}
2251
- woocommerce_support_policy: L-2
23-
woocommerce: '9.6.2'
52+
woocommerce: ${{ fromJson(needs.get-woocommerce-versions.outputs.woocommerce-versions-json)[2] }}
2453
# WordPress
2554
- wordpress_support_policy: L
26-
wordpress: '6.7.2'
55+
wordpress: ${{ fromJson(needs.get-wordpress-versions.outputs.wordpress-versions-json)[0] }}
2756
- wordpress_support_policy: L-1
28-
wordpress: '6.6.2'
29-
# WooCommerce 9.5.0+ requires WordPress 6.6+
30-
# (we'll keep two versions from the 6.6 branch until Apr when WP 6.8 is released)
57+
wordpress: ${{ fromJson(needs.get-wordpress-versions.outputs.wordpress-versions-json)[1] }}
3158
- wordpress_support_policy: L-2
32-
wordpress: '6.6'
59+
wordpress: ${{ fromJson(needs.get-wordpress-versions.outputs.wordpress-versions-json)[2] }}
3360
# PHP
3461
- php_support_policy: L
3562
php: '8.3'

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Fix - Fix payment method title display when new payment settings experience is enabled
77
* Fix - Prevent styles from non-checkout pages affecting the appearance of Stripe element.
88
* Fix - Send correct attribute when setting the default payment method.
9+
* Dev - Build dynamic WordPress and WooCommerce dependencies for unit tests
910

1011
= 9.5.1 - 2025-05-17 =
1112
* Fix - Add a fetch cooldown to the payment method configuration retrieval endpoint to prevent excessive requests.

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
117117
* Fix - Fix payment method title display when new payment settings experience is enabled
118118
* Fix - Prevent styles from non-checkout pages affecting the appearance of Stripe element.
119119
* Fix - Send correct attribute when setting the default payment method.
120+
* Dev - Build dynamic WordPress and WooCommerce dependencies for unit tests
120121

121122

122123
[See changelog for full details across versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).

0 commit comments

Comments
 (0)