Skip to content
Merged
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
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[*]
indent_style = tab
indent_size = 2
tab_width = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
73 changes: 73 additions & 0 deletions .github/actions/nix-builder/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Nix remote builder
description: >-
Points nix at the homelab builder through its untrusted `ci` account by
exporting NIX_SSHOPTS and NIX_BUILDER_STORE. Without a key, or when the
builder does not answer, it exports nothing, so callers fall back to building
on the runner: fork PRs never receive secrets, and a homelab that is down
costs runner time rather than a red check that reads like a build failure.
On that fallback, a cache token makes the runner substitute what the builder
already built from its attic cache.
inputs:
ssh-key:
description: Private key of the builder's `ci` account
required: false
default: ""
attic-token:
description: Attic token with pull access to the `builder` cache
required: false
default: ""
runs:
using: composite
steps:
- name: Configure the builder
shell: bash
env:
SSH_KEY: ${{ inputs.ssh-key }}
ATTIC_TOKEN: ${{ inputs.attic-token }}
run: |
set -euo pipefail

# Only on the fallback: a runner whose nix.conf names substituters sends
# that list to the builder, which then swaps its own in-cluster attic
# address for it and stops substituting from the cache.
use_cache() {
[ -n "$ATTIC_TOKEN" ] || return 0
printf 'machine nix.nerds.casa\npassword %s\n' "$ATTIC_TOKEN" |
sudo install -m 600 /dev/stdin /etc/nix/netrc
printf '%s\n' \
"extra-substituters = https://nix.nerds.casa/builder" \
"extra-trusted-public-keys = builder:QmlzOq6fo2gPZ6Vt++ulIK+FCc0r86e8ydE60L9DBys=" |
sudo tee -a /etc/nix/nix.conf >/dev/null
sudo systemctl restart nix-daemon
echo "Substituting from the builder's attic cache"
}

if [ -z "$SSH_KEY" ]; then
echo "No builder key: building on the runner"
use_cache
exit 0
fi

install -d -m 700 ~/.ssh
printf '%s\n' "$SSH_KEY" > ~/.ssh/nix-builder
chmod 600 ~/.ssh/nix-builder
echo "nix-builder.nerds.casa ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBK0AD9BS0GmSgoEVseK4d8cvkoBML+uCyxeMcOjSeN+" \
> ~/.ssh/nix-builder-known-hosts

sshopts="-o UserKnownHostsFile=$HOME/.ssh/nix-builder-known-hosts -o IdentitiesOnly=yes -o IdentityFile=$HOME/.ssh/nix-builder -o BatchMode=yes -o ConnectTimeout=10 -o ServerAliveInterval=15"
store="ssh-ng://ci@nix-builder.nerds.casa"

# A full round trip to the daemon, not just the SSH handshake: a host
# that accepts the connection but whose daemon is wedged would
# otherwise fail every build after it. `timeout` bounds the case
# ConnectTimeout does not — connected, then silent.
if ! NIX_SSHOPTS="$sshopts" timeout 30 nix store info --store "$store" >/dev/null; then
echo "::warning::Nix builder unreachable: building on the runner"
use_cache
exit 0
fi

{
echo "NIX_SSHOPTS=$sshopts"
echo "NIX_BUILDER_STORE=$store"
} >> "$GITHUB_ENV"
100 changes: 100 additions & 0 deletions .github/labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Every label the repository carries, and the one list both workflows read:
# labels.yaml syncs it to GitHub, issue-triage.yaml derives what Claude may
# touch from `group`.
#
# type, area — Claude adds and removes these, on new issues and on a backfill
# status — Claude adds these on new issues only, never on a backfill
# maintainer — a person's call; Claude never adds or removes one
# renovate — set by renovate.json on its own PRs
#
# A description is also Claude's guidance for when the label fits, so it says
# what the label covers rather than restating its name. GitHub caps it at 100
# characters. `aliases` are old names the sync renames in place, keeping the
# label on every issue that already has it. The sync never deletes a label.

# Type
- name: bug
group: type
color: d73a4a
description: Something isn't working
- name: enhancement
group: type
color: a2eeef
description: New feature or request
- name: documentation
group: type
color: 0075ca
description: The wiki, README or other docs are wrong, missing or unclear

# Status
- name: needs-triage
group: status
color: fbca04
description: Not triaged yet; still here after the triage run means the run failed
- name: needs-info
group: status
color: d876e3
description: The report is missing what it takes to act on it
aliases: [question]
- name: possible-duplicate
group: status
color: cfd3d7
description: Looks like an existing issue; a maintainer confirms with `duplicate`
- name: security
group: status
color: b60205
description: A vulnerability or hardening concern

