From 93c8a9ed99901fd4a4a928c2e642ea0433a266f6 Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Fri, 15 May 2026 14:48:26 +0100 Subject: [PATCH] Update `update-release-branch.py` to take token from stdin --- .github/update-release-branch.py | 21 +++++++++++++-------- .github/workflows/update-release-branch.yml | 6 ++++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/.github/update-release-branch.py b/.github/update-release-branch.py index 90e059259..0c749e7b2 100644 --- a/.github/update-release-branch.py +++ b/.github/update-release-branch.py @@ -16,12 +16,23 @@ No user facing changes. """ # NB: This exact commit message is used to find commits for reverting during backports. -# Changing it requires a transition period where both old and new versions are supported. +# Changing it requires a transition period where both old and new versions are supported. BACKPORT_COMMIT_MESSAGE = 'Update version and changelog for v' # Name of the remote ORIGIN = 'origin' +# Environment variables to check for a GitHub API token. +TOKEN_ENVIRONMENT_VARIABLES = ('GH_TOKEN', 'GITHUB_TOKEN') + +# Gets a GitHub API token from one of the supported environment variables. +def get_github_token(): + for variable_name in TOKEN_ENVIRONMENT_VARIABLES: + token = os.environ.get(variable_name, '').strip() + if token: + return token + raise Exception('Missing GitHub token. Set GITHUB_TOKEN or GH_TOKEN.') + # Runs git with the given args and returns the stdout. # Raises an error if git does not exit successfully (unless passed # allow_non_zero_exit_code=True). @@ -270,12 +281,6 @@ def update_changelog(version): def main(): parser = argparse.ArgumentParser('update-release-branch.py') - parser.add_argument( - '--github-token', - type=str, - required=True, - help='GitHub token, typically from GitHub Actions.' - ) parser.add_argument( '--repository-nwo', type=str, @@ -313,7 +318,7 @@ def main(): target_branch = args.target_branch is_primary_release = args.is_primary_release - repo = Github(args.github_token).get_repo(args.repository_nwo) + repo = Github(get_github_token()).get_repo(args.repository_nwo) # the target branch will be of the form releases/vN, where N is the major version number target_branch_major_version = target_branch.strip('releases/v') diff --git a/.github/workflows/update-release-branch.yml b/.github/workflows/update-release-branch.yml index 147689ace..40d25e216 100644 --- a/.github/workflows/update-release-branch.yml +++ b/.github/workflows/update-release-branch.yml @@ -64,11 +64,12 @@ jobs: - name: Update current release branch if: github.event_name == 'workflow_dispatch' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | echo SOURCE_BRANCH=${REF_NAME} echo TARGET_BRANCH=releases/${MAJOR_VERSION} python .github/update-release-branch.py \ - --github-token ${{ secrets.GITHUB_TOKEN }} \ --repository-nwo ${{ github.repository }} \ --source-branch '${{ env.REF_NAME }}' \ --target-branch 'releases/${{ env.MAJOR_VERSION }}' \ @@ -107,11 +108,12 @@ jobs: - uses: ./.github/actions/release-initialise - name: Update older release branch + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | echo SOURCE_BRANCH=${SOURCE_BRANCH} echo TARGET_BRANCH=${TARGET_BRANCH} python .github/update-release-branch.py \ - --github-token ${{ secrets.GITHUB_TOKEN }} \ --repository-nwo ${{ github.repository }} \ --source-branch ${SOURCE_BRANCH} \ --target-branch ${TARGET_BRANCH} \