mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-10-05 19:30:59 +00:00
chore: test: exercise contexts in matrix when validating workflows (#1033)
After realizing my mistake on my proposed fixes in #1028, I figured I could at least propose another test covering the use of contexts in `jobs.<job-id>.strategy.matrix`. The specification for available contexts is [here](https://docs.github.com/en/actions/reference/workflows-and-actions/contexts#context-availability): | Workflow key | Context | | -------------------- | ----------- | | `jobs.<job_id>.strategy` | `github`, `needs`, `vars`, `inputs` | In Forgejo, the `forge` and `forgejo` contexts are supported in addition to `github`. The new test covers a matrix with [`include`](https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#jobsjob_idstrategymatrixinclude), [`exclude`](https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#jobsjob_idstrategymatrixexclude) and custom properties. Both available and unavailable contexts are tested. <!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - other - [PR](https://code.forgejo.org/forgejo/runner/pulls/1033): <!--number 1033 --><!--line 0 --><!--description Y2hvcmU6IHRlc3Q6IGV4ZXJjaXNlIGNvbnRleHRzIGluIG1hdHJpeCB3aGVuIHZhbGlkYXRpbmcgd29ya2Zsb3dz-->chore: test: exercise contexts in matrix when validating workflows<!--description--> <!--end release-notes-assistant--> Co-authored-by: 2franix <code@c.defx.fr> Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1033 Reviewed-by: earl-warren <earl-warren@noreply.code.forgejo.org> Co-authored-by: 2franix <2franix@noreply.code.forgejo.org> Co-committed-by: 2franix <2franix@noreply.code.forgejo.org>
This commit is contained in:
parent
46a955d1ff
commit
ea824bde1c
1 changed files with 78 additions and 0 deletions
|
@ -30,6 +30,84 @@ jobs:
|
|||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestContextsInWorkflowMatrix(t *testing.T) {
|
||||
t.Run("KnownContexts", func(t *testing.T) {
|
||||
// Parse raw YAML snippet.
|
||||
var node yaml.Node
|
||||
err := yaml.Unmarshal([]byte(`
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
job:
|
||||
uses: ./.forgejo/workflow/test.yaml
|
||||
strategy:
|
||||
matrix:
|
||||
input1:
|
||||
- ${{ forge.KEY }}
|
||||
- ${{ forgejo.KEY }}
|
||||
- ${{ github.KEY }}
|
||||
- ${{ inputs.KEY }}
|
||||
- ${{ vars.KEY }}
|
||||
- ${{ needs.KEY }}
|
||||
include:
|
||||
- forge: ${{ forge.KEY }}
|
||||
- forgejo: ${{ forgejo.KEY }}
|
||||
- github: ${{ github.KEY }}
|
||||
- inputs: ${{ inputs.KEY }}
|
||||
- vars: ${{ vars.KEY }}
|
||||
- needs: ${{ needs.KEY }}
|
||||
exclude:
|
||||
- forge: ${{ forge.KEY }}
|
||||
- forgejo: ${{ forgejo.KEY }}
|
||||
- github: ${{ github.KEY }}
|
||||
- inputs: ${{ inputs.KEY }}
|
||||
- vars: ${{ vars.KEY }}
|
||||
- needs: ${{ needs.KEY }}
|
||||
`), &node)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
// Parse YAML node as a validated workflow.
|
||||
err = (&Node{
|
||||
Definition: "workflow-root",
|
||||
Schema: GetWorkflowSchema(),
|
||||
}).UnmarshalYAML(&node)
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("UnknownContext", func(t *testing.T) {
|
||||
for _, property := range []string{"include", "exclude", "input1"} {
|
||||
t.Run(property, func(t *testing.T) {
|
||||
for _, context := range []string{"secrets", "job", "steps", "runner", "matrix", "strategy"} {
|
||||
t.Run(context, func(t *testing.T) {
|
||||
var node yaml.Node
|
||||
err := yaml.Unmarshal([]byte(fmt.Sprintf(`
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
job:
|
||||
uses: ./.forgejo/workflow/test.yaml
|
||||
strategy:
|
||||
matrix:
|
||||
%[1]s:
|
||||
- input1: ${{ %[2]s.KEY }}
|
||||
`, property, context)), &node)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
err = (&Node{
|
||||
Definition: "workflow-root",
|
||||
Schema: GetWorkflowSchema(),
|
||||
}).UnmarshalYAML(&node)
|
||||
assert.ErrorContains(t, err, "Unknown Variable Access "+context)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestReusableWorkflow(t *testing.T) {
|
||||
t.Run("KnownContexts", func(t *testing.T) {
|
||||
var node yaml.Node
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue