diff --git a/.github/actions/get-wordpress-plugin-versions/action.yml b/.github/actions/get-wordpress-plugin-versions/action.yml new file mode 100644 index 0000000000..b5848a9869 --- /dev/null +++ b/.github/actions/get-wordpress-plugin-versions/action.yml @@ -0,0 +1,57 @@ +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 + env: + WP_PLUGIN_SLUG: ${{ inputs.plugin-slug }} + run: | + if [[ ! "$WP_PLUGIN_SLUG" =~ ^[a-z]([a-z0-9]|-|_)*[a-z]$ ]]; + then + echo "Invalid plugin slug: $WP_PLUGIN_SLUG" + exit 1 + fi + curl -s "https://api.wordpress.org/plugins/info/1.0/$WP_PLUGIN_SLUG.json" > "$WP_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<> $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<> $GITHUB_OUTPUT + echo '${{ steps.get-versions-json.outputs.versions-json }}' | jq -r '.[]' >> $GITHUB_OUTPUT + echo 'EOF' >> $GITHUB_OUTPUT diff --git a/.github/actions/get-wordpress-versions/action.yaml b/.github/actions/get-wordpress-versions/action.yaml new file mode 100644 index 0000000000..c8c246ee2e --- /dev/null +++ b/.github/actions/get-wordpress-versions/action.yaml @@ -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<> $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<> $GITHUB_OUTPUT + echo '${{ steps.get-versions-json.outputs.versions-json }}' | jq -r '.[]' >> $GITHUB_OUTPUT + echo 'EOF' >> $GITHUB_OUTPUT diff --git a/.github/workflows/php-tests.yml b/.github/workflows/php-tests.yml index 3a54232db7..21c6a1b640 100644 --- a/.github/workflows/php-tests.yml +++ b/.github/workflows/php-tests.yml @@ -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 @@ -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' diff --git a/changelog.txt b/changelog.txt index d88fda66a7..48ca43432d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -6,6 +6,7 @@ * Fix - Fix payment method title display when new payment settings experience is enabled * Fix - Prevent styles from non-checkout pages affecting the appearance of Stripe element. * Fix - Send correct attribute when setting the default payment method. +* Dev - Build dynamic WordPress and WooCommerce dependencies for unit tests = 9.5.1 - 2025-05-17 = * Fix - Add a fetch cooldown to the payment method configuration retrieval endpoint to prevent excessive requests. diff --git a/readme.txt b/readme.txt index 7d1ec99570..78681c320b 100644 --- a/readme.txt +++ b/readme.txt @@ -117,6 +117,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o * Fix - Fix payment method title display when new payment settings experience is enabled * Fix - Prevent styles from non-checkout pages affecting the appearance of Stripe element. * Fix - Send correct attribute when setting the default payment method. +* Dev - Build dynamic WordPress and WooCommerce dependencies for unit tests [See changelog for full details across versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).