Skip to content

Commit

Permalink
Use old github token if new tokens are not available
Browse files Browse the repository at this point in the history
  • Loading branch information
trodge committed Mar 4, 2024
1 parent ae819d0 commit a3cf534
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 25 deletions.
11 changes: 10 additions & 1 deletion .ci/magician/cmd/check_cassettes.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

var ccEnvironmentVariables = [...]string{
"COMMIT_SHA",
"GITHUB_TOKEN_DOWNSTREAMS",
"GOCACHE",
"GOPATH",
"GOOGLE_BILLING_ACCOUNT",
Expand Down Expand Up @@ -56,6 +55,8 @@ var checkCassettesCmd = &cobra.Command{
env[ev] = val
}

env["GITHUB_TOKEN_DOWNSTREAMS"] = githubTokenOrFallback("GITHUB_TOKEN_DOWNSTREAMS")

rnr, err := exec.NewRunner()
if err != nil {
fmt.Println("Error creating Runner: ", err)
Expand All @@ -73,6 +74,14 @@ var checkCassettesCmd = &cobra.Command{
},
}

func githubTokenOrFallback(tokenName string) string {
val, ok := os.LookupEnv(tokenName)
if !ok {
return os.Getenv("GITHUB_TOKEN")
}
return val
}

func listCCEnvironmentVariables() string {
var result string
for i, ev := range ccEnvironmentVariables {
Expand Down
6 changes: 1 addition & 5 deletions .ci/magician/cmd/community_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ var communityApprovalCmd = &cobra.Command{
baseBranch := args[5]
fmt.Println("Base Branch: ", baseBranch)

githubToken, ok := os.LookupEnv("GITHUB_TOKEN_MAGIC_MODULES")
if !ok {
fmt.Println("Did not provide GITHUB_TOKEN_MAGIC_MODULES environment variable")
os.Exit(1)
}
githubToken := githubTokenOrFallback("GITHUB_TOKEN_MAGIC_MODULES")
gh := github.NewClient(githubToken)
cb := cloudbuild.NewClient()
execCommunityChecker(prNumber, commitSha, branchName, headRepoUrl, headBranch, baseBranch, gh, cb)
Expand Down
5 changes: 3 additions & 2 deletions .ci/magician/cmd/generate_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ var gcEnvironmentVariables = [...]string{
"BUILD_ID",
"BUILD_STEP",
"COMMIT_SHA",
"GITHUB_TOKEN_DOWNSTREAMS",
"GITHUB_TOKEN_MAGIC_MODULES",
"GOPATH",
"HOME",
"PATH",
Expand Down Expand Up @@ -71,6 +69,9 @@ var generateCommentCmd = &cobra.Command{
env[ev] = val
}

for _, tokenName := range []string{"GITHUB_TOKEN_DOWNSTREAMS", "GITHUB_TOKEN_MAGIC_MODULES"} {
env[tokenName] = githubTokenOrFallback(tokenName)
}
gh := github.NewClient(env["GITHUB_TOKEN_MAGIC_MODULES"])
rnr, err := exec.NewRunner()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions .ci/magician/cmd/generate_downstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var gdEnvironmentVariables = [...]string{
var gdTokenEnvironmentVariables = [...]string{
"GITHUB_TOKEN_CLASSIC",
"GITHUB_TOKEN_DOWNSTREAMS",
"GITHUB_TOKEN",
}

var generateDownstreamCmd = &cobra.Command{
Expand Down
6 changes: 1 addition & 5 deletions .ci/magician/cmd/membership_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ var membershipCheckerCmd = &cobra.Command{
baseBranch := args[5]
fmt.Println("Base Branch: ", baseBranch)

githubToken, ok := os.LookupEnv("GITHUB_TOKEN_MAGIC_MODULES")
if !ok {
fmt.Println("Did not provide GITHUB_TOKEN_MAGIC_MODULES environment variable")
os.Exit(1)
}
githubToken := githubTokenOrFallback("GITHUB_TOKEN_MAGIC_MODULES")
gh := github.NewClient(githubToken)
cb := cloudbuild.NewClient()
execMembershipChecker(prNumber, commitSha, branchName, headRepoUrl, headBranch, baseBranch, gh, cb)
Expand Down
6 changes: 4 additions & 2 deletions .ci/magician/cmd/test_terraform_vcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import (
)

var ttvEnvironmentVariables = [...]string{
"GITHUB_TOKEN_DOWNSTREAMS",
"GITHUB_TOKEN_MAGIC_MODULES",
"GOCACHE",
"GOPATH",
"GOOGLE_BILLING_ACCOUNT",
Expand Down Expand Up @@ -55,6 +53,10 @@ var testTerraformVCRCmd = &cobra.Command{
env[ev] = val
}

for _, tokenName := range []string{"GITHUB_TOKEN_DOWNSTREAMS", "GITHUB_TOKEN_MAGIC_MODULES"} {
env[tokenName] = githubTokenOrFallback(tokenName)
}

baseBranch := os.Getenv("BASE_BRANCH")
if baseBranch == "" {
baseBranch = "main"
Expand Down
6 changes: 1 addition & 5 deletions .ci/magician/cmd/test_tgc.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ var testTGCCmd = &cobra.Command{
commit := os.Getenv("COMMIT_SHA")
pr := os.Getenv("PR_NUMBER")

githubToken, ok := os.LookupEnv("GITHUB_TOKEN_MAGIC_MODULES")
if !ok {
fmt.Println("Did not provide GITHUB_TOKEN_MAGIC_MODULES environment variable")
os.Exit(1)
}
githubToken := githubTokenOrFallback("GITHUB_TOKEN_MAGIC_MODULES")
gh := github.NewClient(githubToken)

execTestTGC(commit, pr, gh)
Expand Down
6 changes: 1 addition & 5 deletions .ci/magician/cmd/test_tpg.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ var testTPGCmd = &cobra.Command{
commit := os.Getenv("COMMIT_SHA")
pr := os.Getenv("PR_NUMBER")

githubToken, ok := os.LookupEnv("GITHUB_TOKEN_MAGIC_MODULES")
if !ok {
fmt.Println("Did not provide GITHUB_TOKEN_MAGIC_MODULES environment variable")
os.Exit(1)
}
githubToken := githubTokenOrFallback("GITHUB_TOKEN_MAGIC_MODULES")
gh := github.NewClient(githubToken)

execTestTPG(version, commit, pr, gh)
Expand Down

0 comments on commit a3cf534

Please sign in to comment.