Update wp-cli framework #1706
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
| name: Update wp-cli framework | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| - master | |
| schedule: | |
| - cron: '17 4 * * *' # Run every day on a seemly random time. | |
| # Cancels all previous workflow runs for the same branch that have not yet completed. | |
| concurrency: | |
| # The concurrency group contains the workflow name and the branch name. | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| update-framework: #---------------------------------------------------------- | |
| name: Update wp-cli framework | |
| runs-on: ubuntu-latest | |
| if: ${{ github.repository_owner == 'wp-cli' }} | |
| steps: | |
| - name: Check out source code | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 | |
| with: | |
| token: ${{ secrets.ACTIONS_BOT }} | |
| - name: Set up PHP environment | |
| uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # v2 | |
| with: | |
| php-version: 'latest' | |
| env: | |
| COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Check existence of composer.json file | |
| id: check_composer_file | |
| run: echo "files_exists=$(test -f composer.json && echo true || echo false)" >> "$GITHUB_OUTPUT" | |
| - name: Install Composer dependencies & cache dependencies | |
| if: steps.check_composer_file.outputs.files_exists == 'true' | |
| uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # v4 | |
| env: | |
| COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }} | |
| with: | |
| # Bust the cache at least once a month - output format: YYYY-MM. | |
| custom-cache-suffix: $(date -u "+%Y-%m") | |
| - name: Update wp-cli framework | |
| run: | | |
| composer update wp-cli/wp-cli --with-all-dependencies | |
| - name: Commit and Create Pull Request | |
| env: | |
| GH_TOKEN: ${{ secrets.ACTIONS_BOT }} | |
| PR_BODY: | | |
| **This is an automated pull-request** | |
| Updates the `wp-cli/wp-cli` framework to the latest changeset. | |
| run: | | |
| if [ -n "$(git status --porcelain)" ]; then | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git checkout -b update-framework | |
| git add composer.json composer.lock | |
| git commit -m "Update wp-cli framework" | |
| git push -f origin update-framework | |
| PR_NUMBER=$(gh pr list --head update-framework --json number --jq '.[0].number // empty') | |
| if [ -z "$PR_NUMBER" ]; then | |
| gh pr create \ | |
| --title "Update wp-cli framework" \ | |
| --body "$PR_BODY" \ | |
| --label "scope:framework" \ | |
| --base "${{ github.event.repository.default_branch }}" \ | |
| --head "update-framework" | |
| else | |
| gh pr edit "$PR_NUMBER" \ | |
| --title "Update wp-cli framework" \ | |
| --body "$PR_BODY" \ | |
| --add-label "scope:framework" \ | |
| --base "${{ github.event.repository.default_branch }}" | |
| fi | |
| fi |