Refactor action inputs and entrypoint script to use 'targets' instead of 'path' and 'patterns'. Update README to reflect new input structure and provide examples for target usage. This change enhances flexibility in specifying scan targets.

This commit is contained in:
Luke Hagar
2025-09-19 16:49:45 +00:00
parent a3c7a2adf2
commit 993579a389
3 changed files with 74 additions and 80 deletions

View File

@@ -21,12 +21,13 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Run Slinky - name: Run Slinky
uses: LukeHagar/slinky@v1 uses: LukeHagar/slinky@v1
with:
targets: "docs/,README.md,**/*.md"
``` ```
### Inputs ### Inputs
- **path**: Root path to scan. Default: `.` - **targets**: Comma-separated paths and patterns to scan. Can be directories, files, or glob patterns (e.g. `docs/,api-specs/**/*.yaml,README.md`). Default: `**/*`
- **patterns**: Comma-separated doublestar patterns (e.g. `docs/**/*.md,**/*.go`). Default: `**/*`
- **concurrency**: Max concurrent requests. Default: `16` - **concurrency**: Max concurrent requests. Default: `16`
- **timeout**: HTTP timeout seconds. Default: `10` - **timeout**: HTTP timeout seconds. Default: `10`
- **json-out**: Optional JSON results path. Default: `results.json` - **json-out**: Optional JSON results path. Default: `results.json`
@@ -62,7 +63,6 @@ slinky run **/*
Notes: Notes:
- Targets can be files, directories, or doublestar globs. Multiple targets are allowed. - Targets can be files, directories, or doublestar globs. Multiple targets are allowed.
- If no targets are provided, the default is `**/*` relative to the current working directory. - If no targets are provided, the default is `**/*` relative to the current working directory.
- Legacy flags `--glob` and `--patterns` are still supported, but positional targets are preferred.
### Notes ### Notes

View File

@@ -6,58 +6,44 @@ branding:
color: "blue" color: "blue"
inputs: inputs:
path: targets:
description: "Root path to scan" description: "Comma-separated paths and patterns to scan. Can be directories, files, or glob patterns. Ex: docs/,api-specs/**/*.yaml,README.md"
required: false
default: "."
patterns:
description: "Comma-separated doublestar patterns. Ex: docs/**/*.md,**/*.go; default **/*"
required: false required: false
default: "**/*" default: "**/*"
concurrency: concurrency:
description: "Maximum concurrent requests" description: "Maximum concurrent requests"
required: false required: false
default: "16"
timeout: timeout:
description: "HTTP timeout seconds" description: "HTTP timeout seconds"
required: false required: false
default: "10"
respect_gitignore: respect_gitignore:
description: "Respect .gitignore while scanning" description: "Respect .gitignore while scanning"
required: false required: false
default: "true"
json_out: json_out:
description: "Optional path to write JSON results" description: "Optional path to write JSON results"
required: false required: false
default: "results.json"
md_out: md_out:
description: "Optional path to write Markdown report for PR comment" description: "Optional path to write Markdown report for PR comment"
required: false required: false
default: "results.md"
repo_blob_base: repo_blob_base:
description: "Override GitHub blob base URL (https://github.com/<owner>/<repo>/blob/<sha>)" description: "Override GitHub blob base URL (https://github.com/<owner>/<repo>/blob/<sha>)"
required: false required: false
default: ""
fail_on_failures: fail_on_failures:
description: "Fail the job if any links fail" description: "Fail the job if any links fail"
required: false required: false
default: "true"
comment_pr: comment_pr:
description: "If running on a PR, post a comment with the report" description: "If running on a PR, post a comment with the report"
required: false required: false
default: "true"
step_summary: step_summary:
description: "Append the report to the GitHub Step Summary" description: "Append the report to the GitHub Step Summary"
required: false required: false
default: "true"
runs: runs:
using: "docker" using: "docker"
image: "docker://ghcr.io/lukehagar/slinky:v1" image: "docker://ghcr.io/lukehagar/slinky:v1"
args: [] args: []
env: env:
INPUT_PATH: ${{ inputs.path }} INPUT_TARGETS: ${{ inputs.targets }}
INPUT_PATTERNS: ${{ inputs.patterns }}
INPUT_CONCURRENCY: ${{ inputs.concurrency }} INPUT_CONCURRENCY: ${{ inputs.concurrency }}
INPUT_TIMEOUT: ${{ inputs.timeout }} INPUT_TIMEOUT: ${{ inputs.timeout }}
INPUT_RESPECT_GITIGNORE: ${{ inputs.respect_gitignore }} INPUT_RESPECT_GITIGNORE: ${{ inputs.respect_gitignore }}

