Skip to content

Commit d5c1d55

Browse files
committed
do not allow contexts listed in 'Available Contexts' page
following the answer in the forum: https://github.com/orgs/community/discussions/35565
1 parent d3399fe commit d5c1d55

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

expr_sema.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -462,27 +462,27 @@ func (sema *ExprSemanticsChecker) SetContextAvailability(avail []string) {
462462
}
463463

464464
func (sema *ExprSemanticsChecker) checkAvailableContext(n *VariableNode) {
465-
if len(sema.availableContexts) == 0 {
466-
return
467-
}
468-
469465
ctx := strings.ToLower(n.Name)
470466
for _, c := range sema.availableContexts {
471467
if c == ctx {
472468
return
473469
}
474470
}
475471

476-
s := "contexts are"
477-
if len(sema.availableContexts) == 1 {
478-
s = "context is"
472+
var notes string
473+
switch len(sema.availableContexts) {
474+
case 0:
475+
notes = "no context is available here"
476+
case 1:
477+
notes = "available context is " + quotes(sema.availableContexts)
478+
default:
479+
notes = "available contexts are " + quotes(sema.availableContexts)
479480
}
480481
sema.errorf(
481482
n,
482-
"context %q is not allowed here. available %s %s. see https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability for more details",
483+
"context %q is not allowed here. %s. see https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability for more details",
483484
n.Name,
484-
s,
485-
quotes(sema.availableContexts),
485+
notes,
486486
)
487487
}
488488

0 commit comments

Comments
 (0)