From e28dd30d87cd9779fc589c51b1519090c3e33ff5 Mon Sep 17 00:00:00 2001 From: Rachel Powers <508861+Ryex@users.noreply.github.com> Date: Fri, 14 Mar 2025 19:26:27 -0700 Subject: [PATCH] ci(blocked_pr): merge env setup for dispatch and pull_request events Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com> --- .github/workflows/blocked-prs.yml | 60 +++++++++---------------- .github/workflows/merge-blocking-pr.yml | 2 +- 2 files changed, 23 insertions(+), 39 deletions(-) diff --git a/.github/workflows/blocked-prs.yml b/.github/workflows/blocked-prs.yml index 21e73660d..96a8cfc03 100644 --- a/.github/workflows/blocked-prs.yml +++ b/.github/workflows/blocked-prs.yml @@ -30,13 +30,30 @@ jobs: uses: actions/checkout@v4 with: ref: ${{ github.event.repository.default_branch }} - - name: Setup From Pull Request Event - if: github.event_name != 'workflow_dispatch' - id: pr_event_setup + + - name: Setup From Dispatch Event + if: github.event_name == 'workflow_dispatch' + id: dispatch_event_setup env: - PR_JSON: "${{ toJSON(github.event.pull_request) }}" + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PR_NUMBER: ${{ inputs.pr_id }} run: | # setup env for the rest of the workflow + OWNER=$(dirname "${{ github.repository }}") + REPO=$(basename "${{ github.repository }}") + PR_JSON=$( + gh api \ + -H "Accept: application/vnd.github.raw+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "/repos/$OWNER/$REPO/pulls/$PR_NUMBER" + ) + echo "PR_JSON=$PR_JSON" >> "$GITHUB_ENV" + + - name: Setup Environment + id: env_setup + run: | + # setup env for the rest of the workflow + PR_JSON=${PR_JSON:-'${{ toJSON(github.event.pull_request) }}'} { echo "REPO=$(jq -r '.base.repo.name' <<< "$PR_JSON")" echo "OWNER=$(jq -r '.base.repo.owner.login' <<< "$PR_JSON")" @@ -55,39 +72,6 @@ jobs: ' <<< "$PR_JSON")" } >> "$GITHUB_ENV" - - name: Setup From Dispatch Event - if: github.event_name == 'workflow_dispatch' - id: dispatch_event_setup - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PR_NUMBER: ${{ inputs.pr_id }} - run: | - # setup env for the rest of the workflow - OWNER=$(dirname "${{ github.repository }}") - REPO=$(basename "${{ github.repository }}") - PR_JSON=$( - gh api \ - -H "Accept: application/vnd.github.raw+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - "/repos/$OWNER/$REPO/pulls/$PR_NUMBER" - ) - { - echo "REPO=$(jq -r '.base.repo.name' <<< "$PR_JSON")" - echo "OWNER=$(jq -r '.base.repo.owner.login' <<< "$PR_JSON")" - echo "PR_NUMBER=$(jq -r '.number' <<< "$PR_JSON")" - echo "JOB_DATA=$(jq -c ' - { - "repo": .base.repo.name, - "owner": .base.repo.owner.login, - "repoUrl": .base.repo.html_url, - "prNumber": .number, - "prHeadSha": .head.sha, - "prHeadLabel": .head.label, - "prBody": .body, - "prLabels": (reduce .labels[].name as $l ([]; . + [$l])) - } - ' <<< "$PR_JSON")" - } >> "$GITHUB_ENV" - name: Find Blocked/Stacked PRs in body id: pr_ids @@ -160,7 +144,7 @@ jobs: - name: Add 'blocked' Label is Missing id: label_blocked - if: fromJSON(steps.pr_ids.outputs.prs).numBlocking > 0 && && !contains(fromJSON(env.JOB_DATA).prLabels, 'blocked') && !fromJSON(steps.blocking_data.outputs.all_merged) + if: (fromJSON(steps.pr_ids.outputs.prs).numBlocking > 0) && !contains(fromJSON(env.JOB_DATA).prLabels, 'blocked') && !fromJSON(steps.blocking_data.outputs.all_merged) continue-on-error: true env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/merge-blocking-pr.yml b/.github/workflows/merge-blocking-pr.yml index 6db3483d4..4ac85fa5f 100644 --- a/.github/workflows/merge-blocking-pr.yml +++ b/.github/workflows/merge-blocking-pr.yml @@ -12,7 +12,7 @@ jobs: # a pr that was a `blocking:` label was merged. # find the open pr's it was blocked by and trigger a refresh of their state - if: github.event.pull_request.merged == true && contains( join( github.event.pull_request.labels.*.name, ',' ), "blocking" ) + if: github.event.pull_request.merged == true && contains( join( github.event.pull_request.labels.*.name, ',' ), 'blocking' ) permissions: issues: write