Skip to content

Commit 2336b80

Browse files
authored
Merge branch 'main' into copilot/fix-1570774-181716041-20411eca-34f5-409a-a217-dd2c5535347a
2 parents df39bed + 4e30390 commit 2336b80

File tree

4 files changed

+178
-0
lines changed

4 files changed

+178
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Check Branch Alias
2+
3+
on:
4+
release:
5+
types: [released]
6+
workflow_dispatch:
7+
8+
permissions: {}
9+
10+
jobs:
11+
check-branch-alias:
12+
uses: wp-cli/.github/.github/workflows/reusable-check-branch-alias.yml@main
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
name: Check Branch Alias
2+
3+
on:
4+
workflow_call:
5+
release:
6+
types: [released]
7+
workflow_dispatch:
8+
9+
# Cancels all previous workflow runs for pull requests that have not completed.
10+
concurrency:
11+
# The concurrency group contains the workflow name and the branch name for pull requests
12+
# or the commit hash for any other events.
13+
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
14+
cancel-in-progress: true
15+
16+
permissions:
17+
contents: read
18+
19+
jobs:
20+
check-branch-alias:
21+
name: Check and update branch-alias
22+
runs-on: ubuntu-latest
23+
if: ${{ github.repository_owner == 'wp-cli' }}
24+
permissions:
25+
contents: write # Required for creating pull requests
26+
pull-requests: write # Required for creating pull requests
27+
28+
steps:
29+
- name: Check out source code
30+
uses: actions/checkout@v5
31+
with:
32+
fetch-depth: 0 # Fetch all history for all tags
33+
token: ${{ secrets.GITHUB_TOKEN }}
34+
35+
- name: Set up PHP
36+
uses: shivammathur/setup-php@v2
37+
with:
38+
php-version: 'latest'
39+
tools: composer
40+
41+
- name: Check existence of composer.json file
42+
id: check_composer_file
43+
uses: andstor/file-existence-action@v3
44+
with:
45+
files: "composer.json"
46+
47+
- name: Check and update branch alias
48+
if: steps.check_composer_file.outputs.files_exists == 'true'
49+
id: check_alias
50+
run: |
51+
# Get the latest stable release tag (exclude pre-releases)
52+
LATEST_TAG=$(git tag --list 'v[0-9]*.[0-9]*.[0-9]*' --sort=-version:refname | head -n 1)
53+
54+
if [ -z "$LATEST_TAG" ]; then
55+
echo "No stable release tags found, skipping branch-alias check"
56+
echo "needs_update=false" >> "$GITHUB_OUTPUT"
57+
exit 0
58+
fi
59+
60+
echo "Latest tag: $LATEST_TAG"
61+
62+
# Extract version numbers (remove 'v' prefix and any pre-release/build metadata)
63+
VERSION="${LATEST_TAG#v}"
64+
# Remove any pre-release or build metadata (e.g., -alpha, +build)
65+
VERSION="${VERSION%%-*}"
66+
VERSION="${VERSION%%+*}"
67+
68+
# Parse major, minor, and patch versions
69+
IFS='.' read -r MAJOR MINOR _ <<< "$VERSION"
70+
71+
# Validate that MAJOR and MINOR are numeric
72+
if ! [[ "$MAJOR" =~ ^[0-9]+$ ]] || ! [[ "$MINOR" =~ ^[0-9]+$ ]]; then
73+
echo "Invalid version format: $VERSION"
74+
echo "needs_update=false" >> "$GITHUB_OUTPUT"
75+
exit 0
76+
fi
77+
78+
# Calculate next minor version
79+
NEXT_MINOR=$((MINOR + 1))
80+
EXPECTED_ALIAS="${MAJOR}.${NEXT_MINOR}.x-dev"
81+
82+
echo "Expected branch-alias: $EXPECTED_ALIAS"
83+
84+
# Determine which branch key is being used (dev-main or dev-master)
85+
BRANCH_KEY=""
86+
CURRENT_ALIAS=""
87+
88+
# Try dev-main first
89+
if composer config extra.branch-alias.dev-main > /dev/null 2>&1; then
90+
BRANCH_KEY="dev-main"
91+
CURRENT_ALIAS=$(composer config extra.branch-alias.dev-main)
92+
# Try dev-master if dev-main doesn't exist
93+
elif composer config extra.branch-alias.dev-master > /dev/null 2>&1; then
94+
BRANCH_KEY="dev-master"
95+
CURRENT_ALIAS=$(composer config extra.branch-alias.dev-master)
96+
else
97+
echo "No branch-alias found in composer.json, will use dev-main"
98+
BRANCH_KEY="dev-main"
99+
CURRENT_ALIAS=""
100+
fi
101+
102+
echo "Current branch-alias ($BRANCH_KEY): $CURRENT_ALIAS"
103+
104+
if [ "$CURRENT_ALIAS" != "$EXPECTED_ALIAS" ]; then
105+
echo "Branch alias needs update"
106+
{
107+
echo "needs_update=true"
108+
echo "expected_alias=$EXPECTED_ALIAS"
109+
echo "current_alias=$CURRENT_ALIAS"
110+
echo "branch_key=$BRANCH_KEY"
111+
echo "latest_tag=$LATEST_TAG"
112+
} >> "$GITHUB_OUTPUT"
113+
else
114+
echo "Branch alias is up to date"
115+
echo "needs_update=false" >> "$GITHUB_OUTPUT"
116+
fi
117+
118+
- name: Update composer.json
119+
if: steps.check_alias.outputs.needs_update == 'true'
120+
run: |
121+
BRANCH_KEY="${{ steps.check_alias.outputs.branch_key }}"
122+
EXPECTED_ALIAS="${{ steps.check_alias.outputs.expected_alias }}"
123+
124+
# Update the branch-alias using composer command
125+
composer config "extra.branch-alias.$BRANCH_KEY" "$EXPECTED_ALIAS"
126+
127+
- name: Create Pull Request
128+
if: steps.check_alias.outputs.needs_update == 'true'
129+
uses: peter-evans/create-pull-request@v7
130+
with:
131+
token: ${{ secrets.GITHUB_TOKEN }}
132+
commit-message: "Update branch-alias to ${{ steps.check_alias.outputs.expected_alias }}"
133+
title: "Update branch-alias to ${{ steps.check_alias.outputs.expected_alias }}"
134+
body: |
135+
This PR updates the Composer `branch-alias` configuration to reflect the latest release.
136+
137+
- Latest release: ${{ steps.check_alias.outputs.latest_tag }}
138+
- Previous branch-alias: `${{ steps.check_alias.outputs.current_alias }}`
139+
- Updated branch-alias: `${{ steps.check_alias.outputs.expected_alias }}`
140+
141+
The branch-alias should point to the next minor development version after the latest release.
142+
branch: update-branch-alias
143+
delete-branch: true
144+
labels: |
145+
automated-pr

