Add respect_gitignore input to action.yml and update related logic in entrypoint.sh, check.go, and fsurls.go to support .gitignore handling during URL collection.

This commit is contained in:
Luke Hagar
2025-09-11 21:02:14 +00:00
parent 9148a9108c
commit f3804fcd2d
4 changed files with 21 additions and 8 deletions

View File

@@ -22,6 +22,10 @@ inputs:
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
@@ -56,6 +60,7 @@ runs:
INPUT_PATTERNS: ${{ inputs.patterns }}
INPUT_CONCURRENCY: ${{ inputs.concurrency }}
INPUT_TIMEOUT: ${{ inputs.timeout }}
INPUT_RESPECT_GITIGNORE: ${{ inputs.respect_gitignore }}
INPUT_JSON_OUT: ${{ inputs.json_out }}
INPUT_MD_OUT: ${{ inputs.md_out }}
INPUT_REPO_BLOB_BASE: ${{ inputs.repo_blob_base }}

View File

@@ -51,7 +51,7 @@ func init() {
cfg := web.Config{MaxConcurrency: maxConcurrency, RequestTimeout: timeout}
// Collect URLs
urlToFiles, err := fsurls.CollectURLs(path, gl)
urlToFiles, err := fsurls.CollectURLs(path, gl, respectGitignore)
if err != nil {
return err
}
@@ -157,13 +157,15 @@ func init() {
checkCmd.Flags().StringVar(&repoBlobBase, "repo-blob-base", "", "override GitHub blob base URL (e.g. https://github.com/owner/repo/blob/<sha>)")
checkCmd.Flags().IntVar(&timeoutSeconds, "timeout", 10, "HTTP request timeout in seconds")
checkCmd.Flags().BoolVar(&failOnFailures, "fail-on-failures", true, "exit non-zero if any links fail")
checkCmd.Flags().BoolVar(&respectGitignore, "respect-gitignore", true, "respect .gitignore while scanning (default true)")
rootCmd.AddCommand(checkCmd)
}
var (
timeoutSeconds int
failOnFailures bool
patterns []string
repoBlobBase string
timeoutSeconds int
failOnFailures bool
patterns []string
repoBlobBase string
respectGitignore bool
)

View File

@@ -5,6 +5,7 @@ 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:-}"
@@ -35,6 +36,11 @@ 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

View File

@@ -28,9 +28,9 @@ var hostnameRegex = regexp.MustCompile(`^(?i)([a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9]
// CollectURLs walks the directory tree rooted at rootPath and collects URLs found in
// text-based files matching any of the provided glob patterns (doublestar ** supported).
// If globs is empty, all files are considered. Respects .gitignore if present.
// If globs is empty, all files are considered. Respects .gitignore if present and respectGitignore=true.
// Returns a map from URL -> sorted unique list of file paths that contained it.
func CollectURLs(rootPath string, globs []string) (map[string][]string, error) {
func CollectURLs(rootPath string, globs []string, respectGitignore bool) (map[string][]string, error) {
if strings.TrimSpace(rootPath) == "" {
rootPath = "."
}
@@ -39,7 +39,7 @@ func CollectURLs(rootPath string, globs []string) (map[string][]string, error) {
st, _ := os.Stat(cleanRoot)
isFileRoot := st != nil && !st.IsDir()
var ign *ignore.GitIgnore
if !isFileRoot {
if !isFileRoot && respectGitignore {
ign = loadGitIgnore(cleanRoot)
}