Skip to content
Permalink
Newer
Older
100755 57 lines (43 sloc) 2.04 KB
Ignoring revisions in .git-blame-ignore-revs.
1
#!/usr/bin/env bash
2
# Update the required checks based on the current branch.
3
# Typically, this will be main.
4
5
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
6
REPO_DIR="$(dirname "$SCRIPT_DIR")"
7
GRANDPARENT_DIR="$(dirname "$REPO_DIR")"
8
source "$GRANDPARENT_DIR/releases.ini"
9
10
if ! gh auth status 2>/dev/null; then
11
gh auth status
July 12, 2022 17:52
12
echo "Failed: Not authorized. This script requires admin access to github/codeql-action through the gh CLI."
13
exit 1
14
fi
15
16
if [ "$#" -eq 1 ]; then
July 12, 2022 17:31
17
# If we were passed an argument, use that as the SHA
18
GITHUB_SHA="$1"
19
elif [ "$#" -gt 1 ]; then
20
echo "Usage: $0 [SHA]"
21
echo "Update the required checks based on the SHA, or main."
July 12, 2022 17:31
22
exit 1
23
elif [ -z "$GITHUB_SHA" ]; then
24
# If we don't have a SHA, use main
25
GITHUB_SHA="$(git rev-parse main)"
26
fi
27
28
echo "Getting checks for $GITHUB_SHA"
29
30
# Ignore any checks with "https://", CodeQL, LGTM, and Update checks.
November 27, 2023 19:16
31
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 . == "Dependabot" or . == "check-expected-release-files" or contains("Update") or contains("update") or contains("test-setup-python-scripts") | not)] | unique | sort')"
32
33
echo "$CHECKS" | jq
34
35
echo "{\"contexts\": ${CHECKS}}" > checks.json
36
37
echo "Updating main"
38
gh api --silent -X "PATCH" "repos/github/codeql-action/branches/main/protection/required_status_checks" --input checks.json
39
40
# list all branchs on origin remote matching releases/v*
41
BRANCHES="$(git ls-remote --heads origin 'releases/v*' | sed 's?.*refs/heads/??' | sort -V)"
42
43
for BRANCH in $BRANCHES; do
44
45
# strip exact 'releases/v' prefix from $BRANCH using count of characters
46
VERSION="${BRANCH:10}"
47
48
if [ "$VERSION" -lt "$OLDEST_SUPPORTED_MAJOR_VERSION" ]; then
49
echo "Skipping $BRANCH"
50
continue
51
fi
52
53
echo "Updating $BRANCH"
54
gh api --silent -X "PATCH" "repos/github/codeql-action/branches/$BRANCH/protection/required_status_checks" --input checks.json
55
done
56
57
rm checks.json