summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorTheFox0x7 <thefox0x7@gmail.com>2024-07-01 20:23:17 +0200
committerTheFox0x7 <thefox0x7@gmail.com>2024-07-01 20:23:17 +0200
commit39a5735dc74beaa2998c03c013f1bd4144e0ab43 (patch)
treee97f84e1b47f2cdb1536d90db52266f8f9c1e736 /pkg
parentMerge pull request 'Fix NewDockerNetworkCreateExecutor in docker_stub' (#39) ... (diff)
downloadforgejo-act-39a5735dc74beaa2998c03c013f1bd4144e0ab43.tar.xz
forgejo-act-39a5735dc74beaa2998c03c013f1bd4144e0ab43.zip
fix(jobparser): template job name if it's defined
Diffstat (limited to 'pkg')
-rw-r--r--pkg/jobparser/jobparser.go9
-rw-r--r--pkg/jobparser/jobparser_test.go5
-rw-r--r--pkg/jobparser/testdata/multiple_named_matrix.in.yaml14
-rw-r--r--pkg/jobparser/testdata/multiple_named_matrix.out.yaml101
4 files changed, 126 insertions, 3 deletions
diff --git a/pkg/jobparser/jobparser.go b/pkg/jobparser/jobparser.go
index 7b3a281..b8c206a 100644
--- a/pkg/jobparser/jobparser.go
+++ b/pkg/jobparser/jobparser.go
@@ -48,12 +48,15 @@ func Parse(content []byte, options ...ParseOption) ([]*SingleWorkflow, error) {
}
for _, matrix := range matricxes {
job := job.Clone()
+ evaluator := NewExpressionEvaluator(NewInterpeter(id, origin.GetJob(id), matrix, pc.gitContext, results, pc.vars))
if job.Name == "" {
- job.Name = id
+ job.Name = nameWithMatrix(id, matrix)
+ } else {
+ job.Name = evaluator.Interpolate(job.Name)
}
- job.Name = nameWithMatrix(job.Name, matrix)
+
job.Strategy.RawMatrix = encodeMatrix(matrix)
- evaluator := NewExpressionEvaluator(NewInterpeter(id, origin.GetJob(id), matrix, pc.gitContext, results, pc.vars))
+
runsOn := origin.GetJob(id).RunsOn()
for i, v := range runsOn {
runsOn[i] = evaluator.Interpolate(v)
diff --git a/pkg/jobparser/jobparser_test.go b/pkg/jobparser/jobparser_test.go
index 454d9e4..06ed825 100644
--- a/pkg/jobparser/jobparser_test.go
+++ b/pkg/jobparser/jobparser_test.go
@@ -18,6 +18,11 @@ func TestParse(t *testing.T) {
wantErr bool
}{
{
+ name: "multiple_named_matrix",
+ options: nil,
+ wantErr: false,
+ },
+ {
name: "multiple_jobs",
options: nil,
wantErr: false,
diff --git a/pkg/jobparser/testdata/multiple_named_matrix.in.yaml b/pkg/jobparser/testdata/multiple_named_matrix.in.yaml
new file mode 100644
index 0000000..bd44b2c
--- /dev/null
+++ b/pkg/jobparser/testdata/multiple_named_matrix.in.yaml
@@ -0,0 +1,14 @@
+name: test
+jobs:
+ job1:
+ strategy:
+ matrix:
+ os: [ubuntu-22.04, ubuntu-20.04]
+ version: [1.17, 1.18, 1.19]
+ runs-on: ${{ matrix.os }}
+ name: On ${{ matrix.os }} with go v${{ matrix.version }}
+ steps:
+ - uses: actions/setup-go@v3
+ with:
+ go-version: ${{ matrix.version }}
+ - run: uname -a && go version
diff --git a/pkg/jobparser/testdata/multiple_named_matrix.out.yaml b/pkg/jobparser/testdata/multiple_named_matrix.out.yaml
new file mode 100644
index 0000000..eea2da6
--- /dev/null
+++ b/pkg/jobparser/testdata/multiple_named_matrix.out.yaml
@@ -0,0 +1,101 @@
+name: test
+jobs:
+ job1:
+ name: On ubuntu-20.04 with go v1.17
+ runs-on: ubuntu-20.04
+ steps:
+ - uses: actions/setup-go@v3
+ with:
+ go-version: ${{ matrix.version }}
+ - run: uname -a && go version
+ strategy:
+ matrix:
+ os:
+ - ubuntu-20.04
+ version:
+ - 1.17
+---
+name: test
+jobs:
+ job1:
+ name: On ubuntu-20.04 with go v1.18
+ runs-on: ubuntu-20.04
+ steps:
+ - uses: actions/setup-go@v3
+ with:
+ go-version: ${{ matrix.version }}
+ - run: uname -a && go version
+ strategy:
+ matrix:
+ os:
+ - ubuntu-20.04
+ version:
+ - 1.18
+---
+name: test
+jobs:
+ job1:
+ name: On ubuntu-20.04 with go v1.19
+ runs-on: ubuntu-20.04
+ steps:
+ - uses: actions/setup-go@v3
+ with:
+ go-version: ${{ matrix.version }}
+ - run: uname -a && go version
+ strategy:
+ matrix:
+ os:
+ - ubuntu-20.04
+ version:
+ - 1.19
+---
+name: test
+jobs:
+ job1:
+ name: On ubuntu-22.04 with go v1.17
+ runs-on: ubuntu-22.04
+ steps:
+ - uses: actions/setup-go@v3
+ with:
+ go-version: ${{ matrix.version }}
+ - run: uname -a && go version
+ strategy:
+ matrix:
+ os:
+ - ubuntu-22.04
+ version:
+ - 1.17
+---
+name: test
+jobs:
+ job1:
+ name: On ubuntu-22.04 with go v1.18
+ runs-on: ubuntu-22.04
+ steps:
+ - uses: actions/setup-go@v3
+ with:
+ go-version: ${{ matrix.version }}
+ - run: uname -a && go version
+ strategy:
+ matrix:
+ os:
+ - ubuntu-22.04
+ version:
+ - 1.18
+---
+name: test
+jobs:
+ job1:
+ name: On ubuntu-22.04 with go v1.19
+ runs-on: ubuntu-22.04
+ steps:
+ - uses: actions/setup-go@v3
+ with:
+ go-version: ${{ matrix.version }}
+ - run: uname -a && go version
+ strategy:
+ matrix:
+ os:
+ - ubuntu-22.04
+ version:
+ - 1.19