Skip to content

Commit eb83d67

Browse files
committed
fix: make the unittest to be correct
1 parent d33ac9c commit eb83d67

File tree

5 files changed

+108
-65
lines changed

5 files changed

+108
-65
lines changed

.github/workflows/pull-request.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ jobs:
2323
- name: Test
2424
run: |
2525
go test ./... -coverprofile coverage.out
26+
- name: Upload coverage to Codecov
27+
uses: codecov/codecov-action@v1
28+
with:
29+
token: ${{ secrets.CODECOV_TOKEN }}
30+
files: coverage.out
31+
flags: unittests
32+
name: codecov-umbrella
33+
fail_ci_if_error: true
2634
- name: Run GoReleaser
2735
uses: goreleaser/goreleaser-action@v2.9.1
2836
with:

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
[![codecov](https://codecov.io/gh/LinuxSuRen/github-action-workflow/branch/master/graph/badge.svg?token=mnFyeD2IQ7)](https://codecov.io/gh/LinuxSuRen/github-action-workflow)
2+
13
# github-action-workflow
24
GitHub Actions compatible workflows

pkg/argo-workflow.go

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func (w *Workflow) ConvertToArgoWorkflow() (output string, err error) {
4040
} else {
4141
w.Jobs[i].Steps[j].Image = defaultImage
4242
}
43+
w.Jobs[i].Steps[j].Run = strings.TrimSpace(w.Jobs[i].Steps[j].Run)
4344
}
4445

4546
// TODO currently we can only handle one job
@@ -51,7 +52,7 @@ func (w *Workflow) ConvertToArgoWorkflow() (output string, err error) {
5152

5253
data := bytes.NewBuffer([]byte{})
5354
if err = t.Execute(data, w); err == nil {
54-
output = data.String()
55+
output = strings.TrimSpace(data.String())
5556
}
5657
return
5758
}
@@ -63,7 +64,6 @@ metadata:
6364
name: {{.Name}}
6465
spec:
6566
entrypoint: main
66-
6767
volumeClaimTemplates:
6868
- metadata:
6969
name: work
@@ -74,38 +74,39 @@ spec:
7474
storage: 64Mi
7575
7676
templates:
77-
- name: main
78-
steps:
79-
{{- range $key, $job := .Jobs}}
80-
{{- range $i, $step := $job.Steps}}
81-
{{if $step.Image}}
82-
- - name: {{$step.Name}}
83-
template: {{$step.Name}}
84-
{{end}}
85-
{{- end}}
86-
{{end}}
77+
- name: main
78+
dag:
79+
tasks:
80+
{{- range $key, $job := .Jobs}}
81+
{{- range $i, $step := $job.Steps}}
82+
{{- if $step.Image}}
83+
- name: {{$step.Name}}
84+
template: {{$step.Name}}
85+
{{- end}}
86+
{{- end}}
87+
{{- end}}
8788
88-
{{- range $key, $job := .Jobs}}
89-
{{- range $i, $step := $job.Steps}}
90-
{{if $step.Image}}
91-
- name: {{$step.Name}}
92-
script:
93-
image: {{$step.Image}}
94-
command: [sh]
95-
{{if $step.Env}}
96-
env:
97-
{{- range $k, $v := $step.Env}}
98-
- name: {{$k}}
99-
value: {{$v}}
100-
{{end}}
101-
{{end}}
102-
source: |
103-
{{$step.Run}}
104-
volumeMounts:
105-
- mountPath: /work
106-
name: work
107-
workingDir: /work
108-
{{end}}
109-
{{- end}}
110-
{{end}}
89+
{{- range $key, $job := .Jobs}}
90+
{{- range $i, $step := $job.Steps}}
91+
{{- if $step.Image}}
92+
- name: {{$step.Name}}
93+
script:
94+
image: {{$step.Image}}
95+
command: [sh]
96+
{{- if $step.Env}}
97+
env:
98+
{{- range $k, $v := $step.Env}}
99+
- name: {{$k}}
100+
value: {{$v}}
101+
{{- end}}
102+
{{- end}}
103+
source: |
104+
{{$step.Run}}
105+
volumeMounts:
106+
- mountPath: /work
107+
name: work
108+
workingDir: /work
109+
{{- end}}
110+
{{- end}}
111+
{{- end}}
111112
`

pkg/argo-workflow_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ func TestWorkflow_ConvertToArgoWorkflow(t *testing.T) {
3434

3535
wantData, err := os.ReadFile(tt.argoWorkflows)
3636
assert.Nil(t, err)
37-
38-
if gotOutput != string(wantData) {
39-
t.Errorf("ConvertToArgoWorkflow() gotOutput = %v, want %v", gotOutput, string(wantData))
40-
}
37+
assert.Equal(t, string(wantData), gotOutput)
4138
})
4239
}
4340
}

pkg/data/argo-workflows.yaml

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,61 @@
1-
apiVersion: argoproj.io/v1alpha1
2-
kind: WorkflowTemplate
3-
metadata:
4-
name: script
5-
spec:
6-
entrypoint: main
7-
templates:
8-
- name: main
9-
steps:
10-
- - name: shell
11-
template: shell
12-
- name: python
13-
template: python
14-
- name: shell
15-
script:
16-
image: alpine
17-
command: [sh]
18-
source: echo 1
19-
- name: python
20-
script:
21-
image: python:alpine3.6
22-
command: [python]
23-
source: |
24-
import random
25-
i = random.randint(1, 100)
26-
print(i)
1+
apiVersion: argoproj.io/v1alpha1
2+
kind: WorkflowTemplate
3+
metadata:
4+
name: build
5+
spec:
6+
entrypoint: main
7+
volumeClaimTemplates:
8+
- metadata:
9+
name: work
10+
spec:
11+
accessModes: ["ReadWriteOnce"]
12+
resources:
13+
requests:
14+
storage: 64Mi
15+
16+
templates:
17+
- name: main
18+
dag:
19+
tasks:
20+
- name: clone
21+
template: clone
22+
- name: test
23+
template: test
24+
- name: goreleaser
25+
template: goreleaser
26+
- name: clone
27+
script:
28+
image: alpine/git:v2.26.2
29+
command: [sh]
30+
source: |
31+
git clone https://gitee.com/LinuxSuRen/yaml-readme .
32+
volumeMounts:
33+
- mountPath: /work
34+
name: work
35+
workingDir: /work
36+
- name: test
37+
script:
38+
image: golang:1.18
39+
command: [sh]
40+
env:
41+
- name: GOPROXY
42+
value: https://goproxy.io,direct
43+
source: |
44+
go test ./... -coverprofile coverage.out
45+
volumeMounts:
46+
- mountPath: /work
47+
name: work
48+
workingDir: /work
49+
- name: goreleaser
50+
script:
51+
image: goreleaser/goreleaser:v1.13.1
52+
command: [sh]
53+
env:
54+
- name: GOPROXY
55+
value: https://goproxy.io,direct
56+
source: |
57+
goreleaser release --skip-publish --rm-dist
58+
volumeMounts:
59+
- mountPath: /work
60+
name: work
61+
workingDir: /work

0 commit comments

Comments
 (0)