From cfedc518ca02fd1aa395ad028a1b369f1ce2e5ed Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Tue, 4 Apr 2023 10:59:53 +0800 Subject: [PATCH] Add `With` field to `jobparser.Job` (#37) Partially Fixes [gitea/act_runner#91 comment](https://gitea.com/gitea/act_runner/issues/91#issuecomment-734544) nektos/act has added `With` to support reusable workflows (see [code](https://github.com/nektos/act/blob/68c72b9a51f4fa586af62619f9e6361e023a5d48/pkg/model/workflow.go#L160)) GitHub actions also support [`jobs..with`](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idwith) Reviewed-on: https://gitea.com/gitea/act/pulls/37 Reviewed-by: Lunny Xiao Co-authored-by: Zettat123 Co-committed-by: Zettat123 --- pkg/jobparser/jobparser_test.go | 5 +++++ pkg/jobparser/model.go | 2 ++ pkg/jobparser/testdata/has_with.in.yaml | 15 +++++++++++++++ pkg/jobparser/testdata/has_with.out.yaml | 17 +++++++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 pkg/jobparser/testdata/has_with.in.yaml create mode 100644 pkg/jobparser/testdata/has_with.out.yaml diff --git a/pkg/jobparser/jobparser_test.go b/pkg/jobparser/jobparser_test.go index fedf996..6749cfa 100644 --- a/pkg/jobparser/jobparser_test.go +++ b/pkg/jobparser/jobparser_test.go @@ -32,6 +32,11 @@ func TestParse(t *testing.T) { options: nil, wantErr: false, }, + { + name: "has_with", + options: nil, + wantErr: false, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/pkg/jobparser/model.go b/pkg/jobparser/model.go index b3e2ae4..7d4906c 100644 --- a/pkg/jobparser/model.go +++ b/pkg/jobparser/model.go @@ -87,6 +87,7 @@ type Job struct { Defaults Defaults `yaml:"defaults,omitempty"` Outputs map[string]string `yaml:"outputs,omitempty"` Uses string `yaml:"uses,omitempty"` + With map[string]interface{} `yaml:"with,omitempty"` } func (j *Job) Clone() *Job { @@ -107,6 +108,7 @@ func (j *Job) Clone() *Job { Defaults: j.Defaults, Outputs: j.Outputs, Uses: j.Uses, + With: j.With, } } diff --git a/pkg/jobparser/testdata/has_with.in.yaml b/pkg/jobparser/testdata/has_with.in.yaml new file mode 100644 index 0000000..4e3dc74 --- /dev/null +++ b/pkg/jobparser/testdata/has_with.in.yaml @@ -0,0 +1,15 @@ +name: test +jobs: + job1: + name: job1 + runs-on: linux + uses: .gitea/workflows/build.yml + with: + package: service + + job2: + name: job2 + runs-on: linux + uses: .gitea/workflows/build.yml + with: + package: module diff --git a/pkg/jobparser/testdata/has_with.out.yaml b/pkg/jobparser/testdata/has_with.out.yaml new file mode 100644 index 0000000..de79b80 --- /dev/null +++ b/pkg/jobparser/testdata/has_with.out.yaml @@ -0,0 +1,17 @@ +name: test +jobs: + job1: + name: job1 + runs-on: linux + uses: .gitea/workflows/build.yml + with: + package: service +--- +name: test +jobs: + job2: + name: job2 + runs-on: linux + uses: .gitea/workflows/build.yml + with: + package: module