Skip to content

Commit 7cf0ed5

Browse files
authored
Merge pull request #1060 from github/aeisenberg/required-checks-script
Create update-required-checks script
2 parents dd56e95 + 827fd55 commit 7cf0ed5

File tree

2 files changed

+35
-45
lines changed

2 files changed

+35
-45
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
# Update the required checks based on the current branch.
3+
# Typically, this will be main.
4+
5+
if [ -z "$GITHUB_TOKEN" ]; then
6+
echo "Failed: No GitHub token found. This script requires admin access to `github/codeql-action`."
7+
exit 1
8+
fi
9+
10+
if [ "$#" -eq 1 ]; then
11+
# If we were passed an argument, pass it as a query to fzf
12+
GITHUB_SHA="$@"
13+
elif [ "$#" -gt 1 ]; then
14+
echo "Usage: $0 [SHA]"
15+
echo "Update the required checks based on the SHA, or main."
16+
elif [ -z "$GITHUB_SHA" ]; then
17+
# If we don't have a SHA, use main
18+
GITHUB_SHA="$(git rev-parse main)"
19+
fi
20+
21+
echo "Getting checks for $GITHUB_SHA"
22+
23+
# Ignore any checks with "https://", CodeQL, LGTM, and Update checks.
24+
CHECKS="$(gh api repos/github/codeql-action/commits/${GITHUB_SHA}/check-runs --paginate | jq --slurp --compact-output --raw-output '[.[].check_runs | .[].name | select(contains("https://") or . == "CodeQL" or . == "LGTM.com" or contains("Update") | not)] | sort')"
25+
26+
echo "$CHECKS" | jq
27+
28+
echo "{\"contexts\": ${CHECKS}}" > checks.json
29+
30+
for BRANCH in main releases/v2 releases/v1; do
31+
echo "Updating $BRANCH"
32+
gh api --silent -X "PATCH" "repos/github/codeql-action/branches/$BRANCH/protection/required_status_checks" --input checks.json
33+
done
34+
35+
rm checks.json

.github/workflows/update-required-checks.yml

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)