Files
lucisv/tools/linux_check.sh
T
Guoliang ChenandClaude Mythos 5.2 71d13b5fbe
ci / checks (push) Successful in 1m0s
ci / corpus (push) Successful in 18s
ci / linux (push) Successful in 6m4s
release / build-and-publish (push) Successful in 5m31s
Release 0.66.2: every source file names its author
Every tracked file that can carry a comment (880 of them) now opens with
"Author: Guoliang Chen, a Senior Digital Design Engineer" and closes with
"Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love,
luciochen.com", in the file's own comment syntax. No behaviour change: the
diff outside the version bump and changelogs is comment lines only.

- tools/stamp_author.py: writes the lines; idempotent, `--check` lists
  what is missing. Headers go under a shebang and under Markdown front
  matter.
- Left alone: test fixtures, cases and snapshots (byte-exact inputs), JSON
  and JSONL, logs, images, lockfiles, docs/site/dist (regenerated) and the
  LICENSE files (already carry the copyright line).
- tools/linux_check.sh: --help reads its header from line 3, now that the
  author line sits under the shebang.
- tools/gates.sh green on this tree: 5 545 tests, corpus 814/6 as before.

Co-Authored-By: Claude Mythos 5.2 <[email protected]>
2026-11-24 12:11:09 -08:00

118 lines
4.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Author: Guoliang Chen, a Senior Digital Design Engineer
# Run a command against this working tree on Linux, inside the same job image
# the luhpe-linux-x64 Actions runner uses, without pushing anything.
#
# The tree is streamed over ssh into a throwaway container started by the
# runner's own Docker daemon on luhpe, so it runs under the runner's cpu and
# memory limits. What is sent: every tracked file as it is on disk, plus every
# UNTRACKED file git does not ignore (a stray .env or key file included -
# check `git status` first). A tracked file deleted from the working tree, or
# any other local tar error, fails the run before anything is judged; a
# partial tree is never shipped. The Rust toolchain and the cargo target
# directory are kept in a Docker volume between runs, so only the first run
# is a cold build.
#
# One run at a time: the runs share that volume (toolchain install, target
# dirs, a --user run's chown), so the container has a fixed name and a second
# run while one is in flight is refused by Docker ("name ... already in use").
# A run whose ssh dropped keeps its container until its command ends.
#
# Usage: tools/linux_check.sh [--user] [--dry-run] [--] <command...>
# tools/linux_check.sh 'cargo clippy --all-targets -- -D warnings'
# tools/linux_check.sh --user cargo test -p lucisv_core
# tools/linux_check.sh grep -rn "two words" crates
#
# One argument is a shell command line, run as written (pipes, ;, quotes).
# Several arguments are one command and its arguments, each kept whole.
# By default the command runs as root, which is how the runner's jobs run and
# so what CI will see. --user runs it as an unprivileged user instead: file
# permissions are enforced there, which root ignores. --dry-run builds the
# archive locally (to check the local half), prints its size and the remote
# command, and contacts nothing.
#
# Needs: ssh access to the host `luhpe` (LUCISV_LINUX_HOST overrides) and the
# gitea-runner container on it (docs: tools/RELEASING.md, "CI releases").
# Exit status is the command's, or non-zero if the archive or the
# connection failed.
set -eu -o pipefail
host=${LUCISV_LINUX_HOST:-luhpe}
image=docker.gitea.com/runner-images:ubuntu-latest
name=lucisv-linux-check
as_user=0
dry_run=0
while [ $# -gt 0 ]; do
case $1 in
--user) as_user=1; shift ;;
--dry-run) dry_run=1; shift ;;
--) shift; break ;;
-h|--help) sed -n '3,38p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;;
*) break ;;
esac
done
[ $# -ge 1 ] || { echo "usage: $0 [--user] [--dry-run] [--] <command...>" >&2; exit 2; }
if [ $# -eq 1 ]; then
cmd=$1
else
cmd=$(printf '%q ' "$@")
fi
repo_root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
cd "$repo_root"
# Inside the container: unpack stdin to /w, make sure the toolchain is in the
# cache volume, then run the command as root or as uid 1001.
inner='
set -eu
export RUSTUP_HOME=/cache/rustup CARGO_HOME=/cache/cargo
mkdir -p /w && tar xzf - -C /w
if [ ! -x "$CARGO_HOME/bin/cargo" ]; then
curl --proto =https --tlsv1.2 -sSf https://sh.rustup.rs \
| sh -s -- -y --profile minimal -c clippy,rustfmt --no-modify-path >/dev/null 2>&1
fi
export PATH="$CARGO_HOME/bin:$PATH"
if [ "$AS_USER" = 1 ]; then
export CARGO_TARGET_DIR=/cache/target-user HOME=/tmp/home
mkdir -p "$CARGO_TARGET_DIR" "$HOME"
chown -R 1001:1001 /w /cache "$HOME"
cd /w && exec setpriv --reuid 1001 --regid 1001 --clear-groups bash -c "$CMD"
fi
export CARGO_TARGET_DIR=/cache/target-root
# An earlier --user run leaves the cache owned by uid 1001; root does not mind.
cd /w && exec bash -c "$CMD"
'
remote="docker exec -i gitea-runner docker run --rm -i --name $name \
-v lucisv-linux-check:/cache \
-e AS_USER=$as_user -e CMD=$(printf '%q' "$cmd") \
$image bash -c $(printf '%q' "$inner")"
# The tree as a gzipped tar on stdout. COPYFILE_DISABLE and --no-xattrs keep
# macOS tar from adding ._* entries and extended-attribute headers that GNU
# tar on the other side warns about. Errors are not hidden: with pipefail a
# file tar cannot read fails the whole run.
archive() {
git ls-files -z --cached --others --exclude-standard \
| COPYFILE_DISABLE=1 tar czf - --no-xattrs --null -T -
}
if [ "$dry_run" = 1 ]; then
bytes=$(archive | wc -c)
echo "archive: $((bytes)) bytes; would run on $host:"
echo "$remote"
exit 0
fi
status=0
archive | ssh -o BatchMode=yes "$host" "$remote" || status=$?
if [ "$status" = 125 ]; then
echo "linux_check: docker refused to start the container; if it says the name" \
"\"$name\" is in use, another run is in flight - wait for it." >&2
fi
exit "$status"
# Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com