-
Notifications
You must be signed in to change notification settings - Fork 6
Add automated branch-alias checker workflow #164
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
03f0313
Initial plan
Copilot 7451447
Add branch-alias checker workflow
Copilot 8edf1f5
Remove actionlint binary and sync check-branch-alias workflow
Copilot afbfd87
Add documentation for workflows in README
Copilot 8a0f161
Improve version parsing and composer.json handling in branch-alias wo…
Copilot 8166749
Add explicit permissions to workflows for security
Copilot 3d7541d
Use composer commands and trigger on release instead of weekly schedule
Copilot 55ae499
Change release trigger from 'published' to 'released'
Copilot 9d4a9b2
Merge branch 'main' into copilot/add-gha-check-branch-alias
swissspidy 2572f07
Merge branch 'main' into copilot/add-gha-check-branch-alias
swissspidy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| name: Check Branch Alias | ||
|
|
||
| on: | ||
| release: | ||
| types: [released] | ||
| workflow_dispatch: | ||
|
|
||
| permissions: {} | ||
|
|
||
| jobs: | ||
| check-branch-alias: | ||
| uses: wp-cli/.github/.github/workflows/reusable-check-branch-alias.yml@main |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| name: Check Branch Alias | ||
|
|
||
| on: | ||
| workflow_call: | ||
| release: | ||
| types: [released] | ||
| workflow_dispatch: | ||
|
|
||
| # Cancels all previous workflow runs for pull requests that have not completed. | ||
| concurrency: | ||
| # The concurrency group contains the workflow name and the branch name for pull requests | ||
| # or the commit hash for any other events. | ||
| group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| check-branch-alias: | ||
| name: Check and update branch-alias | ||
| runs-on: ubuntu-latest | ||
| if: ${{ github.repository_owner == 'wp-cli' }} | ||
| permissions: | ||
| contents: write # Required for creating pull requests | ||
| pull-requests: write # Required for creating pull requests | ||
|
|
||
| steps: | ||
| - name: Check out source code | ||
| uses: actions/checkout@v5 | ||
| with: | ||
| fetch-depth: 0 # Fetch all history for all tags | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Set up PHP | ||
| uses: shivammathur/setup-php@v2 | ||
| with: | ||
| php-version: 'latest' | ||
| tools: composer | ||
|
|
||
| - name: Check existence of composer.json file | ||
| id: check_composer_file | ||
| uses: andstor/file-existence-action@v3 | ||
| with: | ||
| files: "composer.json" | ||
|
|
||
| - name: Check and update branch alias | ||
| if: steps.check_composer_file.outputs.files_exists == 'true' | ||
| id: check_alias | ||
| run: | | ||
| # Get the latest stable release tag (exclude pre-releases) | ||
| LATEST_TAG=$(git tag --list 'v[0-9]*.[0-9]*.[0-9]*' --sort=-version:refname | head -n 1) | ||
|
|
||
| if [ -z "$LATEST_TAG" ]; then | ||
| echo "No stable release tags found, skipping branch-alias check" | ||
| echo "needs_update=false" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "Latest tag: $LATEST_TAG" | ||
|
|
||
| # Extract version numbers (remove 'v' prefix and any pre-release/build metadata) | ||
| VERSION="${LATEST_TAG#v}" | ||
| # Remove any pre-release or build metadata (e.g., -alpha, +build) | ||
| VERSION="${VERSION%%-*}" | ||
| VERSION="${VERSION%%+*}" | ||
|
|
||
| # Parse major, minor, and patch versions | ||
| IFS='.' read -r MAJOR MINOR _ <<< "$VERSION" | ||
|
|
||
| # Validate that MAJOR and MINOR are numeric | ||
| if ! [[ "$MAJOR" =~ ^[0-9]+$ ]] || ! [[ "$MINOR" =~ ^[0-9]+$ ]]; then | ||
| echo "Invalid version format: $VERSION" | ||
| echo "needs_update=false" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Calculate next minor version | ||
| NEXT_MINOR=$((MINOR + 1)) | ||
| EXPECTED_ALIAS="${MAJOR}.${NEXT_MINOR}.x-dev" | ||
|
|
||
| echo "Expected branch-alias: $EXPECTED_ALIAS" | ||
|
|
||
| # Determine which branch key is being used (dev-main or dev-master) | ||
| BRANCH_KEY="" | ||
| CURRENT_ALIAS="" | ||
|
|
||
| # Try dev-main first | ||
| if composer config extra.branch-alias.dev-main > /dev/null 2>&1; then | ||
| BRANCH_KEY="dev-main" | ||
| CURRENT_ALIAS=$(composer config extra.branch-alias.dev-main) | ||
| # Try dev-master if dev-main doesn't exist | ||
| elif composer config extra.branch-alias.dev-master > /dev/null 2>&1; then | ||
| BRANCH_KEY="dev-master" | ||
| CURRENT_ALIAS=$(composer config extra.branch-alias.dev-master) | ||
| else | ||
| echo "No branch-alias found in composer.json, will use dev-main" | ||
| BRANCH_KEY="dev-main" | ||
| CURRENT_ALIAS="" | ||
| fi | ||
|
|
||
| echo "Current branch-alias ($BRANCH_KEY): $CURRENT_ALIAS" | ||
|
|
||
| if [ "$CURRENT_ALIAS" != "$EXPECTED_ALIAS" ]; then | ||
| echo "Branch alias needs update" | ||
| { | ||
| echo "needs_update=true" | ||
| echo "expected_alias=$EXPECTED_ALIAS" | ||
| echo "current_alias=$CURRENT_ALIAS" | ||
| echo "branch_key=$BRANCH_KEY" | ||
| echo "latest_tag=$LATEST_TAG" | ||
| } >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "Branch alias is up to date" | ||
| echo "needs_update=false" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
|
||
| - name: Update composer.json | ||
| if: steps.check_alias.outputs.needs_update == 'true' | ||
| run: | | ||
| BRANCH_KEY="${{ steps.check_alias.outputs.branch_key }}" | ||
| EXPECTED_ALIAS="${{ steps.check_alias.outputs.expected_alias }}" | ||
|
|
||
| # Update the branch-alias using composer command | ||
| composer config "extra.branch-alias.$BRANCH_KEY" "$EXPECTED_ALIAS" | ||
|
|
||
| - name: Create Pull Request | ||
| if: steps.check_alias.outputs.needs_update == 'true' | ||
| uses: peter-evans/create-pull-request@v7 | ||
| with: | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| commit-message: "Update branch-alias to ${{ steps.check_alias.outputs.expected_alias }}" | ||
| title: "Update branch-alias to ${{ steps.check_alias.outputs.expected_alias }}" | ||
| body: | | ||
| This PR updates the Composer `branch-alias` configuration to reflect the latest release. | ||
|
|
||
| - Latest release: ${{ steps.check_alias.outputs.latest_tag }} | ||
| - Previous branch-alias: `${{ steps.check_alias.outputs.current_alias }}` | ||
| - Updated branch-alias: `${{ steps.check_alias.outputs.expected_alias }}` | ||
|
|
||
| The branch-alias should point to the next minor development version after the latest release. | ||
| branch: update-branch-alias | ||
| delete-branch: true | ||
| labels: | | ||
| automated-pr |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.