Skip to content

Commit

Permalink
Merge pull request #6401 from ampproject/fix/gutenberg-update-workflow
Browse files Browse the repository at this point in the history
Fix GHA job that closes stale Gutenberg update PRs
  • Loading branch information
westonruter authored Jun 22, 2021
2 parents 971c5b3 + e1640dd commit a958b43
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions .github/workflows/gutenberg-packages-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ jobs:
runs-on: ubuntu-latest
outputs:
latest-version: ${{ steps.latest-release.outputs.version }}
latest-pr-num: ${{ steps.last-release.outputs.pr-num }}
should-update: ${{ steps.release-status.outputs.outdated }}
steps:
- name: Get latest release version
Expand All @@ -25,15 +24,11 @@ jobs:
- name: Get release version from last PR
id: last-release
run: |
readarray -t RESULT < <(gh api -X GET search/issues -f q='${{ env.QUERY }}' -f sort='created' -f order='desc' --jq '.items.[0]|[.number, .title]|join("\n")')
PR_NUM=${RESULT[0]}
PR_TITLE=${RESULT[1]}
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 "::set-output name=pr-num::$(echo "$PR_NUM")"
echo "::set-output name=version::$(echo "$LAST_VERSION")"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -50,16 +45,32 @@ jobs:
LATEST_VER: ${{ steps.latest-release.outputs.version }}

close-latest-pr:
name: Close latest PR if one exists
if: needs.check-gutenberg-release.outputs.latest-pr-num != ''
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: Close latest PR
- 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 "::set-output name=num::$(echo $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@v2

- 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: ${{ needs.check-gutenberg-release.outputs.latest-pr-num }}
PR_NUM: ${{ steps.latest-pr.num }}

update-packages:
name: Update Gutenberg npm dependencies
Expand Down

0 comments on commit a958b43

Please sign in to comment.