Skip to content

Commit b96989f

Browse files
committed
fix tests and add test cases with no available contexts are allowed
1 parent d5c1d55 commit b96989f

10 files changed

+37
-12
lines changed

expr_sema_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,7 @@ func TestExprSemanticsCheckOK(t *testing.T) {
754754
}
755755

756756
c := NewExprSemanticsChecker(false, nil)
757+
c.SetContextAvailability([]string{"github", "job", "jobs", "matrix", "steps", "needs", "env", "inputs", "secrets", "vars", "runner"})
757758
if tc.funcs != nil {
758759
c.funcs = tc.funcs
759760
}
@@ -1210,6 +1211,14 @@ func TestExprSemanticsCheckError(t *testing.T) {
12101211
},
12111212
availCtx: []string{"env", "matrix"},
12121213
},
1214+
{
1215+
what: "no available context",
1216+
input: "github",
1217+
expected: []string{
1218+
"context \"github\" is not allowed here. no context is available",
1219+
},
1220+
availCtx: []string{},
1221+
},
12131222
{
12141223
what: "no special function allowed",
12151224
input: "success()",
@@ -1301,6 +1310,8 @@ func TestExprSemanticsCheckError(t *testing.T) {
13011310
}
13021311
if tc.availCtx != nil {
13031312
c.SetContextAvailability(tc.availCtx)
1313+
} else {
1314+
c.SetContextAvailability([]string{"github", "job", "jobs", "matrix", "steps", "needs", "env", "inputs", "secrets", "vars", "runner"})
13041315
}
13051316
if tc.availSP != nil {
13061317
c.SetSpecialFunctionAvailability(tc.availSP)
@@ -1496,6 +1507,16 @@ func TestExprCompareOperandsCheck(t *testing.T) {
14961507
},
14971508
"any": AnyType{},
14981509
}
1510+
c.SetContextAvailability([]string{
1511+
"any",
1512+
"number",
1513+
"string",
1514+
"bool",
1515+
"null",
1516+
"object",
1517+
"array",
1518+
"array_2d",
1519+
})
14991520

15001521
ty, errs := c.Check(e)
15011522
if ok {

testdata/err/context_availability.out

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/test\.yaml:3:34: context "env" is not allowed here\. .+ \[expression\]/
1+
/test\.yaml:3:35: context "env" is not allowed here\. .+ \[expression\]/
22
/test\.yaml:10:12: context "env" is not allowed here\. .+ \[expression\]/
33
/test\.yaml:15:32: context "env" is not allowed here\. .+ \[expression\]/
44
/test\.yaml:25:22: context "env" is not allowed here\. .+ \[expression\]/
@@ -17,6 +17,7 @@
1717
/test\.yaml:106:18: context "runner" is not allowed here\. .+ \[expression\]/
1818
/test\.yaml:111:20: context "env" is not allowed here\. .+ \[expression\]/
1919
/test\.yaml:115:25: context "runner" is not allowed here\. .+ \[expression\]/
20+
/test\.yaml:121:23: context "runner" is not allowed here\. .+ \[expression\]/
2021
/test\.yaml:127:17: context "env" is not allowed here\. .+ \[expression\]/
2122
/test\.yaml:134:23: context "env" is not allowed here\. .+ \[expression\]/
2223
/test\.yaml:139:23: context "env" is not allowed here\. .+ \[expression\]/
@@ -31,3 +32,4 @@
3132
/test\.yaml:208:19: context "runner" is not allowed here\. .+ \[expression\]/
3233
/test\.yaml:210:18: context "runner" is not allowed here\. .+ \[expression\]/
3334
/test\.yaml:217:34: context "env" is not allowed here\. .+ \[expression\]/
35+
/test\.yaml:221:17: context "inputs" is not allowed here\. no context is available here\. .+ \[expression\]/

testdata/err/context_availability.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# run-name
22
# ERROR at env
3-
run-name: ${{ github.actor}} ${{ env.GITHUB_ACTOR }}
3+
run-name: ${{ github.actor }} ${{ env.GITHUB_ACTOR }}
44

55
# env
66
env:
@@ -117,7 +117,7 @@ jobs:
117117
password: ${{ env.MY_PASSWORD }}
118118
# jobs.<job_id>.services.<service_id>.env.<env_id>
119119
env:
120-
# OK
120+
# ERROR
121121
RUNNER: ${{ runner.name }}
122122
# jobs.<job_id>.strategy
123123
strategy:
@@ -217,3 +217,5 @@ jobs:
217217
services: ${{ inputs.bool || env.FOO }}
218218
steps:
219219
- run: echo
220+
# ERROR at env because `id` allow no context
221+
id: ${{ inputs.foo }}

testdata/err/env_context_banned.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- uses: test/my-action@main
2222
env:
2323
OS: ${{ runner.os }}
24-
id: foo-${{ runner.name }}
24+
NAME: ${{ runner.name }}
2525
container-job:
2626
runs-on: ubuntu-latest
2727
container:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/test\.yaml:12:24: property "calling_workflow_secret" is not defined in object type {.+} \[expression\]/
1+
/test\.yaml:12:23: property "calling_workflow_secret" is not defined in object type {.+} \[expression\]/

testdata/err/reusable_workflow_empty_secrets.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ jobs:
99
steps:
1010
- name: Use a repo or org secret from the calling workflow.
1111
# So referring this secret causes an error
12-
uses: echo ${{ secrets.CALLING_WORKFLOW_SECRET }}
12+
run: echo ${{ secrets.CALLING_WORKFLOW_SECRET }}

testdata/ok/dynamic_shell_name.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ on: push
22

33
defaults:
44
run:
5-
shell: ${{ env.SHELL }}
5+
shell: ${{ 'sh {0}' }}
66

77
jobs:
88
test:
99
runs-on: ubuntu-latest
1010
defaults:
1111
run:
12-
shell: ${{ env.SHELL }}
12+
shell: ${{ 'sh {0}' }}
1313
steps:
1414
- run: echo hi
15-
shell: ${{ env.SHELL }}
15+
shell: ${{ 'sh {0}' }}

testdata/ok/issue-101.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ jobs:
44
test:
55
runs-on: ubuntu-latest
66
steps:
7-
- uses: echo ${{ runner.arch }}
7+
- run: echo ${{ runner.arch }}

testdata/ok/reusable_workflow_inherit_secrets.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ jobs:
77
steps:
88
# The CALLING_WORKFLOW_SECRET secret is passed with `secrets: inherit`
99
- name: Use a repo or org secret from the calling workflow.
10-
uses: echo ${{ secrets.CALLING_WORKFLOW_SECRET }}
10+
run: echo ${{ secrets.CALLING_WORKFLOW_SECRET }}

testdata/ok/workflow_call_job.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ jobs:
2727
permissions: read-all
2828
call6:
2929
# Edge case. Give up checking format.
30-
uses: ${{ runner.name }}
30+
uses: ${{ 'oooops' }}

0 commit comments

Comments
 (0)