Skip to content
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

Fix GHA job that closes stale Gutenberg update PRs #6401

Merged
merged 2 commits into from
Jun 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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