Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/config-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ name: Reusable — Config Sync
# template is always bootstrapped: it is a stub that extends the central
# `.renovate/default.json5` preset and holds the repo's own Renovate
# rules, so it is never overwritten. The sync warns when an existing
# `renovate.json5` does not extend that preset.
# `renovate.json5` does not extend that preset. The `.gitattributes`
# template (LF line endings) is always bootstrapped as well, and the
# sync warns when an existing `.gitattributes` has no LF default.
#
# Per-repo opt-out: list paths (one per line, relative to repo root)
# in `.github/.config-sync-ignore` to skip them during sync. Blank
Expand Down Expand Up @@ -52,7 +54,7 @@ on:
inputs:
sync-templates:
description: "Also sync template files (only copies if file does not exist locally — will not overwrite customized
files). renovate.json5 is bootstrapped regardless."
files). renovate.json5 and .gitattributes are bootstrapped regardless."
required: false
type: boolean
default: false
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/lint-include.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ on:
required: false
type: boolean
default: false
lint-line-endings:
description: "Report text files committed with CRLF line endings (scripts/lint/line-endings.sh). See lint.yml."
required: false
type: boolean
default: false
lint-line-endings-blocking:
description: "Report CRLF line endings as errors and fail the line-endings linter; false reports warnings only"
required: false
type: boolean
default: true
upload-sarif:
description: "Upload checkov/trivy/zizmor/ruff/biome/psscriptanalyzer results to GitHub code scanning (requires GitHub
Advanced Security). Set false for private repos without GHAS to gate on exit codes with console output instead."
Expand Down Expand Up @@ -209,5 +219,7 @@ jobs:
lint-config-drift: ${{ inputs.lint-config-drift }}
lint-inline-scripts: ${{ inputs.lint-inline-scripts }}
lint-inline-scripts-blocking: ${{ inputs.lint-inline-scripts-blocking }}
lint-line-endings: ${{ inputs.lint-line-endings }}
lint-line-endings-blocking: ${{ inputs.lint-line-endings-blocking }}
upload-sarif: ${{ inputs.upload-sarif }}
lint-job-mode: ${{ inputs.lint-job-mode }}
58 changes: 58 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,19 @@ on:
required: false
type: boolean
default: false
lint-line-endings:
description: >-
Report text files committed with CRLF or mixed line endings (scripts/lint/line-endings.sh, git ls-files --eol).
A path that needs CRLF gets its own .gitattributes rule: `eol=crlf` (stored with LF) or `-text` (stored byte
for byte).
required: false
type: boolean
default: true
lint-line-endings-blocking:
description: "Report CRLF line endings as errors and fail the line-endings linter; false reports warnings only"
required: false
type: boolean
default: true
upload-sarif:
description: "Upload checkov/trivy/zizmor/ruff/biome/psscriptanalyzer results to GitHub code scanning (requires GitHub
Advanced Security). Set false for private repos without GHAS to gate on exit codes with console output instead."
Expand Down Expand Up @@ -962,6 +975,43 @@ jobs:
# The runner's system Python ships PyYAML; a caller's mise Python may not.
run: /usr/bin/python3 "${RUNNER_TEMP}/devsecninja-lint/scripts/lint-inline-scripts.py"

line-endings:
name: line endings
if: ${{ inputs.lint-line-endings && (inputs.lint-job-mode == 'parallel' || (inputs.lint-job-mode == 'auto' && !github.event.repository.private))
}}
continue-on-error: ${{ ! inputs.lint-fail-on-error }}
runs-on: ubuntu-24.04
timeout-minutes: 10
steps:
- name: Checkout lint scripts
# The linter scripts ship with this reusable workflow: fetch them from
# the same commit of DevSecNinja/.github that the caller pinned.
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: ${{ job.workflow_repository }}
ref: ${{ job.workflow_sha }}
path: .devsecninja-lint
sparse-checkout: |-
scripts/lint/
scripts/lint-inline-scripts.py
sparse-checkout-cone-mode: false
persist-credentials: false

- name: Move lint scripts out of the workspace
# Outside the workspace the caller's linters don't scan them, and the
# code checkout doesn't delete them.
run: mv .devsecninja-lint "${RUNNER_TEMP}/devsecninja-lint"

- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Check line endings
env:
LINT_LINE_ENDINGS_BLOCKING: ${{ inputs.lint-line-endings-blocking }}
run: bash "${RUNNER_TEMP}/devsecninja-lint/scripts/lint/line-endings.sh"

all-linters:
# Single-job mode (`lint-job-mode: single`, or `auto` on a private
# repository). Every enabled linter runs as a step of this one job, so a
Expand Down Expand Up @@ -1289,6 +1339,14 @@ jobs:
# The runner's system Python ships PyYAML; a caller's mise Python may not.
run: /usr/bin/python3 "${RUNNER_TEMP}/devsecninja-lint/scripts/lint-inline-scripts.py"

