103 lines
3.5 KiB
YAML
103 lines
3.5 KiB
YAML
name: Merged Blocking Pull Request Automation
|
|
|
|
on:
|
|
pull_request:
|
|
types:
|
|
- closed
|
|
|
|
jobs:
|
|
update-blocked-status:
|
|
name: Update Blocked Status
|
|
runs-on: ubuntu-latest
|
|
|
|
# a pr that was a `blocking:<id>` 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:" )
|
|
|
|
permissions:
|
|
issues: write
|
|
pull-requests: write
|
|
actions: write
|
|
|
|
steps:
|
|
- name: Gather Dependent PRs
|
|
id: gather_deps
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
PR_NUMBER: ${{ github.event.pull_request.number }}
|
|
run: |
|
|
owner=$(echo "${{ github.repository }}" | cut -d '/' -f 1)
|
|
repo=$(echo "${{ github.repository }}" | cut -d '/' -f 2)
|
|
query="
|
|
query(\$repo: String!, \$owner: String!, \$endCursor: String) {
|
|
repository(name: \$repo, owner: \$owner) {
|
|
pullRequests(first: 100, after: \$endCursor, states: [OPEN], labels: [\"blocked-by:${PR_NUMBER}\"]) {
|
|
nodes {
|
|
number
|
|
bodyText
|
|
merged
|
|
}
|
|
pageInfo {
|
|
hasNextPage
|
|
endCursor
|
|
}
|
|
}
|
|
}
|
|
}
|
|
"
|
|
blocked_prs=$(
|
|
gh api graphql \
|
|
-f repo="$repo" \
|
|
-f owner="$owner" \
|
|
-f query="$query" \
|
|
--paginate \
|
|
--slurp \
|
|
| jq -c --argjson pr "${{ github.event.pull_request.number }}" '
|
|
reduce ( .[].data.repository.pullRequests.nodes[] | select(
|
|
.bodyText |
|
|
scan("(?:blocked (?:by|on)|stacked on):? #([0-9]+)") |
|
|
map(tonumber) |
|
|
any(.[]; . == $pr)
|
|
)) as $i ([]; . + [$i])
|
|
'
|
|
)
|
|
echo "deps=$blocked_prs" >> "$GITHUB_OUTPUT"
|
|
echo "numdeps=$(jq -r '. | length' <<< "$blocked_prs")" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Trigger Blocked PR Workflows for Dependants
|
|
if: fromJSON(steps.gather_deps.outputs.numdeps) > 0
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
DEPS: ${{ steps.gather_deps.outputs.deps }}
|
|
run: |
|
|
while read -r pr ; do
|
|
gh api \
|
|
--method POST \
|
|
-H "Accept: application/vnd.github+json" \
|
|
-H "X-GitHub-Api-Version: 2022-11-28" \
|
|
"/repos/${{ github.repository }}/actions/workflows/blocked-prs.yml/dispatches" \
|
|
-f "ref=${{ github.ref_name }}" \
|
|
-f "inputs[pr_id]=$pr"
|
|
done < <(jq -c '.[].number' <<< "$DEPS")
|
|
|
|
label-cleanup:
|
|
# this pr is closed, no need for these anymore
|
|
name: "Cleanup Related blocking:<id> or blocked-by:<id> labels"
|
|
runs-on: ubuntu-latest
|
|
|
|
permissions:
|
|
issues: write
|
|
pull-requests: write
|
|
|
|
steps:
|
|
- name: Checkout Default Branch
|
|
uses: actions/checkout@v4
|
|
with:
|
|
ref: ${{ github.event.repository.default_branch }}
|
|
- name: Delete Related Labels
|
|
uses: ./.github/actions/delete-labels
|
|
with:
|
|
repository: ${{ github.repository }}
|
|
gh_token: ${{ secrets.GITHUB_TOKEN }}
|
|
labels: ${{ format('blocking:{0},blocked-by:{0}', github.event.pull_request.number ) }}
|