Skip to content

Commit 3ff9cef

Browse files
authored
chore(scripts): auto authenticate gh CLI in scripts on dogfood (#13107)
* chore: auto authenticate gh CLI in scripts * fix shellcheck issues
1 parent 53f7e9e commit 3ff9cef

File tree

6 files changed

+34
-1
lines changed

6 files changed

+34
-1
lines changed

scripts/deploy-pr.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
# [#pr-deployments](https://codercom.slack.com/archives/C05DNE982E8) Slack channel
55

66
set -euo pipefail
7+
# shellcheck source=scripts/lib.sh
8+
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
9+
cdroot
710

811
# default settings
912
dryRun=false
@@ -64,6 +67,9 @@ if $confirm; then
6467
fi
6568
fi
6669

70+
# Authenticate gh CLI
71+
gh_auth
72+
6773
# get branch name and pr number
6874
branchName=$(gh pr view --json headRefName | jq -r .headRefName)
6975
prNumber=$(gh pr view --json number | jq -r .number)

scripts/lib.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,22 @@ requiredenvs() {
130130
fi
131131
}
132132

133+
gh_auth() {
134+
local fail=0
135+
if [[ "${CODER:-}" == "true" ]]; then
136+
if ! output=$(coder external-auth access-token github 2>&1); then
137+
log "ERROR: Could not authenticate with GitHub."
138+
log "$output"
139+
fail=1
140+
else
141+
GITHUB_TOKEN=$(coder external-auth access-token github)
142+
export GITHUB_TOKEN
143+
fi
144+
else
145+
log "Please authenticate gh CLI by running 'gh auth login'"
146+
fi
147+
}
148+
133149
# maybedryrun prints the given program and flags, and then, if the first
134150
# argument is 0, executes it. The reason the first argument should be 0 is that
135151
# it is expected that you have a dry_run variable in your script that is set to

scripts/release.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ done
113113
# Check dependencies.
114114
dependencies gh jq sort
115115

116+
# Authenticate gh CLI
117+
gh_auth
118+
116119
if [[ -z $increment ]]; then
117120
# Default to patch versions.
118121
increment="patch"

scripts/release/check_commit_metadata.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ range="${from_ref}..${to_ref}"
3131
# Check dependencies.
3232
dependencies gh
3333

34+
# Authenticate gh CLI
35+
gh_auth
36+
3437
COMMIT_METADATA_BREAKING=0
3538
declare -a COMMIT_METADATA_COMMITS
3639
declare -A COMMIT_METADATA_TITLE COMMIT_METADATA_HUMAN_TITLE COMMIT_METADATA_CATEGORY COMMIT_METADATA_AUTHORS
@@ -145,7 +148,6 @@ main() {
145148
done
146149
} | sort -t- -n | head -n 1
147150
)
148-
149151
# Get the labels for all PRs merged since the last release, this is
150152
# inexact based on date, so a few PRs part of the previous release may
151153
# be included.

scripts/release/generate_release_notes.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ done
5757
# Check dependencies.
5858
dependencies gh sort
5959

60+
# Authticate gh CLI
61+
gh_auth
62+
6063
if [[ -z ${old_version} ]]; then
6164
error "No old version specified"
6265
fi

scripts/release/publish.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ done
7171
# Check dependencies
7272
dependencies gh
7373

74+
# Authenticate gh CLI
75+
gh_auth
76+
7477
# Remove the "v" prefix.
7578
version="${version#v}"
7679
if [[ "$version" == "" ]]; then

0 commit comments

Comments
 (0)