update required checks script to handle release branches

This commit is contained in:
nickfyson 2023-12-20 17:19:16 +00:00
parent a110746c60
commit a42c9a2634
4 changed files with 33 additions and 5 deletions

View file

@ -1,12 +1,19 @@
import argparse import argparse
import json import json
import os import os
import subprocess import configparser
# Name of the remote # Name of the remote
ORIGIN = 'origin' ORIGIN = 'origin'
OLDEST_SUPPORTED_MAJOR_VERSION = 2 script_dir = os.path.dirname(os.path.realpath(__file__))
grandparent_dir = os.path.dirname(os.path.dirname(script_dir))
config = configparser.ConfigParser()
with open(os.path.join(grandparent_dir, 'releases.ini')) as stream:
config.read_string('[default]\n' + stream.read())
OLDEST_SUPPORTED_MAJOR_VERSION = config['default']['OLDEST_SUPPORTED_MAJOR_VERSION']
def main(): def main():

1
.github/releases.ini vendored Normal file
View file

@ -0,0 +1 @@
OLDEST_SUPPORTED_MAJOR_VERSION=2

View file

@ -2,6 +2,11 @@
# Update the required checks based on the current branch. # Update the required checks based on the current branch.
# Typically, this will be main. # Typically, this will be main.
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
REPO_DIR="$(dirname "$SCRIPT_DIR")"
GRANDPARENT_DIR="$(dirname "$REPO_DIR")"
source "$GRANDPARENT_DIR/releases.ini"
if ! gh auth status 2>/dev/null; then if ! gh auth status 2>/dev/null; then
gh auth status gh auth status
echo "Failed: Not authorized. This script requires admin access to github/codeql-action through the gh CLI." echo "Failed: Not authorized. This script requires admin access to github/codeql-action through the gh CLI."
@ -29,7 +34,22 @@ echo "$CHECKS" | jq
echo "{\"contexts\": ${CHECKS}}" > checks.json echo "{\"contexts\": ${CHECKS}}" > checks.json
for BRANCH in main releases/v2; do echo "Updating main"
gh api --silent -X "PATCH" "repos/github/codeql-action/branches/main/protection/required_status_checks" --input checks.json
# list all branchs on origin remote matching releases/v*
BRANCHES="$(git ls-remote --heads origin 'releases/v*' | sed 's?.*refs/heads/??' | sort -V)"
for BRANCH in $BRANCHES; do
# strip exact 'releases/v' prefix from $BRANCH using count of characters
VERSION="${BRANCH:10}"
if [ "$VERSION" -lt "$OLDEST_SUPPORTED_MAJOR_VERSION" ]; then
echo "Skipping $BRANCH"
continue
fi
echo "Updating $BRANCH" echo "Updating $BRANCH"
gh api --silent -X "PATCH" "repos/github/codeql-action/branches/$BRANCH/protection/required_status_checks" --input checks.json gh api --silent -X "PATCH" "repos/github/codeql-action/branches/$BRANCH/protection/required_status_checks" --input checks.json
done done

View file

@ -111,8 +111,8 @@ To deprecate an older version of the Action:
- Add a changelog note announcing the deprecation. - Add a changelog note announcing the deprecation.
- Implement an Actions warning for customers using the deprecated version. - Implement an Actions warning for customers using the deprecated version.
1. Wait for the deprecation period to pass. 1. Wait for the deprecation period to pass.
1. Upgrade the Actions warning for customers using the deprecated version to a non-fatal error, and mention that this version of the Action is no longer supported. 1. Upgrade the Actions warning for customers using the deprecated version to a non-fatal error, and mention that this version of the Action is no longer supported.
1. Make a PR to bump the `OLDEST_SUPPORTED_MAJOR_VERSION` in [release-branches.py](.github/actions/release-branches/release-branches.py). Once this PR is merged, the release process will no longer backport changes to the deprecated release version. 1. Make a PR to bump the `OLDEST_SUPPORTED_MAJOR_VERSION` in [releases.ini](.github/releases.ini). Once this PR is merged, the release process will no longer backport changes to the deprecated release version.
## Resources ## Resources