- name: Check line endings
id: line-endings
if: ${{ inputs.lint-line-endings }}
continue-on-error: true
env:
LINT_LINE_ENDINGS_BLOCKING: ${{ inputs.lint-line-endings-blocking }}
run: bash "${RUNNER_TEMP}/devsecninja-lint/scripts/lint/line-endings.sh"

- name: Report linter results
if: ${{ !cancelled() }}
env:
Expand Down
85 changes: 85 additions & 0 deletions config-sync/templates/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Line endings for this repository, bootstrapped by DevSecNinja/.github
# config-sync (config-sync/templates/.gitattributes). Config-sync adds it only
# when the repository has no .gitattributes and never overwrites it: the
# repository owns this file. Add repository-specific rules at the end; later
# lines win. Based on the shared ~/.gitattributes in DevSecNinja/dotfiles
# (home/dot_gitattributes).

# LF in the repository and in every checkout, on every OS. A path that needs
# CRLF gets its own rule below, for example:
# *.ps1 text eol=crlf CRLF in the checkout, LF in the repository
# *.ics -text stored byte for byte (RFC 5545 calendars need CRLF)
# The shared Lint workflow (lint-line-endings) fails on text files committed
# with CRLF, except -text paths.
* text=auto eol=lf

# Scripts stay LF even when a repository changes the default above.
*.bash text eol=lf
*.fish text eol=lf
*.ksh text eol=lf
*.sh text eol=lf
*.zsh text eol=lf

# cmd.exe misreads labels and GOTO in batch files with LF line endings.
*.bat text eol=crlf
*.cmd text eol=crlf

# A patch keeps the line endings of the files it changes.
*.patch -text

# SVG is XML: text, not binary.
*.svg text

# Binary files: no line-ending conversion and no text diff.
# Images
*.avif binary
*.eps binary
*.gif binary
*.ico binary
*.jpeg binary
*.jpg binary
*.png binary
*.tif binary
*.tiff binary
*.webp binary
# Documents
*.docx binary
*.pdf binary
*.pptx binary
*.xlsx binary
# Fonts
*.eot binary
*.otf binary
*.ttf binary
*.woff binary
*.woff2 binary
# Audio and video
*.mp3 binary
*.mp4 binary
*.wav binary
*.webm binary
# Archives
*.7z binary
*.bz binary
*.bz2 binary
*.bzip2 binary
*.gz binary
*.lz binary
*.lzma binary
*.rar binary
*.tar binary
*.taz binary
*.tbz binary
*.tbz2 binary
*.tgz binary
*.tlz binary
*.txz binary
*.xz binary
*.Z binary
*.zip binary
*.zst binary
# Executables and libraries
*.dll binary
*.dylib binary
*.exe binary
*.so binary
36 changes: 34 additions & 2 deletions config-sync/templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,40 @@ ai-toolkit; see
These files are **starting points** for repos that need them.
They are only copied when `sync-templates: true` is set on the caller,
and only if the target path does not already exist — local edits are
never overwritten. `renovate.json5` is the exception to the first rule:
it is bootstrapped even without `sync-templates`.
never overwritten. `renovate.json5` and `.gitattributes` are the
exceptions to the first rule: they are bootstrapped even without
`sync-templates`.

## .gitattributes

