From 15d5b249c7bfdbbdfecd5c3f4fe7722609cdfa17 Mon Sep 17 00:00:00 2001 From: GErP83 Date: Thu, 21 May 2026 16:53:52 +0200 Subject: [PATCH 1/2] fix scripts to also check untracked files --- README.md | 10 ++++++---- scripts/check-local-swift-dependencies.sh | 10 +++++----- scripts/check-swift-headers.sh | 2 +- scripts/run-actionlint.sh | 21 +++++++++++++++++---- scripts/run-swift-format.sh | 4 ++-- scripts/script-format.sh | 2 +- 6 files changed, 32 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index cc1902c..7627c5f 100644 --- a/README.md +++ b/README.md @@ -235,7 +235,7 @@ Prevents accidental usage of local Swift package dependencies. #### Behavior -* Scans git-tracked `Package.swift` files only (ignores untracked files) +* Scans tracked and untracked `Package.swift` files (excluding ignored files) * Detects `.package(path:)` * Fails immediately on detection @@ -345,7 +345,7 @@ Ensures Swift source files contain a consistent, standardized header. * Enforces a strict 5-line header format * Can optionally insert or update headers in-place -* Processes only git-tracked Swift files +* Processes tracked and untracked Swift files (excluding ignored files) * Skips `Package.swift` explicitly * Accepts `Created by ... on YYYY. MM. DD.` and legacy `..` suffix * In `--fix` mode, normalizes legacy `..` to `.` @@ -640,6 +640,7 @@ Runs `swift-format` to lint or format Swift source files. #### Behavior +* Scans tracked and untracked Swift files (`--exclude-standard`), not only tracked files * Downloads default configuration if missing * Respects ignore rules * Supports parallel execution @@ -677,6 +678,7 @@ Runs `actionlint` to validate GitHub Actions workflows. #### Behavior * Verifies `actionlint` is installed before running +* Emits a clear upgrade hint when local `actionlint` does not recognize newer runner labels * Runs from repository root for consistent workflow path resolution * Passes through optional CLI arguments to `actionlint` @@ -700,12 +702,12 @@ curl -s $(baseUrl)/run-actionlint.sh | bash #### Purpose -Runs `shfmt` to check or fix formatting for tracked shell-related files. +Runs `shfmt` to check or fix formatting for shell-related files. #### Behavior * Verifies `shfmt` is installed before running -* Targets tracked `*.sh`, `*.bash`, and `*.bats` files +* Targets tracked and untracked `*.sh`, `*.bash`, and `*.bats` files (excluding ignored files) * Default mode checks formatting and fails on drift * `--fix` mode applies formatting in-place diff --git a/scripts/check-local-swift-dependencies.sh b/scripts/check-local-swift-dependencies.sh index 131bc8a..5ac70c5 100755 --- a/scripts/check-local-swift-dependencies.sh +++ b/scripts/check-local-swift-dependencies.sh @@ -13,8 +13,8 @@ # - CI: fail fast if local dependencies are detected # - Local: allow developers to verify their Package.swift before pushing # -# The script checks ONLY tracked files to avoid false positives from -# uncommitted or generated files. +# The script checks tracked and untracked files, excluding files ignored +# by standard git ignore rules. set -euo pipefail @@ -37,13 +37,13 @@ REPO_ROOT="$(git -C "$PWD" rev-parse --show-toplevel)" # Collect files to check # # We intentionally use `git ls-files` to: -# - Inspect only tracked files -# - Avoid scanning generated or uncommitted files +# - Inspect tracked and untracked files +# - Exclude ignored/generated files via `--exclude-standard` # # Currently, we only check Package.swift, since local package references # are only valid in that file. read -ra PATHS_TO_CHECK <<<"$( - git -C "${REPO_ROOT}" ls-files -z \ + git -C "${REPO_ROOT}" ls-files -z --cached --others --exclude-standard \ "Package.swift" | xargs -0 )" diff --git a/scripts/check-swift-headers.sh b/scripts/check-swift-headers.sh index 276c4ec..9ebc56d 100755 --- a/scripts/check-swift-headers.sh +++ b/scripts/check-swift-headers.sh @@ -236,7 +236,7 @@ fi FILES=() while IFS= read -r -d '' file; do FILES+=("$file") -done < <(git ls-files -z "${EXCLUDE_PATTERNS[@]}") +done < <(git ls-files -z --cached --others --exclude-standard "${EXCLUDE_PATTERNS[@]}") for file in "${FILES[@]}"; do if ! check_or_fix_header "$file"; then diff --git a/scripts/run-actionlint.sh b/scripts/run-actionlint.sh index 9737704..d1c0586 100755 --- a/scripts/run-actionlint.sh +++ b/scripts/run-actionlint.sh @@ -12,13 +12,26 @@ fatal() { exit 1 } +REPO_ROOT="$(git -C "$PWD" rev-parse --show-toplevel 2>/dev/null || pwd)" +cd "$REPO_ROOT" + +log "Running actionlint..." + if ! command -v actionlint >/dev/null 2>&1; then fatal "actionlint is not installed. Install it first (e.g. 'brew install actionlint' or 'apt-get install actionlint')." fi -REPO_ROOT="$(git -C "$PWD" rev-parse --show-toplevel 2>/dev/null || pwd)" -cd "$REPO_ROOT" +set +e +LOCAL_OUTPUT="$(actionlint "$@" 2>&1)" +LOCAL_RC=$? +set -e + +if [ "$LOCAL_RC" -ne 0 ] && printf '%s' "$LOCAL_OUTPUT" | grep -q 'label ".*" is unknown'; then + error "Your installed actionlint is likely outdated and does not recognize newer runner labels." + error "Please upgrade actionlint and run this script again." +fi + +[ -n "$LOCAL_OUTPUT" ] && printf '%s\n' "$LOCAL_OUTPUT" +[ "$LOCAL_RC" -ne 0 ] && exit "$LOCAL_RC" -log "Running actionlint..." -actionlint "$@" log "✅ actionlint found no issues." diff --git a/scripts/run-swift-format.sh b/scripts/run-swift-format.sh index b66b7fe..8d5b53f 100755 --- a/scripts/run-swift-format.sh +++ b/scripts/run-swift-format.sh @@ -65,14 +65,14 @@ fi # Run swift-format # -# - Uses git to list all tracked Swift files +# - Uses git to list tracked and untracked Swift files # - Applies exclusions defined in .swiftformatignore # - Runs formatting in parallel for performance # # The exit code is captured explicitly to allow controlled error handling. tr '\n' '\0' <.swiftformatignore | xargs -0 -I% printf '":(exclude)%" ' | - xargs git ls-files -z '*.swift' | + xargs git ls-files -z --cached --others --exclude-standard '*.swift' | xargs -0 swift format "${FORMAT_COMMAND[@]}" --parallel && SWIFT_FORMAT_RC=$? || SWIFT_FORMAT_RC=$? diff --git a/scripts/script-format.sh b/scripts/script-format.sh index a8fd365..9721004 100755 --- a/scripts/script-format.sh +++ b/scripts/script-format.sh @@ -50,7 +50,7 @@ fi FILES=() while IFS= read -r -d '' file; do FILES+=("$file") -done < <(git ls-files -z '*.sh' '*.bash' '*.bats') +done < <(git ls-files -z --cached --others --exclude-standard '*.sh' '*.bash' '*.bats') if [ "${#FILES[@]}" -eq 0 ]; then log "No shell files found to format." From 5d992be12eae70b0525a13710929256c4ba5198a Mon Sep 17 00:00:00 2001 From: GErP83 Date: Thu, 21 May 2026 16:57:21 +0200 Subject: [PATCH 2/2] fix tests --- tests/bats/check-local-swift-dependencies.bats | 6 +++--- tests/bats/check-swift-headers.bats | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/bats/check-local-swift-dependencies.bats b/tests/bats/check-local-swift-dependencies.bats index cf10dc9..6f0649d 100755 --- a/tests/bats/check-local-swift-dependencies.bats +++ b/tests/bats/check-local-swift-dependencies.bats @@ -50,7 +50,7 @@ SWIFT [[ "$output" == *"contains local Swift package reference"* ]] } -@test "check-local-swift-dependencies ignores untracked Package.swift" { +@test "check-local-swift-dependencies checks untracked Package.swift" { repo="$(make_temp_repo)" copy_script_into_repo "$repo" "check-local-swift-dependencies.sh" @@ -74,8 +74,8 @@ TXT run bash -c "cd '$repo' && bash scripts/check-local-swift-dependencies.sh" - [ "$status" -eq 0 ] - [[ "$output" == *"Found 0 local Swift package dependency references"* ]] + [ "$status" -eq 1 ] + [[ "$output" == *"contains local Swift package reference"* ]] } @test "check-local-swift-dependencies passes when no Package.swift is tracked" { diff --git a/tests/bats/check-swift-headers.bats b/tests/bats/check-swift-headers.bats index 362aa43..4337eb5 100755 --- a/tests/bats/check-swift-headers.bats +++ b/tests/bats/check-swift-headers.bats @@ -169,12 +169,13 @@ EOF2 run run_checker --fix [ "$status" -eq 0 ] - cp "$TMPDIR/Address.swift" "$TMPDIR/once.swift" + before_content="$(cat "$TMPDIR/Address.swift")" run run_checker --fix [ "$status" -eq 0 ] - diff -u "$TMPDIR/once.swift" "$TMPDIR/Address.swift" + after_content="$(cat "$TMPDIR/Address.swift")" + [ "$before_content" = "$after_content" ] } @test "--author without value fails with clear error" {