Skip to content

Commit 6a2acd1

Browse files
committed
Update update-release-branch.py to take token from stdin
1 parent ddf64ea commit 6a2acd1

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

.github/update-release-branch.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,23 @@
1616
"""
1717

1818
# NB: This exact commit message is used to find commits for reverting during backports.
19-
# Changing it requires a transition period where both old and new versions are supported.
19+
# Changing it requires a transition period where both old and new versions are supported.
2020
BACKPORT_COMMIT_MESSAGE = 'Update version and changelog for v'
2121

2222
# Name of the remote
2323
ORIGIN = 'origin'
2424

25+
# Environment variables to check for a GitHub API token.
26+
TOKEN_ENVIRONMENT_VARIABLES = ('GH_TOKEN', 'GITHUB_TOKEN')
27+
28+
# Gets a GitHub API token from one of the supported environment variables.
29+
def get_github_token():
30+
for variable_name in TOKEN_ENVIRONMENT_VARIABLES:
31+
token = os.environ.get(variable_name, '').strip()
32+
if token:
33+
return token
34+
raise Exception('Missing GitHub token. Set GITHUB_TOKEN or GH_TOKEN.')
35+
2536
# Runs git with the given args and returns the stdout.
2637
# Raises an error if git does not exit successfully (unless passed
2738
# allow_non_zero_exit_code=True).
@@ -270,12 +281,6 @@ def update_changelog(version):
270281
def main():
271282
parser = argparse.ArgumentParser('update-release-branch.py')
272283

273-
parser.add_argument(
274-
'--github-token',
275-
type=str,
276-
required=True,
277-
help='GitHub token, typically from GitHub Actions.'
278-
)
279284
parser.add_argument(
280285
'--repository-nwo',
281286
type=str,
@@ -313,7 +318,7 @@ def main():
313318
target_branch = args.target_branch
314319
is_primary_release = args.is_primary_release
315320

316-
repo = Github(args.github_token).get_repo(args.repository_nwo)
321+
repo = Github(get_github_token()).get_repo(args.repository_nwo)
317322

318323
# the target branch will be of the form releases/vN, where N is the major version number
319324
target_branch_major_version = target_branch.strip('releases/v')

.github/workflows/update-release-branch.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,12 @@ jobs:
6464
6565
- name: Update current release branch
6666
if: github.event_name == 'workflow_dispatch'
67+
env:
68+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6769
run: |
6870
echo SOURCE_BRANCH=${REF_NAME}
6971
echo TARGET_BRANCH=releases/${MAJOR_VERSION}
7072
python .github/update-release-branch.py \
71-
--github-token ${{ secrets.GITHUB_TOKEN }} \
7273
--repository-nwo ${{ github.repository }} \
7374
--source-branch '${{ env.REF_NAME }}' \
7475
--target-branch 'releases/${{ env.MAJOR_VERSION }}' \
@@ -107,11 +108,12 @@ jobs:
107108
- uses: ./.github/actions/release-initialise
108109

109110
- name: Update older release branch
111+
env:
112+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
110113
run: |
111114
echo SOURCE_BRANCH=${SOURCE_BRANCH}
112115
echo TARGET_BRANCH=${TARGET_BRANCH}
113116
python .github/update-release-branch.py \
114-
--github-token ${{ secrets.GITHUB_TOKEN }} \
115117
--repository-nwo ${{ github.repository }} \
116118
--source-branch ${SOURCE_BRANCH} \
117119
--target-branch ${TARGET_BRANCH} \

0 commit comments

Comments
 (0)