1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-09-15 18:57:01 +00:00

fix: tolerate strings for fail-fast, max-parallel, timeout-minutes, cancel-timeout-minutes (#203)

- the model defines them as strings and can parse them either as string or their effective type (boolean, number)
- add workflow validation when reading all testdata
- add fail-fast, max-parallel, timeout-minutes, cancel-timeout-minutes to test workflows in the jobparser tests

Reviewed-on: https://code.forgejo.org/forgejo/act/pulls/203
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Co-authored-by: Earl Warren <contact@earl-warren.org>
Co-committed-by: Earl Warren <contact@earl-warren.org>
This commit is contained in:
Earl Warren 2025-07-27 10:06:07 +00:00 committed by earl-warren
parent 82dea3fdda
commit 57524e90f1
6 changed files with 73 additions and 8 deletions

View file

@ -7,6 +7,8 @@ jobs:
- uses: .gitea/workflows/build.yml - uses: .gitea/workflows/build.yml
with: with:
package: service package: service
timeout-minutes: 20
timeout-minutes: 10
job2: job2:
name: job2 name: job2

View file

@ -7,6 +7,8 @@ jobs:
- uses: .gitea/workflows/build.yml - uses: .gitea/workflows/build.yml
with: with:
package: service package: service
timeout-minutes: "20"
timeout-minutes: "10"
--- ---
name: test name: test
jobs: jobs:

View file

@ -2,6 +2,8 @@ name: test
jobs: jobs:
job1: job1:
strategy: strategy:
fail-fast: true
max-parallel: 5
matrix: matrix:
os: [ubuntu-22.04, ubuntu-20.04] os: [ubuntu-22.04, ubuntu-20.04]
version: [1.17, 1.18, 1.19] version: [1.17, 1.18, 1.19]
@ -10,4 +12,4 @@ jobs:
- uses: actions/setup-go@v3 - uses: actions/setup-go@v3
with: with:
go-version: ${{ matrix.version }} go-version: ${{ matrix.version }}
- run: uname -a && go version - run: uname -a && go version

View file

@ -9,6 +9,8 @@ jobs:
go-version: ${{ matrix.version }} go-version: ${{ matrix.version }}
- run: uname -a && go version - run: uname -a && go version
strategy: strategy:
fail-fast: "true"
max-parallel: "5"
matrix: matrix:
os: os:
- ubuntu-20.04 - ubuntu-20.04
@ -26,6 +28,8 @@ jobs:
go-version: ${{ matrix.version }} go-version: ${{ matrix.version }}
- run: uname -a && go version - run: uname -a && go version
strategy: strategy:
fail-fast: "true"
max-parallel: "5"
matrix: matrix:
os: os:
- ubuntu-20.04 - ubuntu-20.04
@ -43,6 +47,8 @@ jobs:
go-version: ${{ matrix.version }} go-version: ${{ matrix.version }}
- run: uname -a && go version - run: uname -a && go version
strategy: strategy:
fail-fast: "true"
max-parallel: "5"
matrix: matrix:
os: os:
- ubuntu-20.04 - ubuntu-20.04
@ -60,6 +66,8 @@ jobs:
go-version: ${{ matrix.version }} go-version: ${{ matrix.version }}
- run: uname -a && go version - run: uname -a && go version
strategy: strategy:
fail-fast: "true"
max-parallel: "5"
matrix: matrix:
os: os:
- ubuntu-22.04 - ubuntu-22.04
@ -77,6 +85,8 @@ jobs:
go-version: ${{ matrix.version }} go-version: ${{ matrix.version }}
- run: uname -a && go version - run: uname -a && go version
strategy: strategy:
fail-fast: "true"
max-parallel: "5"
matrix: matrix:
os: os:
- ubuntu-22.04 - ubuntu-22.04
@ -94,6 +104,8 @@ jobs:
go-version: ${{ matrix.version }} go-version: ${{ matrix.version }}
- run: uname -a && go version - run: uname -a && go version
strategy: strategy:
fail-fast: "true"
max-parallel: "5"
matrix: matrix:
os: os:
- ubuntu-22.04 - ubuntu-22.04

View file

@ -1,10 +1,13 @@
package jobparser package jobparser
import ( import (
"bytes"
"embed" "embed"
"path/filepath" "path/filepath"
"testing" "testing"
"github.com/nektos/act/pkg/model"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -12,7 +15,11 @@ import (
var testdata embed.FS var testdata embed.FS
func ReadTestdata(t *testing.T, name string) []byte { func ReadTestdata(t *testing.T, name string) []byte {
content, err := testdata.ReadFile(filepath.Join("testdata", name)) t.Helper()
require.NoError(t, err) filename := filepath.Join("testdata", name)
content, err := testdata.ReadFile(filename)
require.NoError(t, err, filename)
_, err = model.ReadWorkflow(bytes.NewReader(content), true)
require.NoError(t, err, filename)
return content return content
} }

View file

@ -1440,10 +1440,10 @@
"required": true "required": true
}, },
"timeout-minutes": { "timeout-minutes": {
"type": "number-strategy-context", "type": "job-timeout-minutes",
"description": "The maximum number of minutes to let a workflow run before GitHub automatically cancels it. Default: 360" "description": "The maximum number of minutes to let a workflow run before GitHub automatically cancels it. Default: 360"
}, },
"cancel-timeout-minutes": "number-strategy-context", "cancel-timeout-minutes": "job-timeout-minutes",
"continue-on-error": { "continue-on-error": {
"type": "boolean-strategy-context", "type": "boolean-strategy-context",
"description": "Prevents a workflow run from failing when a job fails. Set to true to allow a workflow run to pass when this job fails." "description": "Prevents a workflow run from failing when a job fails. Set to true to allow a workflow run to pass when this job fails."
@ -1552,17 +1552,53 @@
"mapping": { "mapping": {
"properties": { "properties": {
"fail-fast": { "fail-fast": {
"type": "boolean", "type": "fail-fast",
"description": "Setting `fail-fast` to `false` prevents GitHub from canceling all in-progress jobs if any matrix job fails. Default: `true`" "description": "Setting `fail-fast` to `false` prevents GitHub from canceling all in-progress jobs if any matrix job fails. Default: `true`"
}, },
"max-parallel": { "max-parallel": {
"type": "number", "type": "max-parallel",
"description": "The maximum number of jobs that can run simultaneously when using a matrix job strategy. By default, GitHub will maximize the number of jobs run in parallel depending on runner availability." "description": "The maximum number of jobs that can run simultaneously when using a matrix job strategy. By default, GitHub will maximize the number of jobs run in parallel depending on runner availability."
}, },
"matrix": "matrix" "matrix": "matrix"
} }
} }
}, },
"fail-fast": {
"context": [
"forge",
"github",
"inputs",
"vars",
"needs",
"strategy",
"matrix",
"secrets",
"steps",
"job",
"runner",
"env",
"hashFiles(1,255)"
],
"one-of": ["boolean", "string"]
},
"max-parallel": {
"context": [
"forge",
"github",
"inputs",
"vars",
"needs",
"strategy",
"matrix",
"secrets",
"steps",
"job",
"runner",
"env",
"hashFiles(1,255)"
],
"one-of": ["number", "string"]
},
"matrix": { "matrix": {
"description": "Use `matrix` to define a matrix of different job configurations. Within your matrix, define one or more variables followed by an array of values.", "description": "Use `matrix` to define a matrix of different job configurations. Within your matrix, define one or more variables followed by an array of values.",
"mapping": { "mapping": {
@ -1895,7 +1931,7 @@
"env", "env",
"hashFiles(1,255)" "hashFiles(1,255)"
], ],
"number": {}, "one-of": ["number", "string"],
"description": "The maximum number of minutes to run the step before killing the process." "description": "The maximum number of minutes to run the step before killing the process."
}, },
"step-with": { "step-with": {
@ -2033,6 +2069,10 @@
"context": ["forge", "github", "inputs", "vars", "needs", "strategy", "matrix"], "context": ["forge", "github", "inputs", "vars", "needs", "strategy", "matrix"],
"string": {} "string": {}
}, },
"job-timeout-minutes": {
"context": ["forge", "github", "inputs", "vars", "needs", "strategy", "matrix"],
"one-of": ["number", "string"]
},
"boolean-steps-context": { "boolean-steps-context": {
"context": [ "context": [
"forge", "forge",