From 2c5a6db95b2eed063f01bb73c33a2ba0d0fed4ae Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Mon, 10 Jul 2023 22:48:25 +0530 Subject: [PATCH 1/3] Update dependabot config to group `@wordpress/*` package updates --- .github/dependabot.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index b9186d2c358..8f8b8b84a74 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -17,13 +17,14 @@ updates: time: "17:00" timezone: America/Los_Angeles open-pull-requests-limit: 10 + groups: + wordpress-packages: + patterns: + - "@wordpress/*" ignore: - # Cannot upgrade until @wordpress/element supports react v17. + # Need to be updated based on `@wordpress/element` react peer dependency version. - dependency-name: react - versions: - - ">= 17" - # Updates are handled via the `gutenberg-packages-update` GHA workflow. - - dependency-name: "@wordpress/*" + - dependency-name: react-dom # Config for GitHub Actions. - package-ecosystem: github-actions From d2a02c0b819858d9d877077059c2ee23bf8aab56 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Mon, 10 Jul 2023 22:49:32 +0530 Subject: [PATCH 2/3] Remove `Gutenberg packages update` workflow - Removed in favor of dependabot updates grouping. --- .../workflows/gutenberg-packages-update.yml | 188 ------------------ 1 file changed, 188 deletions(-) delete mode 100644 .github/workflows/gutenberg-packages-update.yml diff --git a/.github/workflows/gutenberg-packages-update.yml b/.github/workflows/gutenberg-packages-update.yml deleted file mode 100644 index 03d8880c11c..00000000000 --- a/.github/workflows/gutenberg-packages-update.yml +++ /dev/null @@ -1,188 +0,0 @@ -name: Gutenberg packages update - -on: - # Allow for the workflow to be manually run if needed. - workflow_dispatch: - schedule: - # Once a day (https://crontab.guru/once-a-day) - - cron: '0 0 * * *' - -permissions: - pull-requests: write - contents: write - -# Cancel previous workflow run groups that have not completed. -concurrency: - # Group workflow runs by workflow name, along with the head branch ref of the pull request - # or otherwise the branch or tag ref. - group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.ref }} - cancel-in-progress: true - -jobs: - check-gutenberg-release: - name: Check for a new Gutenberg release - runs-on: ubuntu-latest - outputs: - latest-version: ${{ steps.latest-release.outputs.version }} - should-update: ${{ steps.release-status.outputs.outdated }} - steps: - - name: Get latest release version - id: latest-release - run: echo "version=$(gh api -X GET repos/wordpress/gutenberg/releases/latest --jq '.name')" >> $GITHUB_OUTPUT - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Get release version from last PR - id: last-release - run: | - PR_TITLE=$(gh api -X GET search/issues -f q='${{ env.QUERY }}' -f sort='created' -f order='desc' --jq '.items.[0].title') - LAST_VERSION=$(sed -r 's/.+ v(.+) .+/\1/' <<< "$PR_TITLE") - if ! egrep -q '^[0-9][0-9]*(\.[0-9][0-9]*)*$' <<< "$LAST_VERSION"; then - LAST_VERSION='0.0.0' - fi - echo "version=$(echo "$LAST_VERSION")" >> $GITHUB_OUTPUT - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - QUERY: 'repo:ampproject/amp-wp is:pr author:app/github-actions is:merged in:title Update Gutenberg packages after' - - - name: Determine if package updates are needed - id: release-status - run: | - echo "Last version: $LAST_VER" - echo "Latest version: $LATEST_VER" - echo "outdated=$(php -r 'echo json_encode(version_compare($argv[1], $argv[2], ">"));' "$LATEST_VER" "$LAST_VER")" >> $GITHUB_OUTPUT - env: - LAST_VER: ${{ steps.last-release.outputs.version }} - LATEST_VER: ${{ steps.latest-release.outputs.version }} - - close-latest-pr: - name: Close latest open PR if one exists - # Run job if there is a new Gutenberg release. - if: needs.check-gutenberg-release.outputs.should-update == 'true' - runs-on: ubuntu-latest - needs: check-gutenberg-release - steps: - - name: Get latest open PR - id: latest-pr - run: | - PR_NUM=$(gh api -X GET search/issues -f q='${{ env.QUERY }}' -f sort='created' -f order='desc' --jq '.items.[0].number') - echo "num=$(echo $PR_NUM)" >> $GITHUB_OUTPUT - echo "Latest PR number: ${PR_NUM}" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - QUERY: 'repo:ampproject/amp-wp is:pr author:app/github-actions is:open in:title Update Gutenberg packages after' - - # Needed to later close PR. - - name: Checkout repo - if: steps.latest-pr.num != '' - uses: actions/checkout@v3 - - - name: Close latest open PR - if: steps.latest-pr.num != '' - run: gh pr close ${{ env.PR_NUM }} --delete-branch - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PR_NUM: ${{ steps.latest-pr.num }} - - update-packages: - name: Update Gutenberg npm dependencies - # Run job if there is a new Gutenberg release. - if: needs.check-gutenberg-release.outputs.should-update == 'true' - runs-on: ubuntu-latest - needs: check-gutenberg-release - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - # Fetch history for all branches and tags to allow for successful merge of base branch if needed. - fetch-depth: 0 - - - name: Determine branch name - id: branches - run: | - echo "base=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_OUTPUT - echo "head=$(echo "update/gutenberg-v$VERSION-packages")" >> $GITHUB_OUTPUT - env: - VERSION: ${{ needs.check-gutenberg-release.outputs.latest-version }} - - - name: Setup Node - uses: actions/setup-node@v3.6.0 - with: - node-version-file: '.nvmrc' - cache: npm - - - name: Configure git user - run: | - git config user.name ${{ secrets.GIT_USER }} - git config user.email ${{ secrets.GIT_USER_EMAIL }} - - - name: Check if remote branch exists - id: remote-branch - run: echo "exists=$([[ -z $(git ls-remote --heads origin "$HEAD_BRANCH" ) ]] && echo "0" || echo "1")" >> $GITHUB_OUTPUT - env: - HEAD_BRANCH: ${{ steps.branches.outputs.head }} - - - name: Create branch to base pull request on - if: steps.remote-branch.outputs.exists == 0 - run: git checkout -b "$HEAD_BRANCH" - env: - HEAD_BRANCH: ${{ steps.branches.outputs.head }} - - - name: Fetch existing branch to add commits to - if: steps.remote-branch.outputs.exists == 1 - run: | - git checkout "$HEAD_BRANCH" - git merge --no-edit "$BASE_BRANCH" - env: - BASE_BRANCH: ${{ steps.branches.outputs.base }} - HEAD_BRANCH: ${{ steps.branches.outputs.head }} - - - name: Install Node dependencies - run: npm ci - env: - CI: true - - - name: Check package updates - id: packages - run: | - # Get list of latest package versions. - PACKAGES=$(npm outdated --parseable | cut -d':' -f 4 | grep @wordpress | paste -s -d' ' || echo 0) - echo "list=$(echo "$PACKAGES")" >> $GITHUB_OUTPUT - - - name: Update packages - if: steps.packages.outputs.list != 0 - run: npm i $(echo "$PACKAGES") - env: - PACKAGES: ${{ steps.packages.outputs.list }} - - - name: Commit and push changes - if: steps.packages.outputs.list != 0 - run: | - git add --all . - git commit -m "Update Gutenberg package dependencies" - git push origin "$HEAD_BRANCH" - env: - HEAD_BRANCH: ${{ steps.branches.outputs.head }} - - - name: Create pull request - if: steps.packages.outputs.list != 0 && steps.remote-branch.outputs.exists == 0 - run: | - NPM_URL="https://www.npmjs.com/package" - BODY="**Following packages were updated:**" - for PACKAGE in $PACKAGES; do - PACKAGE_SLUG=$(echo $PACKAGE | sed 's/@/\/v\//2') - BODY="$BODY - - - [$PACKAGE]($NPM_URL/$PACKAGE_SLUG)" - done - - echo ${BODY//$'\n'/'%0A'} - - PR_URL=$(gh pr create --base "$BASE_BRANCH" --title "Update Gutenberg packages after v$VERSION release" --body "$BODY" --label dependencies | grep https://) - gh pr merge --auto --merge "$PR_URL" - env: - VERSION: ${{ needs.check-gutenberg-release.outputs.latest-version }} - GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} - BASE_BRANCH: ${{ steps.branches.outputs.base }} - HEAD_BRANCH: ${{ steps.branches.outputs.head }} - PACKAGES: ${{ steps.packages.outputs.list }} From 583d62434c3c525307d5cdb0bd9d7970dde3e3c7 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Mon, 10 Jul 2023 22:59:41 +0530 Subject: [PATCH 3/3] Update `normalize-composer` job to be more robust --- .github/workflows/build-test-measure.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/build-test-measure.yml b/.github/workflows/build-test-measure.yml index b3c8cd69068..9cbab0395c3 100644 --- a/.github/workflows/build-test-measure.yml +++ b/.github/workflows/build-test-measure.yml @@ -176,6 +176,19 @@ jobs: - name: Get composer-normalize.phar run: | wget https://github.com/ergebnis/composer-normalize/releases/latest/download/composer-normalize.phar + + # Check if phar is actually downloaded. + if [ ! -f composer-normalize.phar ]; then + sleep 5 + wget https://github.com/ergebnis/composer-normalize/releases/latest/download/composer-normalize.phar + fi + + # If not downloaded, exit with error this time. + if [ ! -f composer-normalize.phar ]; then + echo "::error::Failed to download composer-normalize.phar" + exit 1 + fi + chmod +x composer-normalize.phar - name: Validate composer.json