Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8f4e8e6fe1 |
No files matched your search
+3
-7
@@ -22,15 +22,11 @@ COPY . .
|
|||||||
|
|
||||||
RUN yarn run prettier --check '**/*.md' --tab-width 4 --prose-wrap always
|
RUN yarn run prettier --check '**/*.md' --tab-width 4 --prose-wrap always
|
||||||
|
|
||||||
# Test phase, same shape and for the same reason. coreutils makes cp GNU
|
# Test phase, same shape and for the same reason.
|
||||||
# cp, which writes into an existing file, as cp does on most hosts.
|
|
||||||
# busybox cp makes a new file, so test/commit-upstream-policy-files.sh
|
|
||||||
# would pass even if script/write-upstream-policy-files copied straight
|
|
||||||
# over the running script/commit-upstream-policy-files.
|
|
||||||
#
|
#
|
||||||
# alpine 3.24.3, 2026-11-04
|
# alpine 3.24.3, 2026-11-04
|
||||||
FROM alpine@sha256:be2656061b536c1883c4034790e21d0a09c5aaaf51968b89368a3c0371ea2c9a AS test
|
FROM alpine@sha256:be2656061b536c1883c4034790e21d0a09c5aaaf51968b89368a3c0371ea2c9a AS test
|
||||||
RUN apk add --no-cache coreutils git make nodejs-current yarn
|
RUN apk add --no-cache git make nodejs-current yarn
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
@@ -41,7 +37,7 @@ RUN script/bootstrap
|
|||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
RUN test/commit-upstream-policy-files.sh
|
RUN timeout 90 test/update-policy.sh
|
||||||
|
|
||||||
# Development environment, and the last stage: a plain `docker build .`
|
# Development environment, and the last stage: a plain `docker build .`
|
||||||
# names no target and so builds this one. Nothing is wanted from the two
|
# names no target and so builds this one. Nothing is wanted from the two
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
.PHONY: bootstrap setup test lint fmt fmt-check check docker hooks write-upstream-policy-files commit-upstream-policy-files
|
.PHONY: bootstrap setup test lint fmt fmt-check check docker hooks update-policy
|
||||||
|
|
||||||
# Makefile targets are thin shims; the implementations live in script/
|
# Makefile targets are thin shims; the implementations live in script/
|
||||||
# per the scripts-to-rule-them-all pattern (see the Entrypoints section
|
# per the scripts-to-rule-them-all pattern (see the Entrypoints section
|
||||||
@@ -31,8 +31,5 @@ docker:
|
|||||||
hooks:
|
hooks:
|
||||||
@script/install-precommit
|
@script/install-precommit
|
||||||
|
|
||||||
write-upstream-policy-files:
|
update-policy:
|
||||||
@script/write-upstream-policy-files
|
@script/update-policy
|
||||||
|
|
||||||
commit-upstream-policy-files:
|
|
||||||
@script/commit-upstream-policy-files
|
|
||||||
@@ -118,7 +118,7 @@ alpine. We provide:
|
|||||||
`script/docker` for the image tag
|
`script/docker` for the image tag
|
||||||
- `script/test` — `docker build --target test --output type=cacheonly .`,
|
- `script/test` — `docker build --target test --output type=cacheonly .`,
|
||||||
building the `test` phase of the `Dockerfile`, which runs
|
building the `test` phase of the `Dockerfile`, which runs
|
||||||
`test/commit-upstream-policy-files.sh`, without writing an image
|
`test/update-policy.sh`, without writing an image
|
||||||
- `script/lint` — `docker build --target lint --output type=cacheonly .`,
|
- `script/lint` — `docker build --target lint --output type=cacheonly .`,
|
||||||
building the `lint` phase, which runs prettier over the markdown files,
|
building the `lint` phase, which runs prettier over the markdown files,
|
||||||
without writing an image
|
without writing an image
|
||||||
@@ -138,14 +138,9 @@ alpine. We provide:
|
|||||||
`script/check`
|
`script/check`
|
||||||
- `script/install-precommit` — installs the git pre-commit hook (our own
|
- `script/install-precommit` — installs the git pre-commit hook (our own
|
||||||
extension); `make hooks` shims to it
|
extension); `make hooks` shims to it
|
||||||
- `script/write-upstream-policy-files` — fetch the vendored policy files from
|
- `script/update-policy` — fetch the shared policy files from this repo and
|
||||||
this repo over HTTP and write them into a repo (our own extension). It writes
|
commit them, without pushing (our own extension); it is for the repos that
|
||||||
into the repo given as its argument, or its own repo with no argument. It
|
carry them and stops when run here
|
||||||
stops when its target is this repo.
|
|
||||||
- `script/commit-upstream-policy-files` — fetch the current
|
|
||||||
`script/write-upstream-policy-files`, run it on its own repo and commit the
|
|
||||||
result without pushing (our own extension). It is for the repos that vendor
|
|
||||||
the policy files. It stops when run here.
|
|
||||||
|
|
||||||
`make hooks` installs the pre-commit hook that runs `script/precommit`.
|
`make hooks` installs the pre-commit hook that runs `script/precommit`.
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: Existing Repo Checklist
|
title: Existing Repo Checklist
|
||||||
last_modified: 2026-11-16
|
last_modified: 2026-11-18
|
||||||
---
|
---
|
||||||
|
|
||||||
Use this checklist when beginning work in a repo that may not yet conform to our
|
Use this checklist when beginning work in a repo that may not yet conform to our
|
||||||
@@ -189,32 +189,14 @@ with your task.
|
|||||||
- [ ] `Makefile` exists in root — reference
|
- [ ] `Makefile` exists in root — reference
|
||||||
`https://git.eeqj.de/sneak/prompts/raw/branch/main/Makefile`
|
`https://git.eeqj.de/sneak/prompts/raw/branch/main/Makefile`
|
||||||
- [ ] Has targets: `test`, `lint`, `fmt`, `fmt-check`, `check`, `docker`,
|
- [ ] Has targets: `test`, `lint`, `fmt`, `fmt-check`, `check`, `docker`,
|
||||||
`hooks`, `commit-upstream-policy-files`
|
`hooks`, `update-policy`
|
||||||
- [ ] Target implementations live in `script/` (scripts-to-rule-them-all);
|
- [ ] Target implementations live in `script/` (scripts-to-rule-them-all);
|
||||||
Makefile targets are thin shims calling them — model scripts at
|
Makefile targets are thin shims calling them — model scripts at
|
||||||
`https://git.eeqj.de/sneak/prompts/raw/branch/main/script/<name>`
|
`https://git.eeqj.de/sneak/prompts/raw/branch/main/script/<name>`
|
||||||
- [ ] `script/precommit` exists and the pre-commit hook (installed by
|
- [ ] `script/precommit` exists and the pre-commit hook (installed by
|
||||||
`script/install-precommit`, shimmed by `make hooks`) runs it
|
`script/install-precommit`, shimmed by `make hooks`) runs it
|
||||||
- [ ] `script/write-upstream-policy-files` and
|
- [ ] `script/update-policy` exists, identical to the model script, and
|
||||||
`script/commit-upstream-policy-files` exist, identical to the model
|
`make update-policy` shims to it
|
||||||
scripts, and `make commit-upstream-policy-files` shims to
|
|
||||||
`script/commit-upstream-policy-files`. `make commit-upstream-policy-files`
|
|
||||||
commits without pushing, so a person reviews and pushes the commit. A
|
|
||||||
`.gitignore` or `.dockerignore` without the comment that ends the
|
|
||||||
canonical file needs no preparation. The script moves each line the
|
|
||||||
canonical file has never held to below the canonical content. Blank lines
|
|
||||||
and comments are dropped. Before its first use, add that comment to an
|
|
||||||
`.editorconfig` that has lines of its own, and put those lines below it.
|
|
||||||
Otherwise the script stops before it writes anything, naming the file and
|
|
||||||
each line. In a file that has the comment, an entry above it which the
|
|
||||||
canonical file has never held also stops the script. It stops the same way
|
|
||||||
on a line in `.golangci.yml` that the canonical file has never held, apart
|
|
||||||
from comments and the repo's entries in the `deny` list of the
|
|
||||||
`test-support` rule. It also stops on a repo's own
|
|
||||||
`script/write-upstream-policy-files` or
|
|
||||||
`script/commit-upstream-policy-files`. The script deletes a copy of a
|
|
||||||
document that the repo does not get. A copy with a line the canonical file
|
|
||||||
has never held stops it instead.
|
|
||||||
- [ ] README has an **Entrypoints** section documenting the `script/`
|
- [ ] README has an **Entrypoints** section documenting the `script/`
|
||||||
entrypoints and linking the standard
|
entrypoints and linking the standard
|
||||||
- [ ] `script/lint` and `script/test` each run
|
- [ ] `script/lint` and `script/test` each run
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: New Repo Checklist
|
title: New Repo Checklist
|
||||||
last_modified: 2026-11-16
|
last_modified: 2026-11-18
|
||||||
---
|
---
|
||||||
|
|
||||||
Use this checklist when creating a new repository from scratch. Follow the steps
|
Use this checklist when creating a new repository from scratch. Follow the steps
|
||||||
@@ -248,13 +248,8 @@ are thin shims calling them. Model scripts:
|
|||||||
- [ ] `script/install-precommit` — installs the pre-commit hook that runs
|
- [ ] `script/install-precommit` — installs the pre-commit hook that runs
|
||||||
`script/precommit`
|
`script/precommit`
|
||||||
- [ ] `make hooks` — shims to `script/install-precommit`
|
- [ ] `make hooks` — shims to `script/install-precommit`
|
||||||
- [ ] `script/write-upstream-policy-files` — fetches the vendored policy files
|
- [ ] `script/update-policy` / `make update-policy` — fetches the shared policy
|
||||||
from the `prompts` repo over HTTP and writes them into the repo; identical
|
files from the `prompts` repo and commits them; identical across repos
|
||||||
across repos
|
|
||||||
- [ ] `script/commit-upstream-policy-files` /
|
|
||||||
`make commit-upstream-policy-files` — fetches the current
|
|
||||||
`script/write-upstream-policy-files`, runs it on the repo and commits the
|
|
||||||
result without pushing; identical across repos
|
|
||||||
- [ ] README **Entrypoints** section documents the scripts and links the
|
- [ ] README **Entrypoints** section documents the scripts and links the
|
||||||
standard
|
standard
|
||||||
|
|
||||||
|
|||||||
+14
-39
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: Repository Policies
|
title: Repository Policies
|
||||||
last_modified: 2026-11-16
|
last_modified: 2026-11-18
|
||||||
---
|
---
|
||||||
|
|
||||||
This document covers repository structure, tooling, and workflow standards. Code
|
This document covers repository structure, tooling, and workflow standards. Code
|
||||||
@@ -93,8 +93,7 @@ style conventions are in separate documents:
|
|||||||
- `make check` (runs `test`, `lint`, `fmt-check`)
|
- `make check` (runs `test`, `lint`, `fmt-check`)
|
||||||
- `make docker`
|
- `make docker`
|
||||||
- `make hooks` (installs pre-commit hook)
|
- `make hooks` (installs pre-commit hook)
|
||||||
- `make commit-upstream-policy-files` (brings the repo up to standards and
|
- `make update-policy` (fetches the shared policy files and commits them)
|
||||||
commits)
|
|
||||||
|
|
||||||
A model Makefile is at
|
A model Makefile is at
|
||||||
`https://git.eeqj.de/sneak/prompts/raw/branch/main/Makefile`.
|
`https://git.eeqj.de/sneak/prompts/raw/branch/main/Makefile`.
|
||||||
@@ -111,8 +110,7 @@ style conventions are in separate documents:
|
|||||||
- `script/fmt-check`
|
- `script/fmt-check`
|
||||||
- `script/check`
|
- `script/check`
|
||||||
- `script/docker`
|
- `script/docker`
|
||||||
- `script/write-upstream-policy-files`
|
- `script/update-policy`
|
||||||
- `script/commit-upstream-policy-files`
|
|
||||||
|
|
||||||
The scripts must be POSIX sh (`#!/bin/sh`, `set -eu`, no bashisms) so they
|
The scripts must be POSIX sh (`#!/bin/sh`, `set -eu`, no bashisms) so they
|
||||||
run in minimal containers; alpine images, for example, have no bash. Locate
|
run in minimal containers; alpine images, for example, have no bash. Locate
|
||||||
@@ -186,19 +184,14 @@ style conventions are in separate documents:
|
|||||||
host. On a pristine checkout with nothing installed, the run dies there,
|
host. On a pristine checkout with nothing installed, the run dies there,
|
||||||
after the containerised gates have passed.
|
after the containerised gates have passed.
|
||||||
|
|
||||||
Six further scripts are our own extensions to the standard:
|
Five further scripts are our own extensions to the standard:
|
||||||
- `script/check` runs `script/test`, `script/lint` and `script/fmt-check`.
|
- `script/check` runs `script/test`, `script/lint` and `script/fmt-check`.
|
||||||
- `script/precommit` is what the git pre-commit hook runs, and it calls
|
- `script/precommit` is what the git pre-commit hook runs, and it calls
|
||||||
`script/check`.
|
`script/check`.
|
||||||
- `script/install-precommit` installs the git pre-commit hook. The
|
- `script/install-precommit` installs the git pre-commit hook. The
|
||||||
`make hooks` target shims to it.
|
`make hooks` target shims to it.
|
||||||
- `script/write-upstream-policy-files` fetches the vendored policy files
|
- `script/update-policy` fetches the shared policy files from the `prompts`
|
||||||
from the `prompts` repo over HTTP and writes them into the repo it is
|
repo and commits them. The `make update-policy` target shims to it.
|
||||||
given, or its own repo with no argument.
|
|
||||||
- `script/commit-upstream-policy-files` fetches the current
|
|
||||||
`script/write-upstream-policy-files` from the `prompts` repo, runs it on
|
|
||||||
its own repo and commits the result. It does not push. The
|
|
||||||
`make commit-upstream-policy-files` target shims to it.
|
|
||||||
- `script/projectname` (literally that filename) simply outputs the
|
- `script/projectname` (literally that filename) simply outputs the
|
||||||
project's name.
|
project's name.
|
||||||
|
|
||||||
@@ -868,30 +861,13 @@ style conventions are in separate documents:
|
|||||||
- Make all changes on a feature branch. You can do whatever you want on a
|
- Make all changes on a feature branch. You can do whatever you want on a
|
||||||
feature branch.
|
feature branch.
|
||||||
|
|
||||||
- One command brings a repo up to standards:
|
- A repo updates its shared policy files with one command: `make update-policy`.
|
||||||
`make commit-upstream-policy-files`. It runs
|
It runs `script/update-policy`, which fetches each file from the `main` branch
|
||||||
`script/commit-upstream-policy-files`, which fetches the current
|
of the `prompts` repo and commits them. It does not push: review the commit,
|
||||||
`script/write-upstream-policy-files` from the head of `main` in the `prompts`
|
then push it. The script lists the files at its top:
|
||||||
repo and runs it on the repo. It then commits the files that changed and does
|
- `docs/REPO_POLICIES.md`
|
||||||
not push, so a person reviews and pushes the commit.
|
- `docs/CODE_STYLEGUIDE.md`
|
||||||
|
- `script/update-policy` itself, so the script stays current
|
||||||
`script/write-upstream-policy-files` fetches the vendored files from
|
|
||||||
`prompts` over HTTP and writes them into the repo. A repo gets only the
|
|
||||||
files its own work uses, such as the style guide of each language it
|
|
||||||
contains. The script deletes a copy of a document that the repo does not
|
|
||||||
get. `script/write-upstream-policy-files` lists the files and says which
|
|
||||||
repos get each. A file the repo lacks is written whole. A `prompts/NAME.md`
|
|
||||||
goes to `docs/NAME.md`, unless the repo keeps it at `NAME.md`. It also
|
|
||||||
writes `script/write-upstream-policy-files` and
|
|
||||||
`script/commit-upstream-policy-files` into the repo, so a repo updated once
|
|
||||||
can update itself. The script replaces each file and keeps only the repo's
|
|
||||||
own entries:
|
|
||||||
- in `.gitignore`, `.editorconfig` and `.dockerignore`: the lines below the
|
|
||||||
comment that ends the canonical file
|
|
||||||
- in a `.gitignore` or `.dockerignore` lacking that comment: every entry the
|
|
||||||
canonical file has never held
|
|
||||||
- in `.golangci.yml`: the entries the repo added to the `deny` list of the
|
|
||||||
`test-support` depguard rule
|
|
||||||
|
|
||||||
- `.golangci.yml` is standardized. The vendored copy in a consuming repo must
|
- `.golangci.yml` is standardized. The vendored copy in a consuming repo must
|
||||||
_NEVER_ be modified by an agent. Fetch it from
|
_NEVER_ be modified by an agent. Fetch it from
|
||||||
@@ -1118,8 +1094,7 @@ style conventions are in separate documents:
|
|||||||
- `Makefile`
|
- `Makefile`
|
||||||
- `script/` entrypoints (`bootstrap`, `setup`, `projectname`, `test`,
|
- `script/` entrypoints (`bootstrap`, `setup`, `projectname`, `test`,
|
||||||
`lint`, `fmt`, `fmt-check`, `check`, `docker`, `cibuild`, `precommit`,
|
`lint`, `fmt`, `fmt-check`, `check`, `docker`, `cibuild`, `precommit`,
|
||||||
`install-precommit`, `write-upstream-policy-files`,
|
`install-precommit`, `update-policy`)
|
||||||
`commit-upstream-policy-files`)
|
|
||||||
- `Dockerfile`, `.dockerignore`
|
- `Dockerfile`, `.dockerignore`
|
||||||
- `.gitea/workflows/check.yml`
|
- `.gitea/workflows/check.yml`
|
||||||
- Go: `go.mod`, `go.sum`, `.golangci.yml`
|
- Go: `go.mod`, `go.sum`, `.golangci.yml`
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# script/commit-upstream-policy-files: bring this repo up to standards.
|
|
||||||
# It fetches the current script/write-upstream-policy-files from the
|
|
||||||
# prompts repo over HTTP, runs it on this repo and commits the files it
|
|
||||||
# wrote or deleted. It does not push. Identical in all repos. Our own
|
|
||||||
# extension to scripts-to-rule-them-all.
|
|
||||||
set -eu
|
|
||||||
|
|
||||||
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
|
|
||||||
WRITE_UPSTREAM_POLICY_FILES_URL="https://git.eeqj.de/sneak/prompts/raw/branch/main/script/write-upstream-policy-files"
|
|
||||||
|
|
||||||
die() {
|
|
||||||
echo "commit-upstream-policy-files: $*" >&2
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
main() {
|
|
||||||
[ "$#" -eq 0 ] || die "usage: script/commit-upstream-policy-files"
|
|
||||||
|
|
||||||
cd "$ROOT"
|
|
||||||
|
|
||||||
tmp="$(mktemp -d)"
|
|
||||||
trap 'rm -rf "$tmp"' EXIT
|
|
||||||
|
|
||||||
curl --fail --silent --show-error --max-time 60 \
|
|
||||||
--output "$tmp/write-upstream-policy-files" \
|
|
||||||
"$WRITE_UPSTREAM_POLICY_FILES_URL" ||
|
|
||||||
die "cannot fetch $WRITE_UPSTREAM_POLICY_FILES_URL"
|
|
||||||
|
|
||||||
sh "$tmp/write-upstream-policy-files" "$ROOT" > "$tmp/written"
|
|
||||||
commit="$(head -n 1 "$tmp/written")"
|
|
||||||
paths="$(tail -n +2 "$tmp/written")"
|
|
||||||
|
|
||||||
for path in $paths; do
|
|
||||||
git add -- "$path"
|
|
||||||
done
|
|
||||||
|
|
||||||
if git diff --cached --quiet -- $paths; then
|
|
||||||
echo "commit-upstream-policy-files: already at prompts $commit, nothing to commit"
|
|
||||||
else
|
|
||||||
git commit -m "Update policy files from prompts $commit" -- $paths
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
main "$@"
|
|
||||||
Executable
+56
@@ -0,0 +1,56 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# script/update-policy: replace the files below with their current
|
||||||
|
# versions from the main branch of the prompts repo, and commit them. It
|
||||||
|
# does not push. Identical in all repos, and it updates itself.
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
|
||||||
|
RAW_URL="https://git.eeqj.de/sneak/prompts/raw/branch/main"
|
||||||
|
|
||||||
|
# Each entry is the path in prompts, a colon, then the path in this repo.
|
||||||
|
FILES="
|
||||||
|
prompts/REPO_POLICIES.md:docs/REPO_POLICIES.md
|
||||||
|
prompts/CODE_STYLEGUIDE.md:docs/CODE_STYLEGUIDE.md
|
||||||
|
script/update-policy:script/update-policy
|
||||||
|
"
|
||||||
|
|
||||||
|
die() {
|
||||||
|
echo "update-policy: $*" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
cd "$ROOT"
|
||||||
|
[ ! -e prompts/REPO_POLICIES.md ] ||
|
||||||
|
die "this is the prompts repo, where these files come from"
|
||||||
|
|
||||||
|
paths=""
|
||||||
|
for entry in $FILES; do
|
||||||
|
paths="$paths ${entry#*:}"
|
||||||
|
done
|
||||||
|
[ -z "$(git status --porcelain -- $paths)" ] ||
|
||||||
|
die "commit or discard your changes to these files first:$paths"
|
||||||
|
|
||||||
|
# Every file is fetched before any is replaced. The temporary directory
|
||||||
|
# is inside the repo so that mv renames: the running script is replaced
|
||||||
|
# by a new file, never rewritten in place.
|
||||||
|
tmp="$(mktemp -d "$ROOT/.update-policy.XXXXXX")"
|
||||||
|
trap 'rm -rf "$tmp"' EXIT
|
||||||
|
for entry in $FILES; do
|
||||||
|
mkdir -p "$tmp/$(dirname "${entry#*:}")"
|
||||||
|
wget -q -T 60 -O "$tmp/${entry#*:}" "$RAW_URL/${entry%%:*}" ||
|
||||||
|
die "cannot fetch $RAW_URL/${entry%%:*}"
|
||||||
|
done
|
||||||
|
chmod 755 "$tmp/script/update-policy"
|
||||||
|
|
||||||
|
for path in $paths; do
|
||||||
|
mkdir -p "$(dirname "$path")"
|
||||||
|
mv "$tmp/$path" "$path"
|
||||||
|
done
|
||||||
|
|
||||||
|
git add -- $paths
|
||||||
|
if git diff --cached --quiet -- $paths; then
|
||||||
|
echo "update-policy: already current, nothing to commit"
|
||||||
|
else
|
||||||
|
git commit -q -m "Update policy files from prompts" -- $paths
|
||||||
|
echo "update-policy: committed; review it, then push"
|
||||||
|
fi
|
||||||
@@ -1,330 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# script/write-upstream-policy-files: write the current policy files
|
|
||||||
# from the prompts repo into a repo clone, over HTTP. It commits
|
|
||||||
# nothing; script/commit-upstream-policy-files does that. Identical in
|
|
||||||
# all repos. Our own extension to scripts-to-rule-them-all.
|
|
||||||
#
|
|
||||||
# Usage: script/write-upstream-policy-files [path of a repo clone]
|
|
||||||
# Without a path it updates the repo this script sits in.
|
|
||||||
#
|
|
||||||
# Standard output is the full hash of the prompts commit, then each path
|
|
||||||
# written or deleted, one per line. Messages go to standard error.
|
|
||||||
#
|
|
||||||
# The script writes and deletes nothing until every file has been
|
|
||||||
# fetched and merged. A repo's own entries are kept:
|
|
||||||
# - .gitignore, .editorconfig, .dockerignore: the lines below the
|
|
||||||
# canonical file's last line. An entry above that line which the
|
|
||||||
# canonical file has never held stops the script.
|
|
||||||
# - .gitignore, .dockerignore lacking that last line: each line the
|
|
||||||
# canonical file has never held, unless it is blank or a comment,
|
|
||||||
# goes below the canonical content.
|
|
||||||
# - .editorconfig lacking that last line: it is replaced if it has no
|
|
||||||
# such line. Otherwise the script stops, because a setting means
|
|
||||||
# nothing away from its section.
|
|
||||||
# - .golangci.yml: the entries the repo added to the deny list of the
|
|
||||||
# test-support rule. Any other line the canonical file has never
|
|
||||||
# held stops the script, unless it is blank or a comment.
|
|
||||||
set -eu
|
|
||||||
|
|
||||||
PROMPTS_URL="https://git.eeqj.de/sneak/prompts"
|
|
||||||
PROMPTS_API_URL="https://git.eeqj.de/api/v1/repos/sneak/prompts"
|
|
||||||
PROMPTS_FIRST_COMMIT="af257bef63f162a681bddc80d9b941c47a44b748"
|
|
||||||
|
|
||||||
# Paths in the prompts repo. A repo gets each file that file_applies
|
|
||||||
# allows, written whole if the repo lacks it. Every document in prompts
|
|
||||||
# is listed, so that a repo's copy of one it does not get is deleted.
|
|
||||||
VENDORED_FILES="
|
|
||||||
.dockerignore
|
|
||||||
.editorconfig
|
|
||||||
.gitea/workflows/check.yml
|
|
||||||
.gitignore
|
|
||||||
.golangci.yml
|
|
||||||
.prettierrc
|
|
||||||
prompts/API_POLICIES.md
|
|
||||||
prompts/CODE_STYLEGUIDE.md
|
|
||||||
prompts/CODE_STYLEGUIDE_GO.md
|
|
||||||
prompts/CODE_STYLEGUIDE_JS.md
|
|
||||||
prompts/CODE_STYLEGUIDE_PYTHON.md
|
|
||||||
prompts/EXISTING_REPO_CHECKLIST.md
|
|
||||||
prompts/GO_HTTP_SERVER_CONVENTIONS.md
|
|
||||||
prompts/LLM_PROSE_TELLS.md
|
|
||||||
prompts/NEW_REPO_CHECKLIST.md
|
|
||||||
prompts/REPO_POLICIES.md
|
|
||||||
script/write-upstream-policy-files
|
|
||||||
script/commit-upstream-policy-files
|
|
||||||
"
|
|
||||||
|
|
||||||
die() {
|
|
||||||
echo "write-upstream-policy-files: $*" >&2
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# fetch <url> <output file>
|
|
||||||
fetch() {
|
|
||||||
curl --fail --silent --show-error --max-time 60 --output "$2" "$1" ||
|
|
||||||
die "cannot fetch $1"
|
|
||||||
}
|
|
||||||
|
|
||||||
# file_applies <path in prompts>: fail if the target repo does not get
|
|
||||||
# the file. A language's files need a source file of that language that
|
|
||||||
# git tracks. The Go HTTP server conventions and the API policies need Go
|
|
||||||
# code outside the tests that uses http.ResponseWriter, as every net/http
|
|
||||||
# handler does. The checklists and the LLM prose tells stay in prompts.
|
|
||||||
# Every repo gets every other file.
|
|
||||||
file_applies() {
|
|
||||||
case "$1" in
|
|
||||||
.golangci.yml | prompts/CODE_STYLEGUIDE_GO.md)
|
|
||||||
[ -n "$(git ls-files -- '*.go')" ]
|
|
||||||
;;
|
|
||||||
prompts/API_POLICIES.md | prompts/GO_HTTP_SERVER_CONVENTIONS.md)
|
|
||||||
git grep -q -F http.ResponseWriter -- '*.go' ':(exclude)*_test.go'
|
|
||||||
;;
|
|
||||||
prompts/CODE_STYLEGUIDE_JS.md)
|
|
||||||
[ -n "$(git ls-files -- '*.js' '*.mjs' '*.ts')" ]
|
|
||||||
;;
|
|
||||||
prompts/CODE_STYLEGUIDE_PYTHON.md)
|
|
||||||
[ -n "$(git ls-files -- '*.py')" ]
|
|
||||||
;;
|
|
||||||
prompts/EXISTING_REPO_CHECKLIST.md | prompts/LLM_PROSE_TELLS.md | \
|
|
||||||
prompts/NEW_REPO_CHECKLIST.md)
|
|
||||||
false
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
# local_path <path in prompts>: print where the file goes in the target
|
|
||||||
# repo. A prompts/NAME.md stays at NAME.md if git tracks it there and not
|
|
||||||
# at docs/NAME.md; otherwise it goes to docs/NAME.md. Any other file goes
|
|
||||||
# to its own path.
|
|
||||||
local_path() {
|
|
||||||
name="${1#prompts/}"
|
|
||||||
if [ "$name" = "$1" ]; then
|
|
||||||
echo "$1"
|
|
||||||
elif [ -z "$(git ls-files -- "docs/$name")" ] &&
|
|
||||||
[ -n "$(git ls-files -- "$name")" ]; then
|
|
||||||
echo "$name"
|
|
||||||
else
|
|
||||||
echo "docs/$name"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# former_lines <patch> <path in prompts>: print the lines earlier commits
|
|
||||||
# removed from the file. The file's section of the patch ends at the
|
|
||||||
# next diff or the next commit.
|
|
||||||
former_lines() {
|
|
||||||
awk -v header="diff --git a/$2 b/$2" '
|
|
||||||
/^diff --git / { inside = ($0 == header); next }
|
|
||||||
/^From / { inside = 0; next }
|
|
||||||
inside && /^-/ { print substr($0, 2) }
|
|
||||||
' "$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
# local_only_lines <fetched> <local> [end]: print each line of the local
|
|
||||||
# file, above line end if given, that the canonical file has never held:
|
|
||||||
# not in the fetched file or in <fetched>.former, the lines earlier
|
|
||||||
# commits removed from it. Blank lines and comments do not count.
|
|
||||||
local_only_lines() {
|
|
||||||
cat "$1" "$1.former" | awk -v end="${3:-}" '
|
|
||||||
NR == FNR { held[$0]; next }
|
|
||||||
(end == "" || FNR < end) && !/^[ \t]*(#|$)/ && !($0 in held)
|
|
||||||
' - "$2"
|
|
||||||
}
|
|
||||||
|
|
||||||
# keep_lines_below_last <fetched> <local>: append to the fetched file
|
|
||||||
# whatever follows its last line in the local file. Stop if the canonical
|
|
||||||
# file has never held a line above that one, unless it is blank or a
|
|
||||||
# comment: replacing the file would delete it. If the local file lacks
|
|
||||||
# that last line, append each line the canonical file has never held,
|
|
||||||
# unless it is blank or a comment. An .editorconfig with such a line
|
|
||||||
# stops the script instead, because a setting means nothing away from
|
|
||||||
# its section.
|
|
||||||
keep_lines_below_last() {
|
|
||||||
last="$(tail -n 1 "$1")"
|
|
||||||
number="$(grep -n -F -x -- "$last" "$2" | head -n 1 | cut -d: -f1)"
|
|
||||||
if [ -z "$last" ] || [ -z "$number" ]; then
|
|
||||||
own="$(local_only_lines "$1" "$2")"
|
|
||||||
[ -n "$own" ] || return 0
|
|
||||||
if [ "$2" = .editorconfig ]; then
|
|
||||||
die "$2 lacks this line and has lines the canonical file has never held; add it and put those lines below it: $last
|
|
||||||
$own"
|
|
||||||
fi
|
|
||||||
printf '%s\n' "$own" >> "$1"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
own="$(local_only_lines "$1" "$2" "$number")"
|
|
||||||
if [ -n "$own" ]; then
|
|
||||||
die "$2 has entries above its last canonical line that the canonical file lacks; move each below that line to keep it, or delete it:
|
|
||||||
$own"
|
|
||||||
fi
|
|
||||||
tail -n "+$((number + 1))" "$2" >> "$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
# keep_deny_entries <fetched> <local>: add to the deny list of the
|
|
||||||
# test-support rule in the fetched file the entries only the local file
|
|
||||||
# has. An entry is a "- pkg:" line, the lines under it and any comment
|
|
||||||
# above it. Stop if the local file still has a line that neither the
|
|
||||||
# result nor the canonical file has ever held, unless it is blank or a
|
|
||||||
# comment: replacing the file would delete it.
|
|
||||||
keep_deny_entries() {
|
|
||||||
awk '
|
|
||||||
function indent(line) { return match(line, /[^ ]/) - 1 }
|
|
||||||
function print_local_entries(i) {
|
|
||||||
for (i = 1; i <= count; i++)
|
|
||||||
if (!(pkg[i] in fetched_pkg))
|
|
||||||
printf "%s", entry[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
FNR == 1 { in_rule = 0; in_list = 0 }
|
|
||||||
|
|
||||||
in_list && /[^ ]/ && indent($0) <= list_indent {
|
|
||||||
in_list = 0
|
|
||||||
if (FILENAME == ARGV[2]) print_local_entries()
|
|
||||||
}
|
|
||||||
|
|
||||||
in_list {
|
|
||||||
is_entry = ($1 == "-" && $2 == "pkg:")
|
|
||||||
if (FILENAME == ARGV[2]) {
|
|
||||||
if (is_entry) fetched_pkg[$3]
|
|
||||||
print
|
|
||||||
} else if (is_entry) {
|
|
||||||
count++
|
|
||||||
pkg[count] = $3
|
|
||||||
entry[count] = comment $0 "\n"
|
|
||||||
comment = ""
|
|
||||||
} else if (/^ *#/) {
|
|
||||||
comment = comment $0 "\n"
|
|
||||||
} else if (count) {
|
|
||||||
entry[count] = entry[count] $0 "\n"
|
|
||||||
}
|
|
||||||
next
|
|
||||||
}
|
|
||||||
|
|
||||||
in_rule && /^ *[^ #]/ && indent($0) <= rule_indent { in_rule = 0 }
|
|
||||||
/^ *test-support:/ { in_rule = 1; rule_indent = indent($0) }
|
|
||||||
in_rule && /^ *deny:/ {
|
|
||||||
in_rule = 0
|
|
||||||
in_list = 1
|
|
||||||
list_indent = indent($0)
|
|
||||||
if (FILENAME == ARGV[2]) found = 1
|
|
||||||
}
|
|
||||||
FILENAME == ARGV[2] { print }
|
|
||||||
|
|
||||||
END {
|
|
||||||
if (in_list) print_local_entries()
|
|
||||||
exit !found
|
|
||||||
}
|
|
||||||
' "$2" "$1" > "$1.merged" ||
|
|
||||||
die "the fetched $2 has no deny list in its test-support rule"
|
|
||||||
mv "$1.merged" "$1"
|
|
||||||
own="$(local_only_lines "$1" "$2")"
|
|
||||||
if [ -n "$own" ]; then
|
|
||||||
die "$2 has lines the canonical file has never held; only the deny list of the test-support rule may differ from canonical:
|
|
||||||
$own"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# stop_on_own_lines <fetched> <local>: stop if the local file has a line
|
|
||||||
# the canonical file has never held, unless it is blank or a comment:
|
|
||||||
# the repo wrote that file itself, and replacing or deleting the file
|
|
||||||
# would lose that line.
|
|
||||||
stop_on_own_lines() {
|
|
||||||
own="$(local_only_lines "$1" "$2")"
|
|
||||||
if [ -n "$own" ]; then
|
|
||||||
die "$2 has lines the canonical file has never held; rename the repo's own file to keep it:
|
|
||||||
$own"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
main() {
|
|
||||||
[ "$#" -le 1 ] ||
|
|
||||||
die "usage: script/write-upstream-policy-files [path of a repo clone]"
|
|
||||||
|
|
||||||
target="${1:-$(dirname "$0")/..}"
|
|
||||||
cd "$target" || die "no such directory: $target"
|
|
||||||
if [ "$(git rev-parse --show-toplevel 2> /dev/null)" != "$(pwd -P)" ]; then
|
|
||||||
die "not the top of a git clone: $target"
|
|
||||||
fi
|
|
||||||
if [ -e prompts/REPO_POLICIES.md ]; then
|
|
||||||
die "this repo is the source of the policy files"
|
|
||||||
fi
|
|
||||||
|
|
||||||
tmp="$(mktemp -d)"
|
|
||||||
trap 'rm -rf "$tmp"' EXIT
|
|
||||||
|
|
||||||
fetch "$PROMPTS_API_URL/branches/main" "$tmp/branch.json"
|
|
||||||
commit="$(grep -Eo '"id":"[0-9a-f]{40}"' "$tmp/branch.json" |
|
|
||||||
head -n 1 | cut -d'"' -f4)"
|
|
||||||
[ -n "$commit" ] || die "no commit hash in $PROMPTS_API_URL/branches/main"
|
|
||||||
|
|
||||||
fetch "$PROMPTS_URL/compare/$PROMPTS_FIRST_COMMIT...$commit.patch" \
|
|
||||||
"$tmp/history.patch"
|
|
||||||
|
|
||||||
to_write=""
|
|
||||||
to_delete=""
|
|
||||||
for file in $VENDORED_FILES; do
|
|
||||||
path="$(local_path "$file")"
|
|
||||||
if file_applies "$file"; then
|
|
||||||
to_write="$to_write $path"
|
|
||||||
else
|
|
||||||
# A document the repo does not get is deleted if git tracks a
|
|
||||||
# copy. Any other file it does not get is left alone.
|
|
||||||
case "$file" in
|
|
||||||
prompts/*) ;;
|
|
||||||
*) continue ;;
|
|
||||||
esac
|
|
||||||
[ -n "$(git ls-files -- "$path")" ] || continue
|
|
||||||
to_delete="$to_delete $path"
|
|
||||||
fi
|
|
||||||
if git check-ignore -q -- "$path"; then
|
|
||||||
die "$path is ignored by git; stop ignoring it"
|
|
||||||
fi
|
|
||||||
if [ -n "$(git status --porcelain -- "$path")" ]; then
|
|
||||||
die "$path has uncommitted changes"
|
|
||||||
fi
|
|
||||||
mkdir -p "$tmp/$(dirname "$path")"
|
|
||||||
fetch "$PROMPTS_URL/raw/commit/$commit/$file" "$tmp/$path"
|
|
||||||
former_lines "$tmp/history.patch" "$file" > "$tmp/$path.former"
|
|
||||||
done
|
|
||||||
|
|
||||||
for path in $to_write; do
|
|
||||||
[ -e "$path" ] || continue
|
|
||||||
case "$path" in
|
|
||||||
.gitignore | .editorconfig | .dockerignore)
|
|
||||||
keep_lines_below_last "$tmp/$path" "$path"
|
|
||||||
;;
|
|
||||||
.golangci.yml)
|
|
||||||
keep_deny_entries "$tmp/$path" "$path"
|
|
||||||
;;
|
|
||||||
script/*)
|
|
||||||
stop_on_own_lines "$tmp/$path" "$path"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
for path in $to_delete; do
|
|
||||||
stop_on_own_lines "$tmp/$path" "$path"
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "$commit"
|
|
||||||
for path in $to_write; do
|
|
||||||
mkdir -p "$(dirname "$path")"
|
|
||||||
case "$path" in
|
|
||||||
script/*)
|
|
||||||
# A new name and mv, because the script running may be
|
|
||||||
# script/commit-upstream-policy-files.
|
|
||||||
cp "$tmp/$path" "$path.new"
|
|
||||||
chmod 755 "$path.new"
|
|
||||||
mv "$path.new" "$path"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
cp "$tmp/$path" "$path"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
echo "$path"
|
|
||||||
done
|
|
||||||
for path in $to_delete; do
|
|
||||||
rm -- "$path"
|
|
||||||
echo "$path"
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
main "$@"
|
|
||||||
File diff suppressed because it is too large.
Load diff
Executable
+86
@@ -0,0 +1,86 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# test/update-policy.sh: test script/update-policy on throwaway repos. A
|
||||||
|
# stub wget serves the files from this checkout, or fails for the path
|
||||||
|
# in WGET_FAIL, so nothing touches the network.
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
PROMPTS="$(cd "$(dirname "$0")/.." && pwd -P)"
|
||||||
|
LISTED="docs/REPO_POLICIES.md docs/CODE_STYLEGUIDE.md script/update-policy"
|
||||||
|
|
||||||
|
dir="$(mktemp -d)"
|
||||||
|
trap 'rm -rf "$dir"' EXIT
|
||||||
|
|
||||||
|
fail() {
|
||||||
|
echo "FAIL: $scenario: $*" >&2
|
||||||
|
cat "$dir/output" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
mkdir "$dir/bin"
|
||||||
|
cat > "$dir/bin/wget" << EOF
|
||||||
|
#!/bin/sh
|
||||||
|
while [ "\$#" -gt 1 ]; do
|
||||||
|
[ "\$1" = "-O" ] && output="\$2"
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
path="\${1#https://git.eeqj.de/sneak/prompts/raw/branch/main/}"
|
||||||
|
[ "\$path" != "\${WGET_FAIL:-}" ] || exit 1
|
||||||
|
cp "$PROMPTS/\$path" "\$output"
|
||||||
|
EOF
|
||||||
|
chmod +x "$dir/bin/wget"
|
||||||
|
PATH="$dir/bin:$PATH"
|
||||||
|
export PATH
|
||||||
|
|
||||||
|
# new_repo: a repo with one commit, holding only an older copy of the
|
||||||
|
# script, so that a run must replace the script that is running.
|
||||||
|
new_repo() {
|
||||||
|
scenario="$1"
|
||||||
|
rm -rf "$dir/repo"
|
||||||
|
git init -q "$dir/repo"
|
||||||
|
cd "$dir/repo"
|
||||||
|
git config user.name test
|
||||||
|
git config user.email test@example.com
|
||||||
|
mkdir script
|
||||||
|
cp "$PROMPTS/script/update-policy" script/
|
||||||
|
echo "# older copy" >> script/update-policy
|
||||||
|
echo own > README.md
|
||||||
|
git add README.md script/update-policy
|
||||||
|
git commit -q -m initial
|
||||||
|
}
|
||||||
|
|
||||||
|
new_repo "a first run writes and commits exactly the listed files"
|
||||||
|
echo stray > stray.txt
|
||||||
|
script/update-policy > "$dir/output" 2>&1 || fail "exited non-zero"
|
||||||
|
[ "$(git rev-list --count HEAD)" = 2 ] || fail "made no single commit"
|
||||||
|
[ "$(git show --name-only --format= HEAD | sort)" = \
|
||||||
|
"$(echo "$LISTED" | tr ' ' '\n' | sort)" ] || fail "commit holds other files"
|
||||||
|
cmp -s docs/REPO_POLICIES.md "$PROMPTS/prompts/REPO_POLICIES.md" ||
|
||||||
|
fail "REPO_POLICIES.md differs"
|
||||||
|
[ -x script/update-policy ] || fail "script not executable"
|
||||||
|
[ "$(git status --porcelain)" = "?? stray.txt" ] || fail "tree not clean"
|
||||||
|
|
||||||
|
scenario="a second run commits nothing"
|
||||||
|
script/update-policy > "$dir/output" 2>&1 || fail "exited non-zero"
|
||||||
|
[ "$(git rev-list --count HEAD)" = 2 ] || fail "made a commit"
|
||||||
|
grep -q "nothing to commit" "$dir/output" || fail "did not say so"
|
||||||
|
|
||||||
|
new_repo "a failed fetch writes nothing"
|
||||||
|
WGET_FAIL=prompts/CODE_STYLEGUIDE.md script/update-policy > "$dir/output" 2>&1 &&
|
||||||
|
fail "exited zero"
|
||||||
|
grep -q "cannot fetch" "$dir/output" || fail "did not say cannot fetch"
|
||||||
|
[ ! -e docs ] || fail "wrote docs/"
|
||||||
|
[ -z "$(git status --porcelain)" ] || fail "tree changed"
|
||||||
|
|
||||||
|
new_repo "an uncommitted change to a listed file stops the script"
|
||||||
|
mkdir docs
|
||||||
|
echo mine > docs/REPO_POLICIES.md
|
||||||
|
script/update-policy > "$dir/output" 2>&1 && fail "exited zero"
|
||||||
|
[ "$(cat docs/REPO_POLICIES.md)" = mine ] || fail "overwrote the change"
|
||||||
|
|
||||||
|
new_repo "the prompts repo itself is refused"
|
||||||
|
mkdir prompts
|
||||||
|
echo source > prompts/REPO_POLICIES.md
|
||||||
|
script/update-policy > "$dir/output" 2>&1 && fail "exited zero"
|
||||||
|
[ ! -e docs ] || fail "wrote docs/"
|
||||||
|
|
||||||
|
echo "update-policy tests passed"
|
||||||
Reference in new issue
Block a user