Skip to content

Commit f3123df

Browse files
authored
feat: support concurrency setting (#7)
Co-authored-by: rick <[email protected]>
1 parent 7d3d77b commit f3123df

13 files changed

+119
-12
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,13 @@ spec:
8282
Considering [GitHub Workflows](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsuses)
8383
has a complex syntax. Currently, we support the following ones:
8484
85+
* [Event filter](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on)
86+
* Support `on.push` and `on.merge_request`
8587
* keyword `uses`
8688
* support `actions/checkout`, `actions/setup-go`, `goreleaser/goreleaser-action` and `docker://`
8789
* keyword `run`
8890
* keyword `env`
91+
* [concurrency](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#concurrency)
92+
* Not support `cancel-in-progress` yet
8993

9094
There are some limitations. For example, only the first job could be recognized in each file.

cmd/convert_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ spec:
201201
resources:
202202
requests:
203203
storage: 64Mi
204-
205204
templates:
206205
- name: main
207206
dag:

cmd/data/combine-workflow.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ spec:
2020
resources:
2121
requests:
2222
storage: 64Mi
23-
2423
templates:
2524
- name: main
2625
dag:
@@ -58,7 +57,6 @@ spec:
5857
resources:
5958
requests:
6059
storage: 64Mi
61-
6260
templates:
6361
- name: main
6462
dag:

cmd/data/one-workflow-env.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ spec:
1818
resources:
1919
requests:
2020
storage: 64Mi
21-
2221
templates:
2322
- name: main
2423
dag:

cmd/data/one-workflow.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ spec:
1818
resources:
1919
requests:
2020
storage: 64Mi
21-
2221
templates:
2322
- name: main
2423
dag:

pkg/argo-workflow.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,11 @@ spec:
258258
resources:
259259
requests:
260260
storage: 64Mi
261-
261+
{{- if .Concurrency}}
262+
synchronization:
263+
mutex:
264+
name: {{.Concurrency}}
265+
{{- end}}
262266
templates:
263267
- name: main
264268
dag:

pkg/argo-workflow_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ func TestWorkflow_ConvertToArgoWorkflow(t *testing.T) {
2525
name: "complex event",
2626
githubActions: "data/github-action-complex-event.yaml",
2727
argoWorkflows: "data/argo-workflows-complex-event.yaml",
28+
}, {
29+
name: "with concurrency",
30+
githubActions: "data/github-actions-concurrency.yaml",
31+
argoWorkflows: "data/argo-workflows-concurrency.yaml",
2832
}}
2933
for _, tt := range tests {
3034
t.Run(tt.name, func(t *testing.T) {

pkg/data/argo-workflows-complex-event.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ spec:
1818
resources:
1919
requests:
2020
storage: 64Mi
21-
2221
templates:
2322
- name: main
2423
dag:
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
apiVersion: argoproj.io/v1alpha1
2+
kind: WorkflowTemplate
3+
metadata:
4+
name: build
5+
spec:
6+
entrypoint: main
7+
arguments:
8+
parameters:
9+
- name: branch
10+
default: master
11+
- name: pr
12+
default: -1
13+
volumeClaimTemplates:
14+
- metadata:
15+
name: work
16+
spec:
17+
accessModes: ["ReadWriteOnce"]
18+
resources:
19+
requests:
20+
storage: 64Mi
21+
synchronization:
22+
mutex:
23+
name: test
24+
templates:
25+
- name: main
26+
dag:
27+
tasks:
28+
- name: clone
29+
template: clone
30+
- name: test
31+
template: test
32+
depends: clone
33+
- name: goreleaser
34+
template: goreleaser
35+
depends: test
36+
- name: clone
37+
script:
38+
image: alpine/git:v2.26.2
39+
command: [sh]
40+
source: |
41+
branch=$(echo {{workflow.parameters.branch}} | sed -e 's/refs\/heads\///g')
42+
git clone --branch $branch https://gitee.com/LinuxSuRen/yaml-readme .
43+
if [ {{workflow.parameters.pr}} != -1 ]; then
44+
git fetch origin merge-requests/{{workflow.parameters.pr}}/head:mr-{{workflow.parameters.pr}}
45+
git checkout mr-{{workflow.parameters.pr}}
46+
fi
47+
volumeMounts:
48+
- mountPath: /work
49+
name: work
50+
workingDir: /work
51+
- name: test
52+
script:
53+
image: golang:1.18
54+
command: [sh]
55+
env:
56+
- name: GOPROXY
57+
value: https://goproxy.io,direct
58+
source: |
59+
go test ./... -coverprofile coverage.out
60+
volumeMounts:
61+
- mountPath: /work
62+
name: work
63+
workingDir: /work
64+
- name: goreleaser
65+
script:
66+
image: goreleaser/goreleaser:v1.13.1
67+
command: [sh]
68+
env:
69+
- name: GOPROXY
70+
value: https://goproxy.io,direct
71+
source: |
72+
goreleaser release --skip-publish --rm-dist
73+
volumeMounts:
74+
- mountPath: /work
75+
name: work
76+
workingDir: /work

pkg/data/argo-workflows-image.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ spec:
1818
resources:
1919
requests:
2020
storage: 64Mi
21-
2221
templates:
2322
- name: main
2423
dag:

pkg/data/argo-workflows.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ spec:
1818
resources:
1919
requests:
2020
storage: 64Mi
21-
2221
templates:
2322
- name: main
2423
dag:
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: build
2+
concurrency: test
3+
jobs:
4+
build:
5+
name: build
6+
runs-on: ubuntu-20.04
7+
steps:
8+
- name: Set up Go 1.18
9+
uses: actions/setup-go@v3
10+
with:
11+
go-version: 1.18
12+
id: go
13+
- name: clone
14+
uses: actions/[email protected]
15+
- name: test
16+
env:
17+
GOPROXY: https://goproxy.io,direct
18+
run: |
19+
go test ./... -coverprofile coverage.out
20+
- name: GoReleaser
21+
uses: goreleaser/[email protected]
22+
env:
23+
GOPROXY: https://goproxy.io,direct
24+
with:
25+
version: latest
26+
args: release --skip-publish --rm-dist

pkg/github.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import (
55
)
66

77
type Workflow struct {
8-
Name string
9-
On interface{} // could be: string, []string, Event
10-
Jobs map[string]Job
8+
Name string
9+
On interface{} // could be: string, []string, Event
10+
Jobs map[string]Job
11+
Concurrency string
1112

1213
// extra fields
1314
GitRepository string

0 commit comments

Comments
 (0)