Skip to content

Commit cb39ac1

Browse files
authored
Merge pull request #74 from daniel-hutao/dev-1
fix: some tips with githubactions for golang
2 parents 0e710cb + 2be4b87 commit cb39ac1

File tree

6 files changed

+22
-18
lines changed

6 files changed

+22
-18
lines changed

cmd/devstream/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ var (
1111

1212
rootCMD = &cobra.Command{
1313
Use: "dtm",
14-
Short: "DevStream is an open-source DevOps tool manager",
15-
Long: `DevStream is an open-source DevOps tool manager`,
14+
Short: "DevStream is an open-source DevOps toolchain manager",
15+
Long: `DevStream is an open-source DevOps toolchain manager`,
1616
}
1717
)
1818

internal/pkg/githubactions/githubactions.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ func (ga *GithubActions) AddWorkflow(workflow *Workflow) error {
7070
opts)
7171

7272
if err != nil {
73-
log.Println(err)
7473
return err
7574
}
7675
log.Printf("github actions Workflow %s created\n", workflow.workflowFileName)
@@ -104,7 +103,6 @@ func (ga *GithubActions) DeleteWorkflow(workflow *Workflow) error {
104103
opts)
105104

106105
if err != nil {
107-
log.Println(err)
108106
return err
109107
}
110108
log.Printf("github actions Workflow %s removed\n", workflow.workflowFileName)
@@ -120,14 +118,14 @@ func (ga *GithubActions) fileExists(filename string) (bool, error) {
120118
&github.RepositoryContentGetOptions{},
121119
)
122120

123-
if resp.StatusCode == http.StatusNotFound {
124-
return false, nil
125-
}
126-
127121
if err != nil {
128122
return false, err
129123
}
130124

125+
if resp.StatusCode == http.StatusNotFound {
126+
return false, nil
127+
}
128+
131129
if resp.StatusCode == http.StatusOK {
132130
return true, nil
133131
}
@@ -141,7 +139,7 @@ func generateGitHubWorkflowFileByName(f string) string {
141139
func getGitHubToken() string {
142140
err := viper.BindEnv("github_token")
143141
if err != nil {
144-
log.Println("ENV var GITHUB_TOKEN is needed")
142+
log.Printf("bind ENV var GITHUB_TOKEN failed: %s", err)
145143
return ""
146144
}
147145

@@ -151,7 +149,7 @@ func getGitHubToken() string {
151149
func getGitHubClient(ctx context.Context) (*github.Client, error) {
152150
token := getGitHubToken()
153151
if token == "" {
154-
return nil, fmt.Errorf("failed to initialize GitHub token")
152+
return nil, fmt.Errorf("failed to initialize GitHub token. More info - https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token")
155153
}
156154
ts := oauth2.StaticTokenSource(
157155
&oauth2.Token{AccessToken: token},

internal/pkg/githubactions/golang/templates.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var PrBuilder = `
44
name: PR Builder
55
on:
66
pull_request:
7-
branches: [ master ]
7+
branches: [ master, main ]
88
jobs:
99
test:
1010
runs-on: ubuntu-latest
@@ -14,17 +14,17 @@ jobs:
1414
uses: actions/setup-go@v2
1515
with:
1616
go-version: 1.17
17-
- name: Test
18-
run: go test -v ./...
1917
- name: Build
2018
run: go build -v ./...
19+
- name: Test
20+
run: go test -v ./...
2121
`
2222

2323
var MasterBuilder = `
2424
name: Master Builder
2525
on:
2626
push:
27-
branches: [ master ]
27+
branches: [ master, main ]
2828
jobs:
2929
test:
3030
name: Test

internal/pkg/githubactions/install.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package githubactions
22

3-
import "fmt"
3+
import "log"
44

55
// Install sets up GitHub Actions workflows.
66
func Install(options *map[string]interface{}) (bool, error) {
@@ -10,11 +10,9 @@ func Install(options *map[string]interface{}) (bool, error) {
1010
}
1111

1212
language := githubActions.GetLanguage()
13+
log.Printf("language is %s", language.String())
1314
ws := defaultWorkflows.GetWorkflowByNameVersionTypeString(language.String())
1415

15-
fmt.Println("lang is ", language.Name, language.Version, language.String())
16-
fmt.Println("ws is ", ws)
17-
1816
for _, pipeline := range ws {
1917
err := githubActions.AddWorkflow(pipeline)
2018
if err != nil {

internal/pkg/githubactions/reinstall.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package githubactions
22

3+
import (
4+
"log"
5+
)
6+
37
// Reinstall remove and set up GitHub Actions workflows.
48
func Reinstall(options *map[string]interface{}) (bool, error) {
59
githubActions, err := NewGithubActions(options)
@@ -8,6 +12,7 @@ func Reinstall(options *map[string]interface{}) (bool, error) {
812
}
913

1014
language := githubActions.GetLanguage()
15+
log.Printf("language is %s", language.String())
1116
ws := defaultWorkflows.GetWorkflowByNameVersionTypeString(language.String())
1217

1318
for _, pipeline := range ws {

internal/pkg/githubactions/uninstall.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package githubactions
22

3+
import "log"
4+
35
// Uninstall remove GitHub Actions workflows.
46
func Uninstall(options *map[string]interface{}) (bool, error) {
57
githubActions, err := NewGithubActions(options)
@@ -8,6 +10,7 @@ func Uninstall(options *map[string]interface{}) (bool, error) {
810
}
911

1012
language := githubActions.GetLanguage()
13+
log.Printf("language is %s", language.String())
1114
ws := defaultWorkflows.GetWorkflowByNameVersionTypeString(language.String())
1215

1316
for _, pipeline := range ws {

0 commit comments

Comments
 (0)