ci(blocked-pr): go back to single labels use gh cli actions directly insead of api where possible
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
This commit is contained in:
44
.github/workflows/blocked-prs.yml
vendored
44
.github/workflows/blocked-prs.yml
vendored
@@ -60,12 +60,11 @@ jobs:
|
||||
id: dispatch_event_setup
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
REPOSITORY: ${{ github.repository }}
|
||||
PR_NUMBER: ${{ inputs.pr_id }}
|
||||
run: |
|
||||
# setup env for the rest of the workflow
|
||||
OWNER=$(echo "$REPOSITORY" | cut -d '/' -f 1)
|
||||
REPO=$(echo "$REPOSITORY" | cut -d '/' -f 2)
|
||||
OWNER=$(dirname "${{ github.repository }}")
|
||||
REPO=$(basename "${{ github.repository }}")
|
||||
PR_JSON=$(
|
||||
gh api \
|
||||
-H "Accept: application/vnd.github.raw+json" \
|
||||
@@ -155,33 +154,38 @@ jobs:
|
||||
'
|
||||
done < <(jq -c '.blocking[]' <<< "$BLOCKING_PRS") | jq -c -s
|
||||
)
|
||||
blocked_by_labels=$(jq -c 'map( select( .merged | not ) | "blocked-by:" + (.number | tostring))' <<< "$blocked_pr_data" )
|
||||
echo "data=$blocked_pr_data" >> "$GITHUB_OUTPUT"
|
||||
echo "all_merged=$(jq -r 'all(.[].merged; .)' <<< "$blocked_pr_data")" >> "$GITHUB_OUTPUT"
|
||||
echo "blocked_by_labels=$blocked_by_labels" >> "$GITHUB_OUTPUT"
|
||||
echo "current_blocking=$(jq -c 'map( select( .merged | not ) | .number )' <<< "$blocked_pr_data" )" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Apply Blocked by Labels
|
||||
- name: Add 'blocked' Label is Missing
|
||||
id: label_blocked
|
||||
if: fromJSON(steps.pr_ids.outputs.prs).numBlocking > 0 && steps.blocking_data.outputs.blocked_by_labels != ''
|
||||
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
|
||||
uses: ./.github/actions/add-labels
|
||||
with:
|
||||
repository: ${{ github.repository }}
|
||||
gh_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
issues: ${{ env.PR_NUMBER }}
|
||||
labels: ${{ join( fromJSON(steps.blocking_data.outputs.blocked_by_labels), ',' ) }}
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
gh -R ${{ github.repository }} issue edit --add-label 'blocked' $PR_NUMBER
|
||||
|
||||
- name: Apply 'blocking:<id>' Label to Unmerged Dependencies
|
||||
- name: Remove 'blocked' Label if All Dependencies Are Merged
|
||||
id: unlabel_blocked
|
||||
if: fromJSON(steps.pr_ids.outputs.prs).numBlocking > 0 && fromJSON(steps.blocking_data.outputs.all_merged)
|
||||
continue-on-error: true
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
gh -R ${{ github.repository }} issue edit --remove-label 'blocked' $PR_NUMBER
|
||||
|
||||
- name: Apply 'blocking' Label to Unmerged Dependencies
|
||||
id: label_blocking
|
||||
if: fromJSON(steps.pr_ids.outputs.prs).numBlocking > 0
|
||||
continue-on-error: true
|
||||
uses: ./.github/actions/add-labels
|
||||
with:
|
||||
repository: ${{ github.repository }}
|
||||
gh_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
issues: ${{ join( fromJSON(steps.blocking_data.outputs.current_blocking) , ',' ) }}
|
||||
labels: ${{ format( 'blocking:{0}', env.PR_NUMBER ) }}
|
||||
env:
|
||||
BLOCKING_ISSUES: ${{ steps.blocking_data.outputs.current_blocking }}
|
||||
run: |
|
||||
while read -r pr ; do
|
||||
gh -R ${{ github.repository }} issue edit --add-label 'blocking' "$pr" || true
|
||||
done < <(jq -c '.[]' <<< "$BLOCKING_ISSUES")
|
||||
|
||||
- name: Apply Blocking PR Status Check
|
||||
id: blocked_check
|
||||
|
||||
45
.github/workflows/manual-add-label.yml
vendored
45
.github/workflows/manual-add-label.yml
vendored
@@ -1,45 +0,0 @@
|
||||
name: "Manual: Apply Labels in Bulk"
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
issues:
|
||||
description: a single or comma separated list of issue numbers
|
||||
required: true
|
||||
type: string
|
||||
labels:
|
||||
description: a single or comma separated list of labels to apply to all listed issues
|
||||
required: true
|
||||
type: string
|
||||
colors:
|
||||
description: |
|
||||
A single or comma separated list of colors to create the labels with if needed.
|
||||
the list order is the same as `labels`. Missing or blank values (e.g. `FFFFFF,,FFFFFF`) use the `default_color`
|
||||
type: string
|
||||
default-color:
|
||||
description: default color to create labels with
|
||||
default: "#D4C5F9"
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
apply-labels:
|
||||
name: Apply 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: Run Label Action
|
||||
uses: ./.github/actions/add-labels
|
||||
with:
|
||||
gh_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
issues: ${{ inputs.issues }}
|
||||
labels: ${{ inputs.labels }}
|
||||
colors: ${{ inputs.colors }}
|
||||
default-color: ${{ inputs.default-color }}
|
||||
30
.github/workflows/manual-delete-labels.yml
vendored
30
.github/workflows/manual-delete-labels.yml
vendored
@@ -1,30 +0,0 @@
|
||||
|
||||
name: "Manual: Delete labels in bulk"
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
labels:
|
||||
description: a single or comma separated list of labels to delete
|
||||
required: true
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
delete-labels:
|
||||
name: Delete 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: Run Label Action
|
||||
uses: ./.github/actions/delete-labels
|
||||
with:
|
||||
gh_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
labels: ${{ inputs.labels }}
|
||||
52
.github/workflows/merge-blocking-pr.yml
vendored
Normal file
52
.github/workflows/merge-blocking-pr.yml
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
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: |
|
||||
blocked_prs=$(
|
||||
gh -R ${{ github.repository }} pr list --label 'blocked' --json 'number,body' \
|
||||
| jq -c --argjson pr "${{ github.event.pull_request.number }}" '
|
||||
reduce ( .[] | select(
|
||||
.body |
|
||||
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 -R ${{ github.repository }} workflow run 'blocked-prs.yml' -r "${{ github.ref_name }}" -f pr_id="$pr"
|
||||
done < <(jq -c '.[].number' <<< "$DEPS")
|
||||
|
||||
102
.github/workflows/merge-blocking_pr.yml
vendored
102
.github/workflows/merge-blocking_pr.yml
vendored
@@ -1,102 +0,0 @@
|
||||
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 ) }}
|
||||
Reference in New Issue
Block a user