mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-19 17:01:12 +00:00
Some checks failed
testing / frontend-checks (push) Has been skipped
testing / backend-checks (push) Has been skipped
testing / test-unit (push) Has been skipped
testing / test-mysql (push) Has been skipped
testing / test-e2e (push) Has been skipped
testing / test-sqlite (push) Has been skipped
testing / test-pgsql (push) Has been skipped
testing / test-remote-cacher (valkey) (push) Has been skipped
testing / test-remote-cacher (redis) (push) Has been skipped
testing / test-remote-cacher (redict) (push) Has been skipped
testing / test-remote-cacher (garnet) (push) Has been skipped
testing / security-check (push) Has been skipped
/ release (push) Has been cancelled
**Backport: https://codeberg.org/forgejo/forgejo/pulls/8864**
The status of two jobs by the same name shadow each other, they need to be distinct. If two jobs by the same name are found, they are made distinct by adding a -<occurence number> suffix.
Resolves forgejo/forgejo#8648
(cherry picked from commit 6bc1803c70
)
```
Conflicts:
services/actions/notifier_helper.go
services/actions/schedule_tasks.go
services/actions/workflows.go
trivial context conflicts
services/actions/job_parser.go
use "github.com/nektos/act/pkg/jobparser"
```
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8884
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Earl Warren <contact@earl-warren.org>
Co-committed-by: Earl Warren <contact@earl-warren.org>
212 lines
3.8 KiB
Go
212 lines
3.8 KiB
Go
// Copyright 2025 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package actions
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestServiceActions_jobParser(t *testing.T) {
|
|
for _, testCase := range []struct {
|
|
name string
|
|
workflow string
|
|
singleWorkflows []string
|
|
}{
|
|
{
|
|
name: "OneJobNoDuplicate",
|
|
workflow: `
|
|
jobs:
|
|
job1:
|
|
runs-on: docker
|
|
steps:
|
|
- run: echo OK
|
|
`,
|
|
singleWorkflows: []string{
|
|
`jobs:
|
|
job1:
|
|
name: job1
|
|
runs-on: docker
|
|
steps:
|
|
- run: echo OK
|
|
`,
|
|
},
|
|
},
|
|
{
|
|
name: "MatrixTwoJobsWithSameJobName",
|
|
workflow: `
|
|
name: test
|
|
jobs:
|
|
job1:
|
|
name: shadowdefaultmatrixgeneratednames
|
|
strategy:
|
|
matrix:
|
|
version: [1.17, 1.19]
|
|
runs-on: docker
|
|
steps:
|
|
- run: echo OK
|
|
`,
|
|
singleWorkflows: []string{
|
|
`name: test
|
|
jobs:
|
|
job1:
|
|
name: shadowdefaultmatrixgeneratednames
|
|
runs-on: docker
|
|
steps:
|
|
- run: echo OK
|
|
strategy:
|
|
matrix:
|
|
version:
|
|
- 1.17
|
|
`,
|
|
`name: test
|
|
jobs:
|
|
job1:
|
|
name: shadowdefaultmatrixgeneratednames-1
|
|
runs-on: docker
|
|
steps:
|
|
- run: echo OK
|
|
strategy:
|
|
matrix:
|
|
version:
|
|
- 1.19
|
|
`,
|
|
},
|
|
},
|
|
{
|
|
name: "MatrixTwoJobsWithMatrixGeneratedNames",
|
|
workflow: `
|
|
name: test
|
|
jobs:
|
|
job1:
|
|
strategy:
|
|
matrix:
|
|
version: [1.17, 1.19]
|
|
runs-on: docker
|
|
steps:
|
|
- run: echo OK
|
|
`,
|
|
singleWorkflows: []string{
|
|
`name: test
|
|
jobs:
|
|
job1:
|
|
name: job1 (1.17)
|
|
runs-on: docker
|
|
steps:
|
|
- run: echo OK
|
|
strategy:
|
|
matrix:
|
|
version:
|
|
- 1.17
|
|
`,
|
|
`name: test
|
|
jobs:
|
|
job1:
|
|
name: job1 (1.19)
|
|
runs-on: docker
|
|
steps:
|
|
- run: echo OK
|
|
strategy:
|
|
matrix:
|
|
version:
|
|
- 1.19
|
|
`,
|
|
},
|
|
},
|
|
{
|
|
name: "MatrixTwoJobsWithDistinctInterpolatedNames",
|
|
workflow: `
|
|
name: test
|
|
jobs:
|
|
job1:
|
|
name: myname-${{ matrix.version }}
|
|
strategy:
|
|
matrix:
|
|
version: [1.17, 1.19]
|
|
runs-on: docker
|
|
steps:
|
|
- run: echo OK
|
|
`,
|
|
singleWorkflows: []string{
|
|
`name: test
|
|
jobs:
|
|
job1:
|
|
name: myname-1.17
|
|
runs-on: docker
|
|
steps:
|
|
- run: echo OK
|
|
strategy:
|
|
matrix:
|
|
version:
|
|
- 1.17
|
|
`,
|
|
`name: test
|
|
jobs:
|
|
job1:
|
|
name: myname-1.19
|
|
runs-on: docker
|
|
steps:
|
|
- run: echo OK
|
|
strategy:
|
|
matrix:
|
|
version:
|
|
- 1.19
|
|
`,
|
|
},
|
|
},
|
|
{
|
|
name: "MatrixTwoJobsWithIdenticalInterpolatedNames",
|
|
workflow: `
|
|
name: test
|
|
jobs:
|
|
job1:
|
|
name: myname-${{ matrix.typo }}
|
|
strategy:
|
|
matrix:
|
|
version: [1.17, 1.19]
|
|
runs-on: docker
|
|
steps:
|
|
- run: echo OK
|
|
`,
|
|
singleWorkflows: []string{
|
|
`name: test
|
|
jobs:
|
|
job1:
|
|
name: myname-
|
|
runs-on: docker
|
|
steps:
|
|
- run: echo OK
|
|
strategy:
|
|
matrix:
|
|
version:
|
|
- 1.17
|
|
`,
|
|
`name: test
|
|
jobs:
|
|
job1:
|
|
name: myname--1
|
|
runs-on: docker
|
|
steps:
|
|
- run: echo OK
|
|
strategy:
|
|
matrix:
|
|
version:
|
|
- 1.19
|
|
`,
|
|
},
|
|
},
|
|
} {
|
|
t.Run(testCase.name, func(t *testing.T) {
|
|
sw, err := jobParser([]byte(testCase.workflow))
|
|
require.NoError(t, err)
|
|
for i, sw := range sw {
|
|
actual, err := sw.Marshal()
|
|
require.NoError(t, err)
|
|
assert.Equal(t, testCase.singleWorkflows[i], string(actual))
|
|
}
|
|
})
|
|
}
|
|
}
|