ci(blocking-lables): cleanup lables with a pr closes
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
This commit is contained in:
2
.github/actions/add-labels/action.yml
vendored
2
.github/actions/add-labels/action.yml
vendored
@@ -19,7 +19,7 @@ inputs:
|
||||
the list order is the same as `labels`. Missing or blank values (e.g. `FFFFFF,,FFFFFF`) use the `default-color`
|
||||
default-color:
|
||||
description: default color to create labels with
|
||||
default: "#D4C5F9"
|
||||
default: "#ffffff"
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
|
||||
4
.github/actions/create-comment/action.yml
vendored
4
.github/actions/create-comment/action.yml
vendored
@@ -1,5 +1,5 @@
|
||||
name: Create Issue Comment
|
||||
description: Create or updste an issue comment
|
||||
description: Create or update an issue comment
|
||||
inputs:
|
||||
comment:
|
||||
description: Comment Text
|
||||
@@ -19,7 +19,7 @@ inputs:
|
||||
required: true
|
||||
repository:
|
||||
description: the OWNER/REPOSITORY to operate on
|
||||
required: true
|
||||
default: ${{ github.repository }}
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
|
||||
2
.github/actions/delete-labels/action.yml
vendored
2
.github/actions/delete-labels/action.yml
vendored
@@ -70,10 +70,12 @@ runs:
|
||||
'
|
||||
)
|
||||
echo "label_ids=$data" >> "$GITHUB_OUTPUT"
|
||||
echo "num_labels=$(jq -r 'length' <<< "$data")" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Delete Labels
|
||||
id: delete_labels
|
||||
shell: bash
|
||||
if: fromJSON( steps.collect_labels.outputs.num_labels ) > 0
|
||||
env:
|
||||
GH_TOKEN: ${{ inputs.gh_token }}
|
||||
LABELS: ${{ steps.collect_labels.outputs.label_ids }}
|
||||
|
||||
@@ -54,7 +54,6 @@ jobs:
|
||||
}
|
||||
' <<< "$PR_JSON")"
|
||||
} >> "$GITHUB_ENV"
|
||||
cat $GITHUB_ENV
|
||||
|
||||
- name: Setup From Dispatch Event
|
||||
if: github.event_name == 'workflow_dispatch'
|
||||
@@ -133,7 +132,7 @@ jobs:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
BLOCKING_PRS: ${{ steps.pr_ids.outputs.prs }}
|
||||
run: |
|
||||
BLOCKED_PR_DATA=$(
|
||||
blocked_pr_data=$(
|
||||
while read -r pr_data ; do
|
||||
gh api \
|
||||
-H "Accept: application/vnd.github+json" \
|
||||
@@ -156,56 +155,33 @@ jobs:
|
||||
'
|
||||
done < <(jq -c '.blocking[]' <<< "$BLOCKING_PRS") | jq -c -s
|
||||
)
|
||||
echo "data=$BLOCKED_PR_DATA" >> "$GITHUB_OUTPUT"
|
||||
echo "all_merged=$(jq -r 'all(.[].merged; .)' <<< "$BLOCKED_PR_DATA")" >> "$GITHUB_OUTPUT"
|
||||
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 Label if Missing
|
||||
- name: Apply Blocked by Labels
|
||||
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 && steps.blocking_data.outputs.blocked_by_labels != ''
|
||||
continue-on-error: true
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
gh api \
|
||||
--method POST \
|
||||
-H "Accept: application/vnd.github+json" \
|
||||
-H "X-GitHub-Api-Version: 2022-11-28" \
|
||||
"/repos/$OWNER/$REPO/issues/$PR_NUMBER/labels" \
|
||||
-f "labels[]=blocked"
|
||||
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), ',' ) }}
|
||||
|
||||
- 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 api \
|
||||
--method DELETE \
|
||||
-H "Accept: application/vnd.github+json" \
|
||||
-H "X-GitHub-Api-Version: 2022-11-28" \
|
||||
"/repos/$OWNER/$REPO/issues/$PR_NUMBER/labels/blocked"
|
||||
|
||||
- name: Apply 'blocking' Label to Dependencies if Missing
|
||||
- name: Apply 'blocking:<id>' Label to Unmerged Dependencies
|
||||
id: label_blocking
|
||||
if: fromJSON(steps.pr_ids.outputs.prs).numBlocking > 0
|
||||
continue-on-error: true
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
BLOCKING_DATA: ${{ steps.blocking_data.outputs.data }}
|
||||
run: |
|
||||
# label pr dependencies with 'blocking' if not already
|
||||
while read -r pr_data ; do
|
||||
if jq -e 'all(.labels[]; . != "blocking")' <<< "$pr_data" > /dev/null ; then
|
||||
pr=$(jq -r '.number' <<< "$pr_data")
|
||||
gh api \
|
||||
--method POST \
|
||||
-H "Accept: application/vnd.github+json" \
|
||||
-H "X-GitHub-Api-Version: 2022-11-28" \
|
||||
"/repos/$OWNER/$REPO/issues/$pr/labels" \
|
||||
-f "labels[]=blocking"
|
||||
fi
|
||||
done < <(jq -c '.[]' <<< "$BLOCKING_DATA")
|
||||
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 ) }}
|
||||
|
||||
- name: Apply Blocking PR Status Check
|
||||
id: blocked_check
|
||||
@@ -229,7 +205,7 @@ jobs:
|
||||
-f "state=$(jq -r 'if .merged then "success" else "failure" end' <<< "$pr_data")" \
|
||||
-f "target_url=$(jq -r '.basePrUrl' <<< "$pr_data" )" \
|
||||
-f "description=$DESC" \
|
||||
-f "context=continuous-integration/blocked-pr-check:$(jq '.number' <<< "$pr_data")"
|
||||
-f "context=ci/blocking-pr-check:$(jq '.number' <<< "$pr_data")"
|
||||
done < <(jq -c '.[]' <<< "$BLOCKING_DATA")
|
||||
|
||||
- name: Context Comment
|
||||
2
.github/workflows/manual-add-label.yml
vendored
2
.github/workflows/manual-add-label.yml
vendored
@@ -1,4 +1,4 @@
|
||||
name: Apply labels in bulk
|
||||
name: "Manual: Apply Labels in Bulk"
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
2
.github/workflows/manual-delete-labels.yml
vendored
2
.github/workflows/manual-delete-labels.yml
vendored
@@ -1,5 +1,5 @@
|
||||
|
||||
name: Delete labels in bulk
|
||||
name: "Manual: Delete labels in bulk"
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
@@ -6,11 +6,13 @@ on:
|
||||
- closed
|
||||
|
||||
jobs:
|
||||
update_blocked_status:
|
||||
update-blocked-status:
|
||||
name: Update Blocked Status
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
if: github.event.pull_request.merged == true
|
||||
# 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
|
||||
@@ -22,30 +24,32 @@ jobs:
|
||||
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($repo: String!, $owner: String!, $endCursor: String) {
|
||||
repository(name: $repo, owner: $owner) {
|
||||
pullRequests(first: 100, after: $endCursor, states: [OPEN], labels: ["blocked"]) {
|
||||
nodes {
|
||||
number
|
||||
bodyText
|
||||
merged
|
||||
}
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
endCursor
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
' \
|
||||
-f query="$query" \
|
||||
--paginate \
|
||||
--slurp \
|
||||
| jq -c --argjson pr "${{ github.event.pull_request.number }}" '
|
||||
@@ -60,7 +64,7 @@ jobs:
|
||||
echo "deps=$blocked_prs" >> "$GITHUB_OUTPUT"
|
||||
echo "numdeps=$(jq -r '. | length' <<< "$blocked_prs")" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Trigger Blocked PP Workflows for Dependants
|
||||
- name: Trigger Blocked PR Workflows for Dependants
|
||||
if: fromJSON(steps.gather_deps.outputs.numdeps) > 0
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -71,8 +75,28 @@ jobs:
|
||||
--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" \
|
||||
"/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