.github/workflows/sync-workflows.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
^.github/workflows/copilot-setup-steps.yml
2626
^.github/workflows/regenerate-readme.yml
2727
^.github/workflows/issue-triage.yml
28+
^.github/workflows/check-branch-alias.yml
2829
^.github/workflows/manage-labels.yml
2930
^AGENTS.md
3031
TARGET_REPOS: |

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,26 @@ This package cannot be used directly. It is a container to provide centralized f
1111

1212
See: [https://help.github.com/en/articles/creating-a-default-community-health-file-for-your-organization](https://help.github.com/en/articles/creating-a-default-community-health-file-for-your-organization)
1313

14+
### GitHub Actions Workflows
15+
16+
This repository contains reusable GitHub Actions workflows that are automatically synced to all WP-CLI repositories:
17+
18+
- **Code Quality Checks** (`code-quality.yml`) - Runs linting, PHPCS, PHPStan, and other code quality tools
19+
- **Regenerate README** (`regenerate-readme.yml`) - Automatically regenerates README.md files from source
20+
- **Check Branch Alias** (`check-branch-alias.yml`) - Monitors and updates Composer branch-alias configuration
21+
22+
#### Branch Alias Checker
23+
24+
The branch alias checker workflow automatically ensures that the Composer `branch-alias` in each repository's `composer.json` is up-to-date. It:
25+
26+
1. Runs weekly (every Monday at 2 AM UTC) or can be triggered manually
27+
2. Checks the latest release tag
28+
3. Calculates the expected branch-alias (next minor version after the latest release)
29+
4. Compares with the current branch-alias
30+
5. Creates a pull request if an update is needed
31+
32+
For example, if a repository has released version `2.12.0`, the branch-alias should be set to `2.13.x-dev` to point to the next development version.
33+
1434
## Installing
1535

1636
There's nothing to install, this package cannot be used directly.

0 commit comments

Comments
 (0)