Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions scripts/check-required-contexts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ function localTargetError(uses, fullWf) {
: onBlock && typeof onBlock === "object" ? "workflow_call" in onBlock
: false;
if (!callable) return `'${uses}' does not declare on.workflow_call, so GitHub cannot run it as a reusable workflow`;
// The caller passes with.context, and GitHub refuses an input the called workflow does not
// declare, so the target must declare on.workflow_call.inputs.context as a string input.
const call = onBlock && typeof onBlock === "object" && !Array.isArray(onBlock) ? onBlock.workflow_call : undefined;
const ctxInput = call && typeof call === "object" ? call.inputs?.context : undefined;
if (!ctxInput || typeof ctxInput !== "object" || ctxInput.type !== "string")
return `'${uses}' does not declare on.workflow_call.inputs.context with type: string, so GitHub refuses the caller's with.context`;
return null;
}

Expand Down
31 changes: 23 additions & 8 deletions tests/workflows/squabble_gate_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,27 @@ fresh_local() { # fresh_local <uses> <target on-block, or - for no target file>
fi
}
LOCAL_TARGET='./.github/workflows/ci-gate.yml'
GOOD_CALL=$'on:\n workflow_call:\n inputs:\n context: {type: string}'
fresh_local "$LOCAL_TARGET" "$GOOD_CALL"
assert_rc 0 'status mapping: a separate caller whose local target declares workflow_call with a string context input passes' check_status
fresh_local "$LOCAL_TARGET" $'on:\n workflow_call:\n inputs:\n context: {type: string, required: true}\n workflow_dispatch:'
assert_rc 0 'status mapping: a required string context input beside another trigger passes' check_status
# The caller passes with.context; GitHub refuses an input the called workflow does not declare.
fresh_local "$LOCAL_TARGET" $'on:\n workflow_call:'
assert_rc 0 'status mapping: a separate caller whose local target declares workflow_call passes' check_status
fresh_local "$LOCAL_TARGET" $'on:\n workflow_call:\n inputs:\n context: {type: string}'
assert_rc 0 'status mapping: a local target with workflow_call inputs passes' check_status
assert_rc 1 'status mapping: a local target whose workflow_call declares no inputs fails' check_status
fresh_local "$LOCAL_TARGET" $'on:\n workflow_call:'
check_status >"$WORK/status-msg" 2>&1 || true
assert_rc 0 'status mapping message: names the missing context input' grep -qF 'inputs.context with type: string' "$WORK/status-msg"
fresh_local "$LOCAL_TARGET" 'on: [workflow_call]'
assert_rc 0 'status mapping: a local target with a workflow_call list passes' check_status
assert_rc 1 'status mapping: a workflow_call list (which cannot declare inputs) fails' check_status
fresh_local "$LOCAL_TARGET" 'on: workflow_call'
assert_rc 1 'status mapping: a bare workflow_call string (which cannot declare inputs) fails' check_status
fresh_local "$LOCAL_TARGET" $'on:\n workflow_call:\n inputs:\n other: {type: string}'
assert_rc 1 'status mapping: inputs without context fails' check_status
fresh_local "$LOCAL_TARGET" $'on:\n workflow_call:\n inputs:\n context: {type: number}'
assert_rc 1 'status mapping: a non-string context input fails' check_status
fresh_local "$LOCAL_TARGET" $'on:\n workflow_call:\n inputs:\n context:'
assert_rc 1 'status mapping: a context input with no type fails' check_status
fresh_local "$LOCAL_TARGET" $'on:\n push:'
assert_rc 1 'status mapping: a local target without workflow_call fails' check_status
fresh_local "$LOCAL_TARGET" $'on:\n push:'
Expand All @@ -359,14 +374,14 @@ assert_rc 1 'status mapping: a missing local target file fails' check_status
fresh_local "$LOCAL_TARGET" -
check_status >"$WORK/status-msg" 2>&1 || true
assert_rc 0 'status mapping message: names the missing target file' grep -qF 'names a file that does not exist' "$WORK/status-msg"
fresh_local './.github/workflows/../workflows/ci-gate.yml' $'on:\n workflow_call:'
fresh_local './.github/workflows/../workflows/ci-gate.yml' "$GOOD_CALL"
assert_rc 1 'status mapping: a local target path with .. fails even though the file exists' check_status
fresh_local './.github/workflows/../workflows/ci-gate.yml' $'on:\n workflow_call:'
fresh_local './.github/workflows/../workflows/ci-gate.yml' "$GOOD_CALL"
check_status >"$WORK/status-msg" 2>&1 || true
assert_rc 0 'status mapping message: names the path traversal' grep -qF "contains '..' path traversal" "$WORK/status-msg"
fresh_local '/etc/ci-gate.yml' $'on:\n workflow_call:'
fresh_local '/etc/ci-gate.yml' "$GOOD_CALL"
assert_rc 1 'status mapping: an absolute local target fails' check_status
fresh_local "$LOCAL_TARGET" $'on:\n workflow_call:'
fresh_local "$LOCAL_TARGET" "$GOOD_CALL"
sed -i 's|^ uses: .*| uses: ./.github/workflows/ci-gate.yml|' "$status_tree/.github/workflows/gate-caller.yml"
printf ' other:\n uses: ./../outside/ci-gate.yml\n with: {context: "CI/gate"}\n' >> "$status_tree/.github/workflows/gate-caller.yml"
assert_rc 1 'status mapping: a second, bad local job fails beside a valid local job' check_status
Expand Down
Loading