# Area
- name: area/catalog
group: area
color: c5def5
description: "The feeds — root, authors, recently added, search, OpenSearch, links and pagination"
- name: area/downloads
group: area
color: c5def5
description: "Book files and covers — format choice, file names, range requests, missing files"
- name: area/auth
group: area
color: c5def5
description: "Reader tokens and sign-in — Basic auth, the account card, locked or renamed accounts"
- name: area/readers
group: area
color: c5def5
description: "Compatibility with a specific reader app: KOReader, Moon+ Reader, Librera, Marvin, Foliate"
- name: area/deploy
group: area
color: c5def5
description: "Installing and approving the extension, releases, checksums, CI"

# Maintainer
- name: duplicate
group: maintainer
color: cfd3d7
description: This issue or pull request already exists
- name: help wanted
group: maintainer
color: "008672"
description: Extra attention is needed
- name: good first issue
group: maintainer
color: 7057ff
description: Good for newcomers
- name: invalid
group: maintainer
color: e4e669
description: This doesn't seem right
- name: wontfix
group: maintainer
color: ffffff
description: This will not be worked on

# Renovate
- name: dependencies
group: renovate
color: 0366d6
description: Pull requests that update a dependency file
- name: github_actions
group: renovate
color: "000000"
description: Pull requests that update GitHub Actions code
39 changes: 39 additions & 0 deletions .github/scripts/sync-labels.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
# Makes the repository's labels match .github/labels.yml: creates the missing
# ones, updates colour and description on the rest, and renames an alias in
# place so the label stays on every issue that carries it. Never deletes a
# label — one missing from the file is left alone.
#
# Usage: GH_TOKEN=… GH_REPO=owner/repo .github/scripts/sync-labels.sh [labels.yml]
set -euo pipefail

file="${1:-.github/labels.yml}"

existing=$(gh label list --limit 500 --json name --jq '.[].name')
has() { grep -qixF -- "$1" <<<"$existing"; }

while IFS= read -r label; do
name=$(jq -r '.name' <<<"$label")
color=$(jq -r '.color' <<<"$label")
description=$(jq -r '.description' <<<"$label")

if has "$name"; then
gh label edit "$name" --color "$color" --description "$description" >/dev/null
echo "updated $name"
continue
fi

renamed=false
while IFS= read -r alias; do
if [[ -z "$alias" ]] || ! has "$alias"; then continue; fi
gh label edit "$alias" --name "$name" --color "$color" --description "$description" >/dev/null
echo "renamed $alias -> $name"
renamed=true
break
done < <(jq -r '.aliases // [] | .[]' <<<"$label")

if [[ "$renamed" == false ]]; then
gh label create "$name" --color "$color" --description "$description" >/dev/null
echo "created $name"
fi
done < <(yq -o=json '.' "$file" | jq -c '.[]')
26 changes: 26 additions & 0 deletions .github/scripts/triage/comment-issue.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
# Posts the one comment a triage run may leave, on the new issue it was
# started for, and only when a maintainer did not open it.
#
# comment-issue.sh 123 --body "Could you add …"
#
# The body is plain text from the model: at most 1500 characters and no
# @-mention, so an issue cannot make the bot notify somebody. The workflow
# caps this script at one call per run (CLAUDE_CODE_SCRIPT_CAPS).
# shellcheck source=lib.sh
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"

