Skip to content

Explore building plugin versions dynamically #4289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
Open
50 changes: 50 additions & 0 deletions .github/actions/get-wordpress-plugin-versions/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Get released versions for a WordPress plugin
description: Action to return the released versions for a WordPress plugin

inputs:
plugin-slug:
description: The WordPress plugin slug
type: string
required: true
version-count:
description: The number of released versions to return
type: number
default: '3'
outputs:
versions-json:
description: The released versions for the plugin as a JSON array
value: ${{ steps.get-versions-json.outputs.versions-json }}
versions-text:
description: The released versions for the plugin as a newline-separated list
value: ${{ steps.get-versions-text.outputs.versions-text }}

runs:
using: "composite"
steps:
- name: Get plugin info
id: get-plugin-info
shell: bash
run: |
curl -s 'https://api.wordpress.org/plugins/info/1.0/${{ inputs.plugin-slug }}.json' > '${{ inputs.plugin-slug }}.json'

- name: Get versions as JSON
id: get-versions-json
shell: bash
# jq does the following:
# - filters the versions to only include x.y.z versions, i.e. ignoring beta, rc, and dev versions etc
# - groups the versions by the first two parts of the version number, i.e. major.minor
# - reverses the order of the versions, so the highest major.minor versions are first
# - limits the number of major.versions to the number specified in the version-count input
# - returns the last version for each major.minor version
run: |
echo 'versions-json<<EOF' >> $GITHUB_OUTPUT
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
echo 'EOF' >> $GITHUB_OUTPUT

- name: Get versions in text format
id: get-versions-text
shell: bash
run: |
echo 'versions-text<<EOF' >> $GITHUB_OUTPUT
echo '${{ steps.get-versions-json.outputs.versions-json }}' | jq -r '.[]' >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
66 changes: 66 additions & 0 deletions .github/actions/get-wordpress-versions/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Get released versions of WordPress
description: Action to return the released versions of WordPress

inputs:
version-count:
description: The number of released versions to return
type: number
default: '3'

outputs:
versions-json:
description: The released WordPress versions as a JSON array
value: ${{ steps.get-versions-json.outputs.versions-json }}
versions-text:
description: The released WordPress versions as a newline-separated list
value: ${{ steps.get-versions-text.outputs.versions-text }}


runs:
using: "composite"
steps:
- name: Build cache key
id: build-cache-key
shell: bash
run: |
echo "cache-timestamp=$( date -u "+%Y%m%d%H" )" >> $GITHUB_OUTPUT

- name: Check WordPress version cache
id: check-wordpress-version-cache
uses: actions/cache@v4
with:
key: wordpress-versions-${{ steps.build-cache-key.outputs.cache-timestamp }}
path: .wp-version-cache
enableCrossOsArchive: true

- name: Get WordPress versions
if: steps.check-wordpress-version-cache.outputs.cache-hit != 'true'
id: fetch-all-wordpress-versions
shell: bash
run: |
mkdir .wp-version-cache
curl -s 'https://api.wordpress.org/core/version-check/1.7/' > .wp-version-cache/all-wordpress-versions.json

- name: Get WordPress versions as JSON
id: get-versions-json
shell: bash
# The jq filtering does the following:
# - extracts the offers array
# - filters the offers to keep only the version field for each entry
# - removes duplicate versions
# - groups the versions by the first two parts of the version number, i.e. major.minor
# - reverses the order of the versions, so the highest major.minor versions are first
# - limits the number of major.minor versions to the number specified in the version-count input
# - returns the last version for each major.minor version
run: |
echo 'versions-json<<EOF' >> $GITHUB_OUTPUT
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
echo 'EOF' >> $GITHUB_OUTPUT

- name: Get WordPress versions in text format
id: get-versions-text
shell: bash
run: |
echo 'versions-text<<EOF' >> $GITHUB_OUTPUT
echo '${{ steps.get-versions-json.outputs.versions-json }}' | jq -r '.[]' >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
43 changes: 35 additions & 8 deletions .github/workflows/php-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,37 @@ on:
pull_request

jobs:
get-woocommerce-versions:
runs-on: ubuntu-22.04
outputs:
woocommerce-versions-json: ${{ steps.get-released-woocommerce-versions.outputs.versions-json }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Get WooCommerce plugin versions
id: get-released-woocommerce-versions
uses: ./.github/actions/get-wordpress-plugin-versions
with:
plugin-slug: woocommerce
version-count: 3
get-wordpress-versions:
runs-on: ubuntu-22.04
outputs:
wordpress-versions-json: ${{ steps.get-wordpress-versions.outputs.versions-json }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Get WordPress versions
id: get-wordpress-versions
uses: ./.github/actions/get-wordpress-versions
with:
version-count: 3

test:
runs-on: ubuntu-22.04
needs: [ get-woocommerce-versions, get-wordpress-versions ]
strategy:
fail-fast: false
max-parallel: 16
Expand All @@ -16,20 +45,18 @@ jobs:
include:
# WooCommerce
- woocommerce_support_policy: L
woocommerce: '9.8.1'
woocommerce: ${{ fromJson(needs.get-woocommerce-versions.outputs.woocommerce-versions-json)[0] }}
- woocommerce_support_policy: L-1
woocommerce: '9.7.1'
woocommerce: ${{ fromJson(needs.get-woocommerce-versions.outputs.woocommerce-versions-json)[1] }}
- woocommerce_support_policy: L-2
woocommerce: '9.6.2'
woocommerce: ${{ fromJson(needs.get-woocommerce-versions.outputs.woocommerce-versions-json)[2] }}
# WordPress
- wordpress_support_policy: L
wordpress: '6.7.2'
wordpress: ${{ fromJson(needs.get-wordpress-versions.outputs.wordpress-versions-json)[0] }}
- wordpress_support_policy: L-1
wordpress: '6.6.2'
# WooCommerce 9.5.0+ requires WordPress 6.6+
# (we'll keep two versions from the 6.6 branch until Apr when WP 6.8 is released)
wordpress: ${{ fromJson(needs.get-wordpress-versions.outputs.wordpress-versions-json)[1] }}
- wordpress_support_policy: L-2
wordpress: '6.6'
wordpress: ${{ fromJson(needs.get-wordpress-versions.outputs.wordpress-versions-json)[2] }}
# PHP
- php_support_policy: L
php: '8.3'
Expand Down
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* Update - Add support for customer order notes and express checkout
* Dev - Minor fix to e2e setup code
* Dev - Make PHP error log from Docker container available in docker/logs/php/error.log
* Dev - Build dynamic WordPress and WooCommerce dependencies for unit tests

= 9.4.1 - 2025-04-17 =
* Dev - Forces rollback of version 9.4.0.
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,6 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
* Update - Add support for customer order notes and express checkout
* Dev - Minor fix to e2e setup code
* Dev - Make PHP error log from Docker container available in docker/logs/php/error.log
* Dev - Build dynamic WordPress and WooCommerce dependencies for unit tests

[See changelog for all versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).
Loading