Skip to content

Commit 7b9330c

Browse files
committed
code review fixes
1 parent 13716d2 commit 7b9330c

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

0-bootstrap/scripts/choose_build_type.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ TARGET_BUILD="$1"
2323
build_types=("cb" "github" "gitlab" "jenkins" "terraform_cloud")
2424

2525
# Validate the build_type input
26-
if [[ ! " ${build_types[*]} " =~ " ${TARGET_BUILD} " ]]; then
26+
if [[ ! " ${build_types[*]} " == *" ${TARGET_BUILD} "* ]]; then
2727
echo "Error: Invalid build type '$TARGET_BUILD'. Must be one of: ${build_types[*]}"
2828
exit 1
2929
fi

helpers/foundation-deployer/github/github.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const (
4646
)
4747

4848
type GH struct {
49-
TriggerNewBuild func(t testing.TB, ctx context.Context, owner, repo, token string, runID int64) (int64, string, string, error)
49+
TriggerNewBuild func(t testing.TB, ctx context.Context, owner, repo, token, commitSha string, runID int64) (int64, string, string, error)
5050
sleepTime time.Duration
5151
}
5252

@@ -59,7 +59,7 @@ func NewGH() GH {
5959
}
6060

6161
// triggerNewBuild triggers a new action execution
62-
func triggerNewBuild(t testing.TB, ctx context.Context, owner, repo, token string, runID int64) (int64, string, string, error) {
62+
func triggerNewBuild(t testing.TB, ctx context.Context, owner, repo, token, commitSha string, runID int64) (int64, string, string, error) {
6363
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})
6464
tc := oauth2.NewClient(ctx, ts)
6565
client := github.NewClient(tc)
@@ -75,8 +75,9 @@ func triggerNewBuild(t testing.TB, ctx context.Context, owner, repo, token strin
7575
}
7676
return 0, "", "", fmt.Errorf("error re-running workflow status: %d body: %s", resp.StatusCode, string(bodyBytes))
7777
}
78-
opts := &github.ListWorkflowRunsOptions{
7978

79+
opts := &github.ListWorkflowRunsOptions{
80+
HeadSHA: commitSha,
8081
ListOptions: github.ListOptions{
8182
PerPage: 1,
8283
Page: 1,
@@ -115,17 +116,18 @@ func triggerNewBuild(t testing.TB, ctx context.Context, owner, repo, token strin
115116
}
116117

117118
// GetLastActionState returns the state of the latest action
118-
func (g GH) GetLastActionState(t testing.TB, ctx context.Context, owner, repo, token string) (int64, string, string, error) {
119+
func (g GH) GetLastActionState(t testing.TB, ctx context.Context, owner, repo, token, commitSha string) (int64, string, string, error) {
119120
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})
120121
tc := oauth2.NewClient(ctx, ts)
121122
client := github.NewClient(tc)
122123

123124
opts := &github.ListWorkflowRunsOptions{
124-
125+
HeadSHA: commitSha,
125126
ListOptions: github.ListOptions{
126127
PerPage: 1,
127128
},
128129
}
130+
129131
runs, _, err := client.Actions.ListRepositoryWorkflowRuns(ctx, owner, repo, opts)
130132

131133
if err != nil {
@@ -260,7 +262,7 @@ func (g GH) GetFinalActionState(t testing.TB, ctx context.Context, owner, repo,
260262
}
261263

262264
// WaitBuildSuccess waits for the current build in a repo to finish.
263-
func (g GH) WaitBuildSuccess(t testing.TB, owner, repo, token string, failureMsg string, maxBuildRetry, maxErrorRetries int, timeBetweenErrorRetries time.Duration) error {
265+
func (g GH) WaitBuildSuccess(t testing.TB, owner, repo, token, commitSha, failureMsg string, maxBuildRetry, maxErrorRetries int, timeBetweenErrorRetries time.Duration) error {
264266
var status, conclusion string
265267
var runID int64
266268
var err error
@@ -269,7 +271,7 @@ func (g GH) WaitBuildSuccess(t testing.TB, owner, repo, token string, failureMsg
269271
// wait action creation
270272
time.Sleep(30 * time.Second)
271273

272-
runID, status, conclusion, err = g.GetLastActionState(t, ctx, owner, repo, token)
274+
runID, status, conclusion, err = g.GetLastActionState(t, ctx, owner, repo, token, commitSha)
273275
if err != nil {
274276
return err
275277
}
@@ -295,7 +297,7 @@ func (g GH) WaitBuildSuccess(t testing.TB, owner, repo, token string, failureMsg
295297
}
296298

297299
// Trigger a new build
298-
runID, status, conclusion, err = g.TriggerNewBuild(t, ctx, owner, repo, token, runID)
300+
runID, status, conclusion, err = g.TriggerNewBuild(t, ctx, owner, repo, token, commitSha, runID)
299301
if err != nil {
300302
return fmt.Errorf("failed to trigger new action (attempt %d/%d): %w", i+1, maxErrorRetries, err)
301303
}

helpers/foundation-deployer/stages/executor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func NewGitHubExecutor(owner, repo, token string) *GitHubExecutor {
6161
}
6262

6363
func (e *GitHubExecutor) WaitBuildSuccess(t testing.TB, commitSha, failureMsg string) error {
64-
return e.executor.WaitBuildSuccess(t, e.owner, e.repo, e.token, failureMsg, MaxBuildRetries, MaxErrorRetries, TimeBetweenErrorRetries)
64+
return e.executor.WaitBuildSuccess(t, e.owner, e.repo, e.token, commitSha, failureMsg, MaxBuildRetries, MaxErrorRetries, TimeBetweenErrorRetries)
6565
}
6666

6767
type GitLabExecutor struct {

helpers/foundation-deployer/utils/git.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,13 @@ func cloneGit(t testing.TB, repositoryUrl, path string, logger *logger.Logger) G
6363

6464
if os.IsNotExist(err) {
6565
cmd := exec.Command("git", "clone", repositoryUrl, path)
66-
fmt.Printf("Executing command %s", cmd)
67-
// Run the command and capture its standard output
68-
output, err := cmd.Output()
66+
fmt.Printf("Executing command %s\n", cmd.String())
67+
// Run the command and capture its combined output
68+
output, err := cmd.CombinedOutput()
6969
if err != nil {
7070
t.Fatalf("Error executing git command: %v", err)
7171
}
72-
// Convert the output to a string and trim whitespace
73-
branchName := strings.TrimSpace(string(output))
74-
fmt.Printf("Current Git branch: %s\n", branchName)
72+
fmt.Printf("git clone output:\n%s\n", string(output))
7573
}
7674

7775
return GitRepo{

0 commit comments

Comments
 (0)