LF line endings for every text file, in the repository and in every
checkout, on every OS: `* text=auto eol=lf`, plus `binary` for common
binary types, LF for shell scripts and CRLF checkouts for `*.bat`/`*.cmd`
(cmd.exe misreads labels in LF batch files). It starts from the shared
`~/.gitattributes` in
[DevSecNinja/dotfiles](https://github.com/DevSecNinja/dotfiles/blob/main/home/dot_gitattributes).

Config-sync creates it when the repo has no `.gitattributes` and never
overwrites it, so the repo owns the file. Give a path that needs CRLF its own
rule at the end, where later lines win:

```gitattributes
# CRLF in the checkout, LF in the repository (e.g. Authenticode-signed scripts).
*.ps1 text eol=crlf
# Stored byte for byte: iCalendar (RFC 5545) requires CRLF.
*.ics -text
```

Each sync run warns when an existing `.gitattributes` has no LF default (the
last `*` line that sets or resets `eol` must set `eol=lf`). A repo that deliberately
uses another default lists `.gitattributes` in `.github/.config-sync-ignore`,
which also skips that warning.

Adding the file doesn't convert files already committed with CRLF; run
`git add --renormalize .` and commit the result. The shared Lint workflow's
`lint-line-endings` check fails on text files committed with CRLF or mixed
line endings, except `-text` paths (see
[docs/architecture.md](../../docs/architecture.md#lint-lintyml)).

## renovate.json5

Expand Down
17 changes: 16 additions & 1 deletion docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,17 @@ runs it blocking. A
later major release makes blocking the default. The checker runs with the
runner's system Python, which ships PyYAML (`ubuntu-24.04`).

The `line endings` linter (`scripts/lint/line-endings.sh`) reports every text
file committed with CRLF or mixed line endings. It reads `git ls-files --eol`,
so git's own `.gitattributes` resolution decides: a path with `-text` (or
`binary`) is stored byte for byte and skipped, and an `eol=crlf` path passes,
because git stores it with LF and only checks it out with CRLF. Those rules are
the only way to keep CRLF; the linter has no exclude input. Findings are errors
that fail the linter; `lint-line-endings-blocking: false` reports them as
warnings. Fix them with `git add --renormalize .` once `.gitattributes` has
`* text=auto eol=lf`, which config-sync bootstraps (see
[Templates](#templates-config-synctemplates)). The linter needs only git.

| Input | Description |
| ------------------------------ | ---------------------------------------------------------------------- |
| `mise-version` | **Required.** mise version to install. |
Expand Down Expand Up @@ -283,6 +294,8 @@ runner's system Python, which ships PyYAML (`ubuntu-24.04`).
| `lint-config-drift` | Config-drift check. Default: `false`. |
| `lint-inline-scripts` | Inline-script check (see above). Default: `true`. After v4.4.0. |
| `lint-inline-scripts-blocking` | Report inline scripts as errors. Default: `false`. After v4.4.0. |
| `lint-line-endings` | CRLF line-endings check (see above). Default: `true`. After v4.7.0. |
| `lint-line-endings-blocking` | Report CRLF as errors and fail. Default: `true`. After v4.7.0. |

**Example caller:**

Expand Down Expand Up @@ -1131,7 +1144,9 @@ These are **starting-point** files. Config-sync copies them only when the
caller sets `sync-templates: true` and the file does not exist yet; it never
overwrites them. `renovate.json5` is always bootstrapped: it is a stub that
extends [`.renovate/default.json5`](#consuming-the-preset) and holds the
repository's own Renovate rules. See
repository's own Renovate rules. `.gitattributes` is always bootstrapped too:
it makes LF the line ending of every text file, and each sync warns when an
existing `.gitattributes` has no LF default. See
[`config-sync/templates/README.md`](../config-sync/templates/README.md) for
details.

Expand Down
33 changes: 29 additions & 4 deletions scripts/config-sync/sync-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ sync_tree() {
continue
fi

if [ "${kind}" = "templates" ] && [ -e "${dest}" ]; then
# A symlink counts as existing even when it dangles: cp would write
# the template through it.
if [ "${kind}" = "templates" ] && { [ -e "${dest}" ] || [ -L "${dest}" ]; }; then
echo " ✔ ${dest} already exists (templates are not overwritten)"
continue
fi
Expand Down Expand Up @@ -187,11 +189,34 @@ if [ "${SYNC_TEMPLATES}" = "true" ]; then
echo "=== Syncing template files (new files only) ==="
sync_tree templates
else
# The Renovate stub carries the org defaults, so every repo
# gets one even without sync-templates.
# The Renovate stub carries the org defaults and .gitattributes the
# LF line endings, so every repo gets both even without
# sync-templates.
echo ""
echo "=== Bootstrapping renovate.json5 (new file only) ==="
echo "=== Bootstrapping renovate.json5 and .gitattributes (new files only) ==="
sync_tree templates renovate.json5
sync_tree templates .gitattributes
fi

# .gitattributes is repo-owned as well; only check that LF stays the
# default line ending: the last catch-all (`*`, or the quoted `"*"`) that
# sets or resets `eol` sets `eol=lf` (`-eol`, `!eol` and a bare `eol` drop
# an earlier LF default). A repository that needs another default lists
# .gitattributes in its ignore file, which also skips this check. Exit 0:
# LF default.
lf_default() {
awk '{ sub(/\r$/, "") }
$1 == "*" || $1 == "\"*\"" {
for (i = 2; i <= NF; i++) {
if ($i ~ /^eol=/) eol = substr($i, 5)
else if ($i == "eol" || $i == "-eol" || $i == "!eol") eol = ""
}
}
END { exit eol != "lf" }' "$1"
}
# shellcheck disable=SC2310 # is_ignored and lf_default only test; their status is the answer.
if [ -f .gitattributes ] && ! is_ignored .gitattributes && ! lf_default .gitattributes; then
echo "::warning file=.gitattributes,title=.gitattributes has no LF default::Make \"* text=auto eol=lf\" the last catch-all rule, before the path-specific rules: replace a catch-all that sets another eol (e.g. \"* text=auto eol=crlf\") instead of adding one above it. Every text file is then stored and checked out with LF. Give a path that needs CRLF its own rule (\"eol=crlf\" or \"-text\"). See https://github.com/DevSecNinja/.github/blob/main/config-sync/templates/README.md#gitattributes"
fi

# renovate.json5 is repo-owned; only check that its top-level
Expand Down
Loading
Loading