Skip to content

Commit ea5dad5

Browse files
kouamoeba
andauthored
GH-47075: [Release][Dev] Use GH_TOKEN as GitHub token environment variable (#47181)
### Rationale for this change We have many environment variables for GitHub token: `GH_TOKEN`, `ARROW_GITHUB_API_TOKEN` and `CROSSBOW_GITHUB_TOKEN` It's difficult to maintain. For example, we may forget to define one of them. ### What changes are included in this PR? Use `GH_TOKEN` as unified environment variable for GitHub token. We can still use `ARROW_GITHUB_API_TOKEN` and `CROSSBOW_GITHUB_TOKEN` for backward compatibility but `GH_TOKEN` is recommended. ### Are these changes tested? Yes. ### Are there any user-facing changes? No. * GitHub Issue: #47075 Lead-authored-by: Sutou Kouhei <kou@clear-code.com> Co-authored-by: Sutou Kouhei <kou@cozmixng.org> Co-authored-by: Bryce Mecum <petridish@gmail.com> Signed-off-by: Sutou Kouhei <kou@clear-code.com>
1 parent c3be5fc commit ea5dad5

26 files changed

+94
-81
lines changed

.github/workflows/comment_bot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
run: pip install -e arrow/dev/archery[bot]
5050
- name: Handle GitHub comment event
5151
env:
52-
ARROW_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5353
CROSSBOW_GITHUB_TOKEN: ${{ secrets.CROSSBOW_GITHUB_TOKEN }}
5454
run: |
5555
archery --debug trigger-bot \

.github/workflows/dev.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,9 @@ jobs:
107107
gem install test-unit
108108
pip install "cython>=3" setuptools pytest requests setuptools-scm
109109
- name: Run Release Test
110-
env:
111-
ARROW_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
112110
shell: bash
113111
run: |
112+
echo "GH_TOKEN=${{ secrets.GITHUB_TOKEN }}" > dev/release/.env
114113
ci/scripts/release_test.sh $(pwd)
115114
- name: Run Merge Script Test
116115
shell: bash

.github/workflows/pr_bot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ jobs:
8989
run: pip install -e arrow/dev/archery[bot]
9090
- name: Handle PR workflow event
9191
env:
92-
ARROW_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
92+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9393
run: |
9494
if [ "${GITHUB_EVENT_NAME}" = "workflow_run" ]; then
9595
# workflow_run is executed on PR review. Update to original event.

dev/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ for configuring your tokens: environment variables or a configuration file.
5656
#### Pass tokens via Environment Variables
5757

5858
The merge script uses the GitHub REST API. You must set a
59-
`ARROW_GITHUB_API_TOKEN` environment variable to use a
59+
`GH_TOKEN` environment variable to use a
6060
[Personal Access Token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token).
6161
You need to add `workflow` scope to the Personal Access Token.
6262

dev/archery/archery/bot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ def _clone_arrow_and_crossbow(dest, crossbow_repo, arrow_repo_url, pr_number):
359359
git.clone(crossbow_url, str(queue_path))
360360

361361
# 3. initialize crossbow objects
362-
github_token = os.environ['CROSSBOW_GITHUB_TOKEN']
362+
github_token = os.environ.get('CROSSBOW_GITHUB_TOKEN', os.environ['GH_TOKEN'])
363363
arrow = Repo(arrow_path)
364364
queue = Queue(queue_path, github_token=github_token, require_https=True)
365365

dev/archery/archery/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ def integration(with_all=False, random_seed=12345, **args):
815815

816816

817817
@archery.command()
818-
@click.option('--arrow-token', envvar='ARROW_GITHUB_TOKEN',
818+
@click.option('--arrow-token', envvar=['GH_TOKEN', 'ARROW_GITHUB_TOKEN'],
819819
help='OAuth token for responding comment in the arrow repo')
820820
@click.option('--committers-file', '-c', type=click.File('r', encoding='utf8'))
821821
@click.option('--event-name', '-n', required=True)

dev/archery/archery/crossbow/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
@click.group()
3737
@click.option('--github-token', '-t', default=None,
38-
envvar="CROSSBOW_GITHUB_TOKEN",
38+
envvar=['CROSSBOW_GITHUB_TOKEN', 'GH_TOKEN'],
3939
help='OAuth token for GitHub authentication')
4040
@click.option('--arrow-path', '-a',
4141
type=click.Path(), default=_default_arrow_path,

dev/archery/archery/crossbow/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def push(self, refs=None, github_token=None):
291291
if github_token is None:
292292
raise RuntimeError(
293293
'Could not determine GitHub token. Please set the '
294-
'CROSSBOW_GITHUB_TOKEN environment variable to a '
294+
'CROSSBOW_GITHUB_TOKEN or GH_TOKEN environment variable to a '
295295
'valid GitHub access token or pass one to --github-token.'
296296
)
297297
callbacks = GitRemoteCallbacks(github_token)

dev/archery/archery/release/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
callback=validate_arrow_sources,
2929
help="Specify Arrow source directory.")
3030
@click.option('--github-token', '-t', default=None,
31-
envvar="CROSSBOW_GITHUB_TOKEN",
31+
envvar=['GH_TOKEN', 'CROSSBOW_GITHUB_TOKEN'],
3232
help='OAuth token for GitHub authentication')
3333
@click.pass_obj
3434
def release(obj, src, github_token):

dev/merge_arrow_pr.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
# variables.
3131
#
3232
# Configuration environment variables:
33-
# - ARROW_GITHUB_API_TOKEN: a GitHub API token to use for API requests
33+
# - GH_TOKEN: a GitHub API token to use for API requests
34+
# - ARROW_GITHUB_API_TOKEN: Same as GH_TOKEN. For backward compatibility.
3435
# - ARROW_GITHUB_ORG: the GitHub organisation ('apache' by default)
3536
# - DEBUG: use for testing to avoid pushing to apache (0 by default)
3637

@@ -254,10 +255,16 @@ def __init__(self, project_name, cmd):
254255
config = load_configuration()
255256
if "github" in config.sections():
256257
token = config["github"]["api_token"]
258+
if not token:
259+
token = os.environ.get('GH_TOKEN')
257260
if not token:
258261
token = os.environ.get('ARROW_GITHUB_API_TOKEN')
262+
if token:
263+
print('ARROW_GITHUB_API_TOKEN environment variable is '
264+
'deprecated. Use GH_TOKEN environment variable instead.')
259265
if not token:
260-
token = cmd.prompt('Env ARROW_GITHUB_API_TOKEN not set, '
266+
token = cmd.prompt('Env GH_TOKEN nor '
267+
'ARROW_GITHUB_API_TOKEN not set, '
261268
'please enter your GitHub API token '
262269
'(GitHub personal access token):')
263270
headers = {

0 commit comments

Comments
 (0)