Skip to content

Commit 43f7a29

Browse files
authored
Merge branch 'main' into feature/wp-version-resolve
2 parents 52c024b + 0c5c2e9 commit 43f7a29

File tree

6 files changed

+135
-9
lines changed

6 files changed

+135
-9
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
---
2+
name: WP Versions Data Fetcher
3+
4+
on:
5+
schedule:
6+
- cron: '0 5 * * *'
7+
workflow_dispatch:
8+
inputs:
9+
max_retries:
10+
description: 'Max retries to fetch data from WPOrg API'
11+
default: 3
12+
required: false
13+
type: number
14+
15+
concurrency:
16+
group: ${{ github.repository }}-${{ github.workflow }}
17+
cancel-in-progress: true
18+
19+
permissions: {}
20+
21+
env:
22+
ARTIFACTS_BRANCH: 'artifacts'
23+
FEATURE_BRANCH: 'sync-wp-versions'
24+
FILE_PATH: 'wp-versions.json'
25+
MAX_RETRIES: ${{ inputs.max_retries || 3 }}
26+
WP_ORG_API_URL: 'https://api.wordpress.org/core/stable-check/1.0/'
27+
28+
jobs:
29+
fetch-versions:
30+
runs-on: ubuntu-latest
31+
timeout-minutes: 10
32+
permissions:
33+
contents: write
34+
pull-requests: write
35+
steps:
36+
- name: Checkout repository
37+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
38+
with:
39+
ref: ${{ env.ARTIFACTS_BRANCH }}
40+
41+
- name: Check if feature branch exists
42+
id: remote-branch
43+
run: |
44+
echo "exists=$([[ -z $(git ls-remote --heads origin ${{ env.FEATURE_BRANCH }}) ]] && echo "0" || echo "1")" >> $GITHUB_OUTPUT
45+
46+
- name: Create feature branch
47+
if: steps.remote-branch.outputs.exists == '0'
48+
run: |
49+
git checkout -b ${{ env.FEATURE_BRANCH }}
50+
51+
- name: Checkout feature branch
52+
if: steps.remote-branch.outputs.exists == '1'
53+
run: |
54+
git fetch --all --prune
55+
git checkout ${{ env.FEATURE_BRANCH }}
56+
git pull --no-rebase
57+
58+
- name: Fetch WP Versions
59+
run: |
60+
BACKOFF=10
61+
for i in $(seq 1 $MAX_RETRIES); do
62+
echo "Fetching WP versions, attempt $i"
63+
RES_CODE=$(curl -sL -w "%{http_code}" $WP_ORG_API_URL -o /tmp/wp-versions.json)
64+
if [ $RES_CODE -eq 200 ]; then
65+
mv /tmp/wp-versions.json $FILE_PATH
66+
echo "::notice::WP versions data has been fetched successfully."
67+
break
68+
fi
69+
echo "Failed to fetch WP versions, attempt $i"
70+
if [ $i -eq $MAX_RETRIES ]; then
71+
echo "::error::Failed to fetch WP versions from $WP_ORG_API_URL after $MAX_RETRIES attempts"
72+
exit 1
73+
fi
74+
echo "Retrying in $BACKOFF seconds"
75+
sleep $BACKOFF
76+
BACKOFF=$((BACKOFF * 2))
77+
done
78+
79+
- name: Track modified files
80+
id: version-file
81+
run: |
82+
IS_MODIFIED=$(git ls-files --modified wp-versions.json)
83+
if [ -n "$IS_MODIFIED" ]; then
84+
DIFF=$(git diff ${{ env.ARTIFACTS_BRANCH }} -- $FILE_PATH)
85+
echo "# Modified WP Versions Data" >> $GITHUB_STEP_SUMMARY
86+
echo "<details><summary>WP Versions Data Diff</summary>" >> $GITHUB_STEP_SUMMARY
87+
echo "" >> $GITHUB_STEP_SUMMARY
88+
echo "\`\`\`diff" >> $GITHUB_STEP_SUMMARY
89+
echo "$DIFF" >> $GITHUB_STEP_SUMMARY
90+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
91+
echo "</details>" >> $GITHUB_STEP_SUMMARY
92+
echo "modified=true" >> $GITHUB_OUTPUT
93+
else
94+
echo "::notice::WP versions data has not been modified."
95+
exit 0
96+
fi
97+
98+
- name: Set git user
99+
if: steps.version-file.outputs.modified == 'true'
100+
run: |
101+
# See: https://api.github.com/users/github-actions[bot]
102+
git config --global user.name "github-actions[bot]"
103+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
104+
105+
- name: Commit WP Versions Data
106+
if: steps.version-file.outputs.modified == 'true'
107+
run: |
108+
git add $FILE_PATH
109+
git commit -m "Update $FILE_PATH on $(date -u)" --signoff
110+
111+
- name: Push changes
112+
if: steps.version-file.outputs.modified == 'true'
113+
run: |
114+
git push origin ${{ env.FEATURE_BRANCH }}
115+
116+
- name: Create Pull Request
117+
run: |
118+
body="## Summary
119+
Update WP versions data file with the \`${WP_ORG_API_URL}\` endpoint response."
120+
delimiter="${body//$'\n'/'%0A'}"
121+
echo "body<<${delimiter}" >> $GITHUB_OUTPUT
122+
echo "$body" >> $GITHUB_OUTPUT
123+
echo "${delimiter}" >> $GITHUB_OUTPUT
124+
gh pr create --base ${{ env.ARTIFACTS_BRANCH }} --head ${{ env.FEATURE_BRANCH }} --title "Update WP Versions Data" --body "$body" --label "scope:artifacts" || true
125+
env:
126+
GH_TOKEN: ${{ github.token }}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"wp-cli/eval-command": "^1 || ^2",
2222
"wp-cli/wp-cli": "^2.5.1",
2323
"wp-coding-standards/wpcs": "^3",
24-
"yoast/phpunit-polyfills": "^1.0.3"
24+
"yoast/phpunit-polyfills": "^1.0.3 || ^2.0.1"
2525
},
2626
"require-dev": {
2727
"roave/security-advisories": "dev-latest"

phpunit.xml.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
>
55
<testsuites>
66
<testsuite name="default">
7-
<directory prefix="spec-" suffix=".php">tests/</directory>
8-
<directory prefix="test-" suffix=".php">tests/</directory>
7+
<directory prefix="Spec" suffix=".php">tests/</directory>
8+
<directory prefix="Test" suffix=".php">tests/tests</directory>
99
</testsuite>
1010
</testsuites>
1111
</phpunit>

tests/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
require_once VENDOR_DIR . '/autoload.php';
3131
require_once WP_CLI_ROOT . '/php/utils.php';
32-
require_once __DIR__ . '/wp-cli-testcase.php';
32+
require_once __DIR__ . '/includes/TestCase.php';
3333

3434
function wpcli_tests_include_config( array $config_filenames = [] ) {
3535
$config_filename = false;
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use WP_CLI\Tests\TestCase;
44
use WP_CLI\Utils;
55

6-
class BehatTagsTest extends TestCase {
6+
class TestBehatTags extends TestCase {
77

88
public $temp_dir;
99

@@ -39,7 +39,7 @@ public function test_behat_tags_wp_version_github_token( $env, $expected ) {
3939
putenv( 'WP_VERSION' );
4040
putenv( 'GITHUB_TOKEN' );
4141

42-
$behat_tags = dirname( __DIR__ ) . '/utils/behat-tags.php';
42+
$behat_tags = dirname( dirname( __DIR__ ) ) . '/utils/behat-tags.php';
4343

4444
$contents = '@require-wp-4.6 @require-wp-4.8 @require-wp-4.9 @less-than-wp-4.6 @less-than-wp-4.8 @less-than-wp-4.9';
4545
file_put_contents( $this->temp_dir . '/features/wp_version.feature', $contents );
@@ -64,7 +64,7 @@ public function test_behat_tags_wp_version_github_token( $env, $expected ) {
6464
putenv( false === $env_github_token ? 'GITHUB_TOKEN' : "GITHUB_TOKEN=$env_github_token" );
6565
}
6666

67-
public function data_behat_tags_wp_version_github_token() {
67+
public static function data_behat_tags_wp_version_github_token() {
6868
return array(
6969
array( 'WP_VERSION=4.5', '[email protected]&&[email protected]&&[email protected]&&~@github-api' ),
7070
array( 'WP_VERSION=4.6', '[email protected]&&[email protected]&&[email protected]&&~@github-api' ),
@@ -85,7 +85,7 @@ public function test_behat_tags_php_version() {
8585

8686
putenv( 'GITHUB_TOKEN' );
8787

88-
$behat_tags = dirname( __DIR__ ) . '/utils/behat-tags.php';
88+
$behat_tags = dirname( dirname( __DIR__ ) ) . '/utils/behat-tags.php';
8989

9090
$php_version = substr( PHP_VERSION, 0, 3 );
9191
$contents = '';
@@ -142,7 +142,7 @@ public function test_behat_tags_extension() {
142142

143143
putenv( 'GITHUB_TOKEN' );
144144

145-
$behat_tags = dirname( __DIR__ ) . '/utils/behat-tags.php';
145+
$behat_tags = dirname( dirname( __DIR__ ) ) . '/utils/behat-tags.php';
146146

147147
file_put_contents( $this->temp_dir . '/features/extension.feature', '@require-extension-imagick @require-extension-curl' );
148148

0 commit comments

Comments
 (0)