View File

@@ -1,47 +1,9 @@
#!/bin/sh #!/bin/sh
set -eu set -eu
PATH_ARG="${INPUT_PATH:-.}" # Set up environment variables for GitHub blob base URL
PATTERNS_ARG="${INPUT_PATTERNS:-**/*}" if [ -n "${INPUT_REPO_BLOB_BASE:-}" ]; then
CONCURRENCY_ARG="${INPUT_CONCURRENCY:-16}" export SLINKY_REPO_BLOB_BASE_URL="${INPUT_REPO_BLOB_BASE}"
TIMEOUT_ARG="${INPUT_TIMEOUT:-10}"
RESPECT_GITIGNORE_ARG="${INPUT_RESPECT_GITIGNORE:-true}"
JSON_OUT_ARG="${INPUT_JSON_OUT:-results.json}"
MD_OUT_ARG="${INPUT_MD_OUT:-results.md}"
REPO_BLOB_BASE_ARG="${INPUT_REPO_BLOB_BASE:-}"
FAIL_ON_FAILURES_ARG="${INPUT_FAIL_ON_FAILURES:-true}"
COMMENT_PR_ARG="${INPUT_COMMENT_PR:-true}"
STEP_SUMMARY_ARG="${INPUT_STEP_SUMMARY:-true}"
# Build argv safely
set -- check --concurrency "$CONCURRENCY_ARG" --timeout "$TIMEOUT_ARG"
if [ "${FAIL_ON_FAILURES_ARG}" = "true" ]; then
set -- "$@" --fail-on-failures=true
else
set -- "$@" --fail-on-failures=false
fi
if [ -n "${PATTERNS_ARG}" ]; then
set -- "$@" "$PATTERNS_ARG"
else
set -- "$@" "**/*"
fi
if [ -n "${JSON_OUT_ARG}" ]; then
set -- "$@" --json-out "$JSON_OUT_ARG"
fi
if [ -n "${MD_OUT_ARG}" ]; then
set -- "$@" --md-out "$MD_OUT_ARG"
fi
if [ "${RESPECT_GITIGNORE_ARG}" = "true" ]; then
set -- "$@" --respect-gitignore=true
else
set -- "$@" --respect-gitignore=false
fi
# Compute GitHub blob base URL for file links used in the Markdown report
if [ -n "${REPO_BLOB_BASE_ARG}" ]; then
export SLINKY_REPO_BLOB_BASE_URL="${REPO_BLOB_BASE_ARG}"
elif [ -n "${GITHUB_REPOSITORY:-}" ]; then elif [ -n "${GITHUB_REPOSITORY:-}" ]; then
COMMIT_SHA="${GITHUB_SHA:-}" COMMIT_SHA="${GITHUB_SHA:-}"
if [ -n "${GITHUB_EVENT_PATH:-}" ] && command -v jq >/dev/null 2>&1; then if [ -n "${GITHUB_EVENT_PATH:-}" ] && command -v jq >/dev/null 2>&1; then
@@ -55,36 +17,82 @@ elif [ -n "${GITHUB_REPOSITORY:-}" ]; then
fi fi
fi fi
# Emit consolidated config at start (visible with ACTIONS_STEP_DEBUG=true) # Build command arguments
EFFECTIVE_REPO_BLOB_BASE="${SLINKY_REPO_BLOB_BASE_URL:-$REPO_BLOB_BASE_ARG}" set -- check
TARGETS_DEBUG="${PATTERNS_ARG:-**/*}"
printf "::debug:: Config: targets=%s concurrency=%s timeout=%s respect_gitignore=%s json_out=%s md_out=%s fail_on_failures=%s comment_pr=%s step_summary=%s repo_blob_base_url=%s\n" \
"$TARGETS_DEBUG" "$CONCURRENCY_ARG" "$TIMEOUT_ARG" "$RESPECT_GITIGNORE_ARG" "$JSON_OUT_ARG" "$MD_OUT_ARG" \
"$FAIL_ON_FAILURES_ARG" "$COMMENT_PR_ARG" "$STEP_SUMMARY_ARG" "$EFFECTIVE_REPO_BLOB_BASE"
printf "::debug:: CLI Args: slinky %s\n" "$*"
# Execute but always continue to allow summaries/comments even on failure # Add optional flags
if [ -n "${INPUT_CONCURRENCY:-}" ]; then
set -- "$@" --concurrency "${INPUT_CONCURRENCY}"
fi
if [ -n "${INPUT_TIMEOUT:-}" ]; then
set -- "$@" --timeout "${INPUT_TIMEOUT}"
fi
if [ -n "${INPUT_JSON_OUT:-}" ]; then
set -- "$@" --json-out "${INPUT_JSON_OUT}"
fi
if [ -n "${INPUT_MD_OUT:-}" ]; then
set -- "$@" --md-out "${INPUT_MD_OUT}"
fi
if [ -n "${INPUT_REPO_BLOB_BASE:-}" ]; then
set -- "$@" --repo-blob-base "${INPUT_REPO_BLOB_BASE}"
fi
if [ "${INPUT_FAIL_ON_FAILURES:-true}" = "true" ]; then
set -- "$@" --fail-on-failures=true
else
set -- "$@" --fail-on-failures=false
fi
if [ "${INPUT_RESPECT_GITIGNORE:-true}" = "true" ]; then
set -- "$@" --respect-gitignore=true
else
set -- "$@" --respect-gitignore=false
fi
# Add targets
if [ -n "${INPUT_TARGETS:-}" ]; then
# Split comma-separated targets and add each one
IFS=','
for target in $INPUT_TARGETS; do
target=$(echo "$target" | xargs) # trim whitespace
if [ -n "$target" ]; then
set -- "$@" "$target"
fi
done
unset IFS
else
# Default: scan everything
set -- "$@" "**/*"
fi
# Debug output
if [ "${ACTIONS_STEP_DEBUG:-}" = "true" ]; then
printf "::debug:: CLI Args: slinky %s\n" "$*"
fi
# Execute the command
set +e set +e
slinky "$@" slinky "$@"
SLINKY_EXIT_CODE=$? SLINKY_EXIT_CODE=$?
set -e set -e
# Expose outputs (use underscore names) # Expose outputs
if [ -n "${GITHUB_OUTPUT:-}" ]; then if [ -n "${GITHUB_OUTPUT:-}" ]; then
if [ -n "${JSON_OUT_ARG}" ]; then if [ -n "${INPUT_JSON_OUT:-}" ]; then
echo "json_path=${JSON_OUT_ARG}" >> "$GITHUB_OUTPUT" echo "json_path=${INPUT_JSON_OUT}" >> "$GITHUB_OUTPUT"
fi fi
if [ -n "${MD_OUT_ARG}" ]; then if [ -n "${INPUT_MD_OUT:-}" ]; then
echo "md_path=${MD_OUT_ARG}" >> "$GITHUB_OUTPUT" echo "md_path=${INPUT_MD_OUT}" >> "$GITHUB_OUTPUT"
fi fi
fi fi
# Append report to job summary if requested # Append report to job summary if requested
if [ "${STEP_SUMMARY_ARG}" = "true" ] && [ -n "${GITHUB_STEP_SUMMARY:-}" ] && [ -n "${MD_OUT_ARG}" ] && [ -f "${MD_OUT_ARG}" ]; then if [ "${INPUT_STEP_SUMMARY:-true}" = "true" ] && [ -n "${GITHUB_STEP_SUMMARY:-}" ] && [ -n "${INPUT_MD_OUT:-}" ] && [ -f "${INPUT_MD_OUT}" ]; then
cat "${MD_OUT_ARG}" >> "$GITHUB_STEP_SUMMARY" cat "${INPUT_MD_OUT}" >> "$GITHUB_STEP_SUMMARY"
fi fi
# PR comment handling is now done in the CLI itself when running on a PR
exit ${SLINKY_EXIT_CODE:-0} exit ${SLINKY_EXIT_CODE:-0}