mirror of
https://github.com/github/codeql-action.git
synced 2026-08-05 04:57:19 -05:00
Update update-release-branch.py to take token from stdin
This commit is contained in:
@@ -16,12 +16,23 @@ No user facing changes.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# NB: This exact commit message is used to find commits for reverting during backports.
|
# 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'
|
BACKPORT_COMMIT_MESSAGE = 'Update version and changelog for v'
|
||||||
|
|
||||||
# Name of the remote
|
# Name of the remote
|
||||||
ORIGIN = 'origin'
|
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.
|
# Runs git with the given args and returns the stdout.
|
||||||
# Raises an error if git does not exit successfully (unless passed
|
# Raises an error if git does not exit successfully (unless passed
|
||||||
# allow_non_zero_exit_code=True).
|
# allow_non_zero_exit_code=True).
|
||||||
@@ -270,12 +281,6 @@ def update_changelog(version):
|
|||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser('update-release-branch.py')
|
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(
|
parser.add_argument(
|
||||||
'--repository-nwo',
|
'--repository-nwo',
|
||||||
type=str,
|
type=str,
|
||||||
@@ -313,7 +318,7 @@ def main():
|
|||||||
target_branch = args.target_branch
|
target_branch = args.target_branch
|
||||||
is_primary_release = args.is_primary_release
|
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
|
# 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')
|
target_branch_major_version = target_branch.strip('releases/v')
|
||||||
|
|||||||
@@ -64,11 +64,12 @@ jobs:
|
|||||||
|
|
||||||
- name: Update current release branch
|
- name: Update current release branch
|
||||||
if: github.event_name == 'workflow_dispatch'
|
if: github.event_name == 'workflow_dispatch'
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
echo SOURCE_BRANCH=${REF_NAME}
|
echo SOURCE_BRANCH=${REF_NAME}
|
||||||
echo TARGET_BRANCH=releases/${MAJOR_VERSION}
|
echo TARGET_BRANCH=releases/${MAJOR_VERSION}
|
||||||
python .github/update-release-branch.py \
|
python .github/update-release-branch.py \
|
||||||
--github-token ${{ secrets.GITHUB_TOKEN }} \
|
|
||||||
--repository-nwo ${{ github.repository }} \
|
--repository-nwo ${{ github.repository }} \
|
||||||
--source-branch '${{ env.REF_NAME }}' \
|
--source-branch '${{ env.REF_NAME }}' \
|
||||||
--target-branch 'releases/${{ env.MAJOR_VERSION }}' \
|
--target-branch 'releases/${{ env.MAJOR_VERSION }}' \
|
||||||
@@ -107,11 +108,12 @@ jobs:
|
|||||||
- uses: ./.github/actions/release-initialise
|
- uses: ./.github/actions/release-initialise
|
||||||
|
|
||||||
- name: Update older release branch
|
- name: Update older release branch
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
echo SOURCE_BRANCH=${SOURCE_BRANCH}
|
echo SOURCE_BRANCH=${SOURCE_BRANCH}
|
||||||
echo TARGET_BRANCH=${TARGET_BRANCH}
|
echo TARGET_BRANCH=${TARGET_BRANCH}
|
||||||
python .github/update-release-branch.py \
|
python .github/update-release-branch.py \
|
||||||
--github-token ${{ secrets.GITHUB_TOKEN }} \
|
|
||||||
--repository-nwo ${{ github.repository }} \
|
--repository-nwo ${{ github.repository }} \
|
||||||
--source-branch ${SOURCE_BRANCH} \
|
--source-branch ${SOURCE_BRANCH} \
|
||||||
--target-branch ${TARGET_BRANCH} \
|
--target-branch ${TARGET_BRANCH} \
|
||||||
|
|||||||
Reference in New Issue
Block a user