Files
swift-nio/.github/workflows/static_sdk.yml
T
Rick Newton-Rogers b31565862a Pass inputs through env vars (#3549)
Pass workflow inputs through environment variables instead of inline
template expansion

### Motivation

* `${{ inputs.* }}` expressions used directly in `run:` blocks are
expanded by GitHub Actions before the shell runs, which can allow code
injection via template expansion (see
https://docs.zizmor.sh/audits/#template-injection).

### Modifications

* Move `${{ inputs.* }}` and `${{ matrix.config.* }}` references out of
`run:` blocks and into step-level `env:` blocks across 13 workflow
files.

### Result

* All high-confidence `template-injection` findings from `zizmor` are
resolved.
* No changes should be required in downstream caller workflows

This can be seen successfully in use via test commits here:
- https://github.com/apple/swift-nio/actions/runs/23000641572?pr=3549
- https://github.com/apple/swift-log/actions/runs/23001027416?pr=427
- https://github.com/grpc/grpc-swift-2/actions/runs/23001010064?pr=43
2026-03-12 12:57:22 +00:00

81 lines
3.3 KiB
YAML

name: Static SDK
permissions:
contents: read
on:
workflow_call:
inputs:
env_vars:
type: string
description: "Environment variables for jobs as JSON (e.g., '{\"DEBUG\":\"1\",\"LOG_LEVEL\":\"info\"}')."
default: "{}"
command_arguments:
type: string
description: "The arguments passed to swift build. Defaults to '--swift-sdk x86_64-swift-linux-musl'."
default: "--swift-sdk x86_64-swift-linux-musl"
jobs:
construct-matrix:
name: Construct Static SDK matrix
runs-on: ubuntu-latest
outputs:
static-sdk-matrix: '${{ steps.generate-matrix.outputs.static-sdk-matrix }}'
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- id: generate-matrix
run: |
# Validate and use JSON environment variables directly
env_vars_json="$INPUT_ENV_VARS"
# Validate JSON format
if ! echo "$env_vars_json" | jq empty 2>/dev/null; then
echo "Error: env_vars is not valid JSON"
exit 1
fi
# Generate matrix with parsed environment variables
cat >> "$GITHUB_OUTPUT" << EOM
static-sdk-matrix=$(echo '{
"config":[
{
"name":"latest-release Jammy",
"swift_version":"latest-release",
"platform":"Linux",
"runner":"ubuntu-latest",
"image":"ubuntu:jammy",
"setup_command":"apt update -q && apt install -y -q curl jq tar && curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/install_swift_prerequisites.sh | bash && curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/install_swift_sdk.sh | INSTALL_SWIFT_VERSION=latest INSTALL_SWIFT_ARCH=x86_64 bash && hash -r",
"command":"swift build",
"command_arguments":"--swift-sdks-path /tmp/swiftsdks '"$INPUT_COMMAND_ARGUMENTS"'",
"env":'"$env_vars_json"'
},
{
"name":"main Jammy",
"swift_version":"main",
"platform":"Linux",
"runner":"ubuntu-latest",
"image":"ubuntu:jammy",
"setup_command":"apt update -q && apt install -y -q curl jq tar && curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/install_swift_prerequisites.sh | bash && curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/install_swift_sdk.sh | INSTALL_SWIFT_BRANCH=main INSTALL_SWIFT_ARCH=x86_64 bash && hash -r",
"command":"swift build",
"command_arguments":"--swift-sdks-path /tmp/swiftsdks '"$INPUT_COMMAND_ARGUMENTS"'",
"env":'"$env_vars_json"'
}
]
}' | jq -c)
EOM
env:
INPUT_ENV_VARS: ${{ inputs.env_vars }}
INPUT_COMMAND_ARGUMENTS: ${{ inputs.command_arguments }}
static-sdk:
name: Static SDK
needs: construct-matrix
# Workaround https://github.com/nektos/act/issues/1875
uses: apple/swift-nio/.github/workflows/swift_test_matrix.yml@main
with:
name: "Static SDK"
matrix_string: '${{ needs.construct-matrix.outputs.static-sdk-matrix }}'