diff --git a/README.md b/README.md index 316649d..240b67f 100644 --- a/README.md +++ b/README.md @@ -21,12 +21,13 @@ jobs: - uses: actions/checkout@v4 - name: Run Slinky uses: LukeHagar/slinky@v1 + with: + targets: "docs/,README.md,**/*.md" ``` ### Inputs -- **path**: Root path to scan. Default: `.` -- **patterns**: Comma-separated doublestar patterns (e.g. `docs/**/*.md,**/*.go`). 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: `**/*` - **concurrency**: Max concurrent requests. Default: `16` - **timeout**: HTTP timeout seconds. Default: `10` - **json-out**: Optional JSON results path. Default: `results.json` @@ -62,7 +63,6 @@ slinky run **/* Notes: - 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. -- Legacy flags `--glob` and `--patterns` are still supported, but positional targets are preferred. ### Notes diff --git a/action.yml b/action.yml index 344ebe2..7cb9a81 100644 --- a/action.yml +++ b/action.yml @@ -6,58 +6,44 @@ branding: color: "blue" inputs: - path: - description: "Root path to scan" - required: false - default: "." - patterns: - description: "Comma-separated doublestar patterns. Ex: docs/**/*.md,**/*.go; default **/*" + targets: + 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: "**/*" concurrency: description: "Maximum concurrent requests" required: false - default: "16" timeout: description: "HTTP timeout seconds" required: false - default: "10" respect_gitignore: description: "Respect .gitignore while scanning" required: false - default: "true" json_out: description: "Optional path to write JSON results" required: false - default: "results.json" md_out: description: "Optional path to write Markdown report for PR comment" required: false - default: "results.md" repo_blob_base: description: "Override GitHub blob base URL (https://github.com///blob/)" required: false - default: "" fail_on_failures: description: "Fail the job if any links fail" required: false - default: "true" comment_pr: description: "If running on a PR, post a comment with the report" required: false - default: "true" step_summary: description: "Append the report to the GitHub Step Summary" required: false - default: "true" runs: using: "docker" image: "docker://ghcr.io/lukehagar/slinky:v1" args: [] env: - INPUT_PATH: ${{ inputs.path }} - INPUT_PATTERNS: ${{ inputs.patterns }} + INPUT_TARGETS: ${{ inputs.targets }} INPUT_CONCURRENCY: ${{ inputs.concurrency }} INPUT_TIMEOUT: ${{ inputs.timeout }} INPUT_RESPECT_GITIGNORE: ${{ inputs.respect_gitignore }} diff --git a/entrypoint.sh b/entrypoint.sh index 72aefaa..95cfd4f 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,47 +1,9 @@ #!/bin/sh set -eu -PATH_ARG="${INPUT_PATH:-.}" -PATTERNS_ARG="${INPUT_PATTERNS:-**/*}" -CONCURRENCY_ARG="${INPUT_CONCURRENCY:-16}" -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}" +# Set up environment variables for GitHub blob base URL +if [ -n "${INPUT_REPO_BLOB_BASE:-}" ]; then + export SLINKY_REPO_BLOB_BASE_URL="${INPUT_REPO_BLOB_BASE}" elif [ -n "${GITHUB_REPOSITORY:-}" ]; then COMMIT_SHA="${GITHUB_SHA:-}" if [ -n "${GITHUB_EVENT_PATH:-}" ] && command -v jq >/dev/null 2>&1; then @@ -55,36 +17,82 @@ elif [ -n "${GITHUB_REPOSITORY:-}" ]; then fi fi -# Emit consolidated config at start (visible with ACTIONS_STEP_DEBUG=true) -EFFECTIVE_REPO_BLOB_BASE="${SLINKY_REPO_BLOB_BASE_URL:-$REPO_BLOB_BASE_ARG}" -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" "$*" +# Build command arguments +set -- check -# 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 slinky "$@" SLINKY_EXIT_CODE=$? set -e -# Expose outputs (use underscore names) +# Expose outputs if [ -n "${GITHUB_OUTPUT:-}" ]; then - if [ -n "${JSON_OUT_ARG}" ]; then - echo "json_path=${JSON_OUT_ARG}" >> "$GITHUB_OUTPUT" + if [ -n "${INPUT_JSON_OUT:-}" ]; then + echo "json_path=${INPUT_JSON_OUT}" >> "$GITHUB_OUTPUT" fi - if [ -n "${MD_OUT_ARG}" ]; then - echo "md_path=${MD_OUT_ARG}" >> "$GITHUB_OUTPUT" + if [ -n "${INPUT_MD_OUT:-}" ]; then + echo "md_path=${INPUT_MD_OUT}" >> "$GITHUB_OUTPUT" fi fi # 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 - cat "${MD_OUT_ARG}" >> "$GITHUB_STEP_SUMMARY" +if [ "${INPUT_STEP_SUMMARY:-true}" = "true" ] && [ -n "${GITHUB_STEP_SUMMARY:-}" ] && [ -n "${INPUT_MD_OUT:-}" ] && [ -f "${INPUT_MD_OUT}" ]; then + cat "${INPUT_MD_OUT}" >> "$GITHUB_STEP_SUMMARY" 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} \ No newline at end of file