|
1 | | -# This workflow automatically deletes the branch associated with a pull request |
2 | | -# after it has been merged, unless the branch is protected (e.g., main, dev, staging). |
3 | | -# It helps keep the repository clean by removing merged feature or bug-fix branches. |
| 1 | +# This workflow keeps WordPress "Tested up to" metadata current. |
| 2 | +# It scans tracked PHP, Markdown, and text files without assuming repository-specific |
| 3 | +# metadata filenames, then opens a pull request when values need to be updated to |
| 4 | +# the latest WordPress major.minor release. |
4 | 5 |
|
5 | | -name: Branch Cleanup |
| 6 | +name: WordPress Tested Up To |
6 | 7 |
|
7 | 8 | on: |
8 | | - pull_request: |
9 | | - types: [closed] |
| 9 | + schedule: |
| 10 | + - cron: '23 12 * * *' |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 14 | + cancel-in-progress: true |
10 | 15 |
|
11 | 16 | permissions: |
12 | 17 | contents: write |
13 | | - pull-requests: read |
| 18 | + pull-requests: write |
14 | 19 |
|
15 | 20 | env: |
16 | 21 | PLUGIN_SLUG: optimizations-ace-mc |
17 | 22 |
|
18 | 23 | jobs: |
19 | | - cleanup: |
| 24 | + tested-up-to: |
| 25 | + name: Update Tested Up To Metadata |
20 | 26 | runs-on: ubuntu-latest |
21 | 27 |
|
22 | 28 | steps: |
23 | | - - uses: actions/checkout@v6 |
24 | | - with: |
25 | | - fetch-depth: 0 |
26 | | - token: ${{ secrets.GITHUB_TOKEN }} |
| 29 | + - name: Checkout code |
| 30 | + uses: actions/checkout@v6 |
27 | 31 |
|
28 | | - - name: Delete merged branch |
29 | | - if: github.event.pull_request.merged == true && github.event.pull_request.head.repo.full_name == github.repository |
30 | | - env: |
31 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
32 | | - BRANCH_NAME: ${{ github.event.pull_request.head.ref }} |
33 | | - REPOSITORY: ${{ github.repository }} |
| 32 | + - name: Download WordPress version data |
34 | 33 | run: | |
35 | | - echo "Checking branch: $BRANCH_NAME" |
| 34 | + curl --fail --silent --show-error --location \ |
| 35 | + --proto '=https' --tlsv1.2 \ |
| 36 | + https://api.wordpress.org/core/version-check/1.7/ \ |
| 37 | + --output wordpress-version-check.json |
| 38 | +
|
| 39 | + - name: Update WordPress Tested Up To metadata |
| 40 | + run: python3 .github/scripts/check-wordpress-tested-up-to.py --fix |
36 | 41 |
|
37 | | - # Check protected branches. Quotes prevent injection. |
38 | | - if [[ "$BRANCH_NAME" =~ ^(main|master|dev|develop|staging|production)$ ]]; then |
39 | | - echo "::warning::Skipping deletion of protected branch: $BRANCH_NAME" |
40 | | - exit 0 |
| 42 | + - name: Remove downloaded version data |
| 43 | + run: rm -f wordpress-version-check.json |
| 44 | + |
| 45 | + - name: Check for changes |
| 46 | + id: changes |
| 47 | + run: | |
| 48 | + if git diff --quiet; then |
| 49 | + echo "has_changes=false" >> "$GITHUB_OUTPUT" |
| 50 | + echo "WordPress Tested up to metadata is up to date" |
| 51 | + else |
| 52 | + echo "has_changes=true" >> "$GITHUB_OUTPUT" |
| 53 | + echo "WordPress Tested up to metadata was updated" |
| 54 | + git diff --name-only |
41 | 55 | fi |
42 | 56 |
|
43 | | - # Attempt branch deletion. Quotes prevent injection. |
44 | | - echo "Attempting to delete branch: $BRANCH_NAME" |
45 | | - if git push origin --delete "$BRANCH_NAME" 2>/dev/null; then |
46 | | - echo "::notice::Successfully deleted branch: $BRANCH_NAME" |
| 57 | + - name: Create or update pull request |
| 58 | + if: steps.changes.outputs.has_changes == 'true' |
| 59 | + env: |
| 60 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 61 | + BRANCH_NAME: chore/update-wordpress-tested-up-to |
| 62 | + BASE_BRANCH: ${{ github.event.repository.default_branch }} |
| 63 | + PR_TITLE: 'chore: Update WordPress Tested up to metadata' |
| 64 | + run: | |
| 65 | + git config --local user.email "github-actions[bot]@users.noreply.github.com" |
| 66 | + git config --local user.name "github-actions[bot]" |
| 67 | +
|
| 68 | + git switch --create "$BRANCH_NAME" |
| 69 | + git add --update |
| 70 | + git commit -m "chore: update WordPress Tested up to metadata" |
| 71 | +
|
| 72 | + git fetch origin "$BRANCH_NAME:refs/remotes/origin/$BRANCH_NAME" 2>/dev/null || true |
| 73 | + git push --force-with-lease origin "HEAD:$BRANCH_NAME" |
| 74 | +
|
| 75 | + PR_BODY_FILE="$(mktemp)" |
| 76 | + cat > "$PR_BODY_FILE" <<'EOF' |
| 77 | + ## WordPress Tested Up To Update |
| 78 | +
|
| 79 | + This PR updates the plugin metadata to match the latest WordPress major.minor release reported by WordPress.org. |
| 80 | +
|
| 81 | + See the diff in this PR for details. |
| 82 | +
|
| 83 | + --- |
| 84 | + *This PR was automatically generated by the [WordPress Tested Up To](https://github.com/${{ github.repository }}/blob/main/.github/workflows/wordpress-tested-up-to.yml) workflow.* |
| 85 | + EOF |
| 86 | +
|
| 87 | + EXISTING_PR_URL="$( |
| 88 | + gh pr list \ |
| 89 | + --repo "$GITHUB_REPOSITORY" \ |
| 90 | + --head "$BRANCH_NAME" \ |
| 91 | + --state open \ |
| 92 | + --json url \ |
| 93 | + --jq '.[0].url // ""' |
| 94 | + )" |
| 95 | +
|
| 96 | + if [ -n "$EXISTING_PR_URL" ]; then |
| 97 | + gh pr edit "$EXISTING_PR_URL" --title "$PR_TITLE" --body-file "$PR_BODY_FILE" |
| 98 | + PR_URL="$EXISTING_PR_URL" |
| 99 | + echo "::notice::Updated pull request: $PR_URL" |
47 | 100 | else |
48 | | - echo "::error::Failed to delete branch: $BRANCH_NAME" |
49 | | - exit 1 |
| 101 | + PR_URL="$( |
| 102 | + gh pr create \ |
| 103 | + --repo "$GITHUB_REPOSITORY" \ |
| 104 | + --base "$BASE_BRANCH" \ |
| 105 | + --head "$BRANCH_NAME" \ |
| 106 | + --title "$PR_TITLE" \ |
| 107 | + --body-file "$PR_BODY_FILE" |
| 108 | + )" |
| 109 | + echo "::notice::Created pull request: $PR_URL" |
50 | 110 | fi |
| 111 | +
|
| 112 | + gh pr edit "$PR_URL" --add-label automation --add-label maintenance || \ |
| 113 | + echo "::warning::Pull request was created, but labels could not be applied." |
0 commit comments