[[ "$EVENT" == issues ]] || die "comments are only posted on a newly opened issue, never on a backfill"
n="${1:-}"
require_issue "$n"
[[ "${2:-}" == --body && $# -eq 3 ]] || die "usage: comment-issue.sh <issue> --body \"text\""
body="$3"

! author_is_maintainer || die "a maintainer opened #$n; it gets labels only, no comment"
[[ -n "${body//[[:space:]]/}" ]] || die "the body is empty"
[[ ${#body} -le 1500 ]] || die "the body is ${#body} characters; keep it under 1500"
! grep -qE '(^|[^[:alnum:]_.])@[[:alnum:]]' <<<"$body" || die "the body must not @-mention anyone"

printf '%s\n\n---\n_Automated triage by [Claude Code](https://claude.ai/code) — a maintainer reads every issue._\n' "$body" |
gh issue comment "$n" --body-file - >/dev/null
echo "commented on #$n"
52 changes: 52 additions & 0 deletions .github/scripts/triage/edit-issue.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash
# Adds and removes triage labels on one issue — nothing else about the issue
# can be changed through it.
#
# edit-issue.sh 123 --add-label area/tv --add-label bug --remove-label area/web
#
# Only labels of the groups this run may touch are accepted (lib.sh
# triage_labels), needs-info only on an issue a maintainer did not open, and
# an issue ends with at most two area labels.
# shellcheck source=lib.sh
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"

n="${1:-}"
shift || die "usage: edit-issue.sh <issue> [--add-label L]… [--remove-label L]…"
require_issue "$n"

add=() remove=()
while [[ $# -gt 0 ]]; do
case "$1" in
--add-label) add+=("${2:?--add-label needs a label}") ;;
--remove-label) remove+=("${2:?--remove-label needs a label}") ;;
*) die "only --add-label and --remove-label are accepted" ;;
esac
shift 2
done
[[ ${#add[@]} -gt 0 || ${#remove[@]} -gt 0 ]] || die "nothing to change"

permitted=$(triage_labels)
for label in "${add[@]}" "${remove[@]}"; do
grep -qxF -- "$label" <<<"$permitted" ||
die "'$label' is not a label this run may change; use one of: $(tr '\n' ' ' <<<"$permitted")"
done

if printf '%s\n' "${add[@]}" | grep -qxF needs-info && author_is_maintainer; then
die "needs-info is never added to an issue a maintainer opened"
fi

current=$(gh issue view "$n" --json labels --jq '.labels[].name')
areas=$({
grep '^area/' <<<"$current" || true
printf '%s\n' "${add[@]}" | grep '^area/' || true
} | sort -u | grep -vxF -f <(printf '%s\n' "${remove[@]}" '') || true)
[[ $(grep -c . <<<"$areas" || true) -le 2 ]] ||
die "issue #$n would end with more than two area labels: $(tr '\n' ' ' <<<"$areas")"

args=()
for label in "${add[@]}"; do args+=(--add-label "$label"); done
for label in "${remove[@]}"; do args+=(--remove-label "$label"); done
gh issue edit "$n" "${args[@]}" >/dev/null

[[ ${#add[@]} -eq 0 ]] || echo "#$n added: ${add[*]}"
[[ ${#remove[@]} -eq 0 ]] || echo "#$n removed: ${remove[*]}"
23 changes: 23 additions & 0 deletions .github/scripts/triage/finish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
# Runs after Claude, outside its reach, over every issue the run covered, and
# drops needs-triage — which only a successful run clears, so an issue still
# carrying it is one the run failed on.
#
# finish.sh 12 34 56
#
# It does not set the native Issue Type: those are an organization feature
# and this repository belongs to a personal account. GitHub answers the
# update with 200 and keeps no type — for the Actions token, with or without
# contents: write, and for the owner's own token alike (all checked on #134).
# The type labels carry it. If the repository moves to an organization, the
# type step needs push access, which belongs in its own job, never in the
# one holding the Claude token.
set -euo pipefail

for n in "$@"; do
labels=$(gh api "repos/$GITHUB_REPOSITORY/issues/$n" --jq '.labels[].name')
if grep -qxF needs-triage <<<"$labels"; then
gh issue edit "$n" --remove-label needs-triage >/dev/null
echo "#$n triaged"
fi
done
57 changes: 57 additions & 0 deletions .github/scripts/triage/gh.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env bash
# Read-only gh for the triage run, scoped to this repository. Adapted from
# anthropics/claude-code-action's scripts/gh.sh.
#
# gh.sh issue view 123 [--comments]
# gh.sh issue list [--state open|closed|all] [--limit N] [--label L] [--search Q]
# gh.sh search issues "query" [--state open|closed] [--limit N]
# shellcheck source=lib.sh
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"

cmd="${1:-} ${2:-}"
shift 2 || die "usage: gh.sh issue view|issue list|search issues …"

case "$cmd" in
"issue view") allowed=(--comments) valued=() ;;
"issue list") allowed=(--state --limit --label --search) valued=(--state --limit --label --search) ;;
"search issues") allowed=(--state --limit) valued=(--state --limit) ;;
*) die "only 'issue view', 'issue list' and 'search issues' are allowed" ;;
esac

positional=() flags=() expect_value=false
for arg in "$@"; do
if [[ "$expect_value" == true ]]; then
flags+=("$arg")
expect_value=false
continue
fi
if [[ "$arg" != -* ]]; then
positional+=("$arg")
continue
fi
flag="${arg%%=*}"
printf '%s\n' "${allowed[@]}" | grep -qxF -- "$flag" || die "flag $flag is not allowed for '$cmd' (allowed: ${allowed[*]})"
flags+=("$arg")
if [[ "$arg" != *=* ]] && printf '%s\n' "${valued[@]}" | grep -qxF -- "$flag"; then
expect_value=true
fi
done
[[ "$expect_value" == false ]] || die "flag ${flags[-1]} needs a value"

case "$cmd" in
"issue view")
[[ ${#positional[@]} -eq 1 && "${positional[0]}" =~ ^[0-9]+$ ]] || die "issue view takes exactly one issue number"
gh issue view "${positional[0]}" "${flags[@]}"
;;
"issue list")
[[ ${#positional[@]} -eq 0 ]] || die "issue list takes no positional argument"
gh issue list "${flags[@]}"
;;
"search issues")
[[ ${#positional[@]} -eq 1 ]] || die "search issues takes exactly one quoted query"
query_lower=$(tr '[:upper:]' '[:lower:]' <<<"${positional[0]}")
[[ "$query_lower" != *repo:* && "$query_lower" != *org:* && "$query_lower" != *user:* ]] ||
die "the query must not carry repo:, org: or user: qualifiers"
gh search issues "${positional[0]}" --repo "$REPO" "${flags[@]}"
;;
esac
Loading
Loading