fix: remove literal ${{ runner.temp }} that breaks action loading (#38)

* fix: remove literal ${{ runner.temp }} from action.yaml

GitHub evaluates all ${{ }} expressions in action.yaml, including inside
input descriptions where the `runner` context is unavailable. The literal
${{ runner.temp }} in the `path` description made the action fail to load
with "Unrecognized named-value: 'runner'", breaking every consumer of
v0.3.0 regardless of whether `path` was set.

Fixes #37

* test: add CI workflow exercising the action

Run the action on ubuntu/windows/macos (defaults, cache, custom path) and
assert that an invalid `path` is rejected. Actually using the action via
`uses: ./` catches load-time errors like #37 that static linters miss.

* test: use Trivy v0.71.0 in CI workflow

v0.68.2 has no release assets, so the install step 404s. v0.71.0 (the version
from #37) downloads correctly.

* test: add positive control to reject-invalid-path job

The job asserted only that the install step failed, so it stayed green even
when the action failed to load entirely (the #37 regression). Add a control
step that installs with a valid path and must succeed, so the job can only
pass when the action loads and then rejects the invalid paths.
This commit is contained in:
DmitriyLewen authored and GitHub committed 2026-06-03 18:03:56 +06:00
1 parent 151a37f29c
commit 81e514348e
3 files changed
+153 -4

No files matched your search

+149
View File
@@ -0,0 +1,149 @@
name: Test
on:
push:
branches:
- main
pull_request:
permissions:
contents: read
jobs:
# Default usage. This job fails to load if action.yaml contains an invalid
# ${{ }} expression (e.g. `runner.temp` in an input description), which is the
# regression guard for https://github.com/aquasecurity/setup-trivy/issues/37.
defaults:
name: Install with defaults (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest
steps:
- name: Checkout
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
- name: Install Trivy
uses: ./
with:
version: v0.71.0
- name: Verify Trivy is installed
shell: bash
run: trivy --version
cache:
name: Install with cache (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest
steps:
- name: Checkout
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
- name: Install Trivy with cache
uses: ./
with:
version: v0.71.0
cache: true
- name: Verify Trivy is installed
shell: bash
run: trivy --version
custom-path:
name: Install to custom path (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest
steps:
- name: Checkout
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
- name: Install Trivy to a custom path
uses: ./
with:
version: v0.71.0
path: ./bins
- name: Verify Trivy is installed
shell: bash
run: trivy --version
# The action must reject a `path` that contains shell variables or "~" so they
# are never silently expanded (regression guard for the validation added in
# https://github.com/aquasecurity/setup-trivy/pull/33). We expect the install
# step to FAIL and assert that explicitly.
#
# The error text printed by the action ("must be a literal path") cannot be
# captured from a `uses:` step — only `outcome` is exposed, not stdout/stderr.
# So a bare `outcome == failure` check would also pass if the action failed for
# an unrelated reason (e.g. the #37 load failure), giving a false green. The
# positive-control step below closes that gap: it installs with a valid path
# and MUST succeed, so the job can only pass when the action actually loads and
# then rejects the invalid paths.
reject-invalid-path:
name: Reject invalid path (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest
steps:
- name: Checkout
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
# Positive control: a valid path must load and succeed. If the action is
# broken (e.g. an invalid expression in action.yaml), this step fails and
# so does the job, preventing a false green from the steps below.
- name: Install Trivy with a valid path (control)
uses: ./
with:
version: v0.71.0
path: ./control-bin
- name: Install Trivy with a shell variable in path
id: invalid-var
continue-on-error: true
uses: ./
with:
version: v0.71.0
path: $HOME/trivy
- name: Install Trivy with a tilde in path
id: invalid-tilde
continue-on-error: true
uses: ./
with:
version: v0.71.0
path: ~/trivy
- name: Assert the action rejected the invalid paths
shell: bash
run: |
if [ "${{ steps.invalid-var.outcome }}" != "failure" ]; then
echo "::error::Expected the action to reject a path with a shell variable, but it succeeded."
exit 1
fi
if [ "${{ steps.invalid-tilde.outcome }}" != "failure" ]; then
echo "::error::Expected the action to reject a path with a tilde, but it succeeded."
exit 1
fi
echo "Action loaded correctly and rejected the invalid paths."
+1 -1
View File
@@ -59,7 +59,7 @@ steps:
> [!IMPORTANT]
> `path` must be a **literal** path. Shell variables (e.g. `$HOME`, `$RUNNER_TEMP`) and `~` are **not** expanded and will fail the action.
> Use a GitHub expression that is resolved before the step runs instead, for example `path: ${{ runner.temp }}/trivy`, or a relative path like `./bins`.
> Use a GitHub expression that is resolved before the step runs instead, or a relative path like `./bins`.
## Install Trivy with non-default token
There are cases when `github.token` (default value for `actions/checkout`) contains an invalid token for `http://github.com`.
+3 -3
View File
@@ -12,8 +12,8 @@ inputs:
Path in runner to install Trivy. Trivy will be installed in "<path>/trivy-bin" dir
("$HOME/.local/bin/trivy-bin" by default).
Must be a literal path: shell variables (e.g. $HOME, $RUNNER_TEMP) and "~" are NOT
expanded. Use a GitHub expression such as ${{ runner.temp }} instead, or a relative
path like "./bins".
expanded. Use a GitHub expression that is resolved before the step runs, or a
relative path like "./bins".
required: false
default: ''
cache:
@@ -56,7 +56,7 @@ runs:
# `$GITHUB_OUTPUT` file (and thus poison the `dir` output).
case "${INPUT_PATH}" in
*'$'* | *'~'*)
echo "::error::The 'path' input must be a literal path. Shell variables (e.g. \$HOME, \$USER) and '~' are not expanded. Use a GitHub expression like \${{ runner.temp }}, a relative path, or leave 'path' empty to use the default (\$HOME/.local/bin)." >&2
echo "::error::The 'path' input must be a literal path. Shell variables (e.g. \$HOME, \$USER) and '~' are not expanded. Use a GitHub expression that is resolved before the step runs, a relative path, or leave 'path' empty to use the default (\$HOME/.local/bin)." >&2
exit 1
;;
*[$'\n\r']*)