Skip to content

Commit cd86752

Browse files
authored
feat/next config workflows (#1840)
* supporting workflows in next
1 parent 0ad85ea commit cd86752

File tree

17 files changed

+169
-75
lines changed

17 files changed

+169
-75
lines changed

backend/controllers/cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (d DiggerController) UpdateRepoCache(c *gin.Context) {
6767

6868
// update the cache here, do it async for immediate response
6969
go func() {
70-
err = utils.CloneGitRepoAndDoAction(cloneUrl, branch, *token, func(dir string) error {
70+
err = utils.CloneGitRepoAndDoAction(cloneUrl, branch, "", *token, func(dir string) error {
7171
diggerYmlBytes, err := os.ReadFile(path.Join(dir, "digger.yml"))
7272
diggerYmlStr = string(diggerYmlBytes)
7373
config, _, _, err = dg_configuration.LoadDiggerConfig(dir, true, nil)

backend/controllers/github.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ func GetDiggerConfigForBranch(gh utils.GithubClientProvider, installationId int6
553553
var diggerYmlStr string
554554
var dependencyGraph graph.Graph[string, dg_configuration.Project]
555555

556-
err = utils.CloneGitRepoAndDoAction(cloneUrl, branch, *token, func(dir string) error {
556+
err = utils.CloneGitRepoAndDoAction(cloneUrl, branch, "", *token, func(dir string) error {
557557
diggerYmlBytes, err := os.ReadFile(path.Join(dir, "digger.yml"))
558558
diggerYmlStr = string(diggerYmlBytes)
559559
config, _, dependencyGraph, err = dg_configuration.LoadDiggerConfig(dir, true, changedFiles)

backend/utils/github.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,18 @@ func createTempDir() string {
2828

2929
type action func(string) error
3030

31-
func CloneGitRepoAndDoAction(repoUrl string, branch string, token string, action action) error {
31+
func CloneGitRepoAndDoAction(repoUrl string, branch string, commitHash string, token string, action action) error {
3232
dir := createTempDir()
3333
git := NewGitShellWithTokenAuth(dir, token)
3434
err := git.Clone(repoUrl, branch)
3535
if err != nil {
3636
return err
3737
}
3838

39+
if commitHash != "" {
40+
git.Checkout(commitHash)
41+
}
42+
3943
defer func() {
4044
log.Printf("removing cloned directory %v", dir)
4145
ferr := os.RemoveAll(dir)

backend/utils/github_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ func init() {
1414

1515
func TestGithubCloneWithInvalidTokenThrowsErr(t *testing.T) {
1616
f := func(d string) error { return nil }
17-
err := CloneGitRepoAndDoAction("https://github.com/diggerhq/private-repo", "main", "invalid-token", f)
17+
err := CloneGitRepoAndDoAction("https://github.com/diggerhq/private-repo", "main", "", "invalid-token", f)
1818
assert.NotNil(t, err)
1919
}
2020

2121
func TestGithubCloneWithPublicRepoThrowsNoError(t *testing.T) {
2222
token := os.Getenv("GITHUB_PAT_TOKEN")
2323
f := func(d string) error { return nil }
24-
err := CloneGitRepoAndDoAction("https://github.com/diggerhq/digger", "develop", token, f)
24+
err := CloneGitRepoAndDoAction("https://github.com/diggerhq/digger", "develop", "", token, f)
2525
assert.Nil(t, err)
2626
}
2727

@@ -32,13 +32,13 @@ func TestGithubCloneWithPrivateRepoAndValidTokenThrowsNoError(t *testing.T) {
3232
return
3333
}
3434
f := func(d string) error { return nil }
35-
err := CloneGitRepoAndDoAction("https://github.com/diggerhq/infra-gcp", "main", token, f)
35+
err := CloneGitRepoAndDoAction("https://github.com/diggerhq/infra-gcp", "main", "", token, f)
3636
assert.Nil(t, err)
3737
}
3838

3939
func TestGithubCloneWithInvalidBranchThrowsError(t *testing.T) {
4040
token := os.Getenv("GITHUB_PAT_TOKEN")
4141
f := func(d string) error { return nil }
42-
err := CloneGitRepoAndDoAction("https://github.com/diggerhq/digger", "not-a-branch", token, f)
42+
err := CloneGitRepoAndDoAction("https://github.com/diggerhq/digger", "not-a-branch", "", token, f)
4343
assert.NotNil(t, err)
4444
}

backend/utils/gitlab.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func GetDiggerConfigForBranch(gh GitlabProvider, projectId int, repoFullName str
6262
log.Printf("Error getting changed files: %v", err)
6363
return "", nil, nil, fmt.Errorf("error getting changed files")
6464
}
65-
err = CloneGitRepoAndDoAction(cloneUrl, branch, token, func(dir string) error {
65+
err = CloneGitRepoAndDoAction(cloneUrl, branch, "", token, func(dir string) error {
6666
diggerYmlBytes, err := os.ReadFile(path.Join(dir, "digger.yml"))
6767
diggerYmlStr = string(diggerYmlBytes)
6868
config, _, dependencyGraph, err = dg_configuration.LoadDiggerConfig(dir, true, changedFiles)

backend/utils/gitshell.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ func (g *GitShell) runCommand(args ...string) (string, error) {
103103
return strings.TrimSpace(stdout.String()), nil
104104
}
105105

106+
func (g *GitShell) Checkout(branchOrCommit string) error {
107+
args := []string{"checkout"}
108+
args = append(args, branchOrCommit)
109+
_, err := g.runCommand(args...)
110+
return err
111+
}
112+
106113
// Clone with authentication
107114
func (g *GitShell) Clone(repoURL, branch string) error {
108115
authURL, err := g.formatAuthURL(repoURL)

cli/pkg/spec/spec.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ func RunSpec(
4343
usage.ReportErrorAndExit(spec.VCS.Actor, fmt.Sprintf("could not get backend api: %v", err), 1)
4444
}
4545

46+
// for additional output reporting
47+
diggerOutPath := os.Getenv("DIGGER_OUT")
48+
if diggerOutPath == "" {
49+
diggerOutPath = os.Getenv("RUNNER_TEMP") + "/digger-out.log"
50+
os.Setenv("DIGGER_OUT", diggerOutPath)
51+
}
52+
4653
if spec.Job.Commit != "" {
4754
// checking out to the commit ID
4855
log.Printf("fetching commit ID %v", spec.Job.Commit)

ee/backend/controllers/gitlab.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func handlePushEvent(gh utils.GitlabProvider, payload *gitlab.PushEvent, organis
156156
isMainBranch = false
157157
}
158158

159-
err = utils.CloneGitRepoAndDoAction(cloneURL, pushBranch, token, func(dir string) error {
159+
err = utils.CloneGitRepoAndDoAction(cloneURL, pushBranch, "", token, func(dir string) error {
160160
config, err := dg_configuration.LoadDiggerConfigYaml(dir, true, nil)
161161
if err != nil {
162162
log.Printf("ERROR load digger.yml: %v", err)

ee/drift/tasks/github.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func LoadProjectsFromGithubRepo(gh utils2.GithubClientProvider, installationId s
4242
return fmt.Errorf("error getting github service")
4343
}
4444

45-
err = utils3.CloneGitRepoAndDoAction(cloneUrl, branch, *token, func(dir string) error {
45+
err = utils3.CloneGitRepoAndDoAction(cloneUrl, branch, "", *token, func(dir string) error {
4646
config, err := dg_configuration.LoadDiggerConfigYaml(dir, true, nil)
4747
if err != nil {
4848
log.Printf("ERROR load digger.yml: %v", err)

ee/drift/utils/github.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func GetDiggerConfigForBranch(gh utils.GithubClientProvider, installationId int6
103103

104104
var changedFiles []string = nil
105105

106-
err = utils2.CloneGitRepoAndDoAction(cloneUrl, branch, *token, func(dir string) error {
106+
err = utils2.CloneGitRepoAndDoAction(cloneUrl, branch, "", *token, func(dir string) error {
107107
diggerYmlBytes, err := os.ReadFile(path.Join(dir, "digger.yml"))
108108
diggerYmlStr = string(diggerYmlBytes)
109109
config, _, dependencyGraph, err = dg_configuration.LoadDiggerConfig(dir, true, changedFiles)

0 commit comments

Comments
 (0)