Repository navigation
feat(dolt): persist beads_global to GitHub on every dolt commit #1800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,47 @@ | ||||||||||||||||||
| #!/usr/bin/env bash | ||||||||||||||||||
| # @git@, @mirrorDir@, @remoteUrl@, @userEmail@ are substituted by pkgs.replaceVars. | ||||||||||||||||||
| # `bd` is resolved via PATH (user-installed in ~/.local/bin). | ||||||||||||||||||
| # | ||||||||||||||||||
| # Triggered by launchd/systemd when the dolt manifest changes. Exports the | ||||||||||||||||||
| # full beads_global database to JSONL and pushes it to refs/heads/main of | ||||||||||||||||||
| # the beads GitHub repo so the data renders in the GitHub UI. Dolt's native | ||||||||||||||||||
| # git+https push only writes refs/dolt/data, which GitHub does not render. | ||||||||||||||||||
|
|
||||||||||||||||||
| set -euo pipefail | ||||||||||||||||||
|
|
||||||||||||||||||
| MIRROR="@mirrorDir@" | ||||||||||||||||||
| REMOTE="@remoteUrl@" | ||||||||||||||||||
| GIT="@git@/bin/git" | ||||||||||||||||||
| USER_EMAIL="@userEmail@" | ||||||||||||||||||
|
|
||||||||||||||||||
| export PATH="/etc/profiles/per-user/${USER}/bin:${HOME}/.nix-profile/bin:${HOME}/.local/bin:/run/current-system/sw/bin:/usr/bin:/bin" | ||||||||||||||||||
|
|
||||||||||||||||||
| if ! command -v bd >/dev/null 2>&1; then | ||||||||||||||||||
| echo "bd not on PATH; cannot export beads database" >&2 | ||||||||||||||||||
| exit 1 | ||||||||||||||||||
| fi | ||||||||||||||||||
|
|
||||||||||||||||||
| mkdir -p "$(dirname "${MIRROR}")" | ||||||||||||||||||
|
|
||||||||||||||||||
| if [ ! -d "${MIRROR}/.git" ]; then | ||||||||||||||||||
| "${GIT}" clone --depth 1 "${REMOTE}" "${MIRROR}" | ||||||||||||||||||
| fi | ||||||||||||||||||
|
|
||||||||||||||||||
| cd "${MIRROR}" | ||||||||||||||||||
| "${GIT}" fetch --depth 1 origin main | ||||||||||||||||||
| "${GIT}" reset --hard origin/main | ||||||||||||||||||
|
|
||||||||||||||||||
| bd --global export --all >issues.jsonl.tmp | ||||||||||||||||||
| mv issues.jsonl.tmp issues.jsonl | ||||||||||||||||||
|
|
||||||||||||||||||
| if "${GIT}" diff --quiet -- issues.jsonl; then | ||||||||||||||||||
| echo "no JSONL changes; skipping commit" | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. First-run bug: bootstrap commit is silently skipped. At this point Reproducer: Since the script's first effective run on any fresh machine starts with a mirror that doesn't yet contain Fix: stage first, then check the index: "${GIT}" add issues.jsonl
if "${GIT}" diff --cached --quiet -- issues.jsonl; then
echo "no JSONL changes; skipping commit"
exit 0
fiVerified: after
Suggested change
|
||||||||||||||||||
| exit 0 | ||||||||||||||||||
| fi | ||||||||||||||||||
|
|
||||||||||||||||||
| "${GIT}" add issues.jsonl | ||||||||||||||||||
| "${GIT}" \ | ||||||||||||||||||
| -c "user.name=beads-backup" \ | ||||||||||||||||||
| -c "user.email=${USER_EMAIL}" \ | ||||||||||||||||||
| commit -m "chore(beads): refresh issues.jsonl snapshot" | ||||||||||||||||||
| "${GIT}" push origin main | ||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| #!/usr/bin/env bash | ||
| # shellcheck disable=SC2329 | ||
|
|
||
| Describe 'home-manager/services/dolt/backup-dolt-main.sh' | ||
| SCRIPT="$PWD/home-manager/services/dolt/backup-dolt-main.sh" | ||
|
|
||
| Describe 'script properties' | ||
| It 'uses bash shebang' | ||
| When run bash -c "head -1 '$SCRIPT'" | ||
| The output should include '#!/usr/bin/env bash' | ||
| End | ||
|
|
||
| It 'uses strict mode' | ||
| When run bash -c "grep 'set -euo pipefail' '$SCRIPT'" | ||
| The output should include 'set -euo pipefail' | ||
| End | ||
|
|
||
| It 'passes bash syntax check after stripping placeholders' | ||
| When run bash -c "sed 's|@[A-Za-z_][A-Za-z0-9_]*@|/usr|g' '$SCRIPT' | bash -n" | ||
| The status should be success | ||
| End | ||
| End | ||
|
|
||
| Describe 'placeholder substitutions' | ||
| It 'references @git@' | ||
| When run bash -c "grep '@git@' '$SCRIPT'" | ||
| The output should include '@git@' | ||
| End | ||
|
|
||
| It 'references @mirrorDir@' | ||
| When run bash -c "grep '@mirrorDir@' '$SCRIPT'" | ||
| The output should include '@mirrorDir@' | ||
| End | ||
|
|
||
| It 'references @remoteUrl@' | ||
| When run bash -c "grep '@remoteUrl@' '$SCRIPT'" | ||
| The output should include '@remoteUrl@' | ||
| End | ||
|
|
||
| It 'references @userEmail@' | ||
| When run bash -c "grep '@userEmail@' '$SCRIPT'" | ||
| The output should include '@userEmail@' | ||
| End | ||
| End | ||
|
|
||
| Describe 'preflight checks' | ||
| It 'requires bd on PATH' | ||
| When run bash -c "grep 'command -v bd' '$SCRIPT'" | ||
| The output should include 'command -v bd' | ||
| End | ||
|
|
||
| It 'extends PATH for Nix profiles and user-local bins' | ||
| When run bash -c "grep 'export PATH=' '$SCRIPT'" | ||
| The output should include '.nix-profile/bin' | ||
| End | ||
| End | ||
|
|
||
| Describe 'mirror checkout management' | ||
| It 'creates the mirror parent directory' | ||
| When run bash -c "grep 'mkdir -p' '$SCRIPT'" | ||
| The output should include 'mkdir -p' | ||
| End | ||
|
|
||
| It 'clones the remote when the mirror is missing' | ||
| When run bash -c "grep 'clone --depth 1' '$SCRIPT'" | ||
| The output should include 'clone --depth 1' | ||
| End | ||
|
|
||
| It 'resets the mirror to origin/main before exporting' | ||
| When run bash -c "grep 'reset --hard origin/main' '$SCRIPT'" | ||
| The output should include 'reset --hard origin/main' | ||
| End | ||
| End | ||
|
|
||
| Describe 'export and push' | ||
| It 'exports the full beads dataset' | ||
| When run bash -c "grep -- 'bd --global export --all' '$SCRIPT'" | ||
| The output should include 'bd --global export --all' | ||
| End | ||
|
|
||
| It 'writes to a temporary file before renaming' | ||
| When run bash -c "grep 'issues.jsonl.tmp' '$SCRIPT'" | ||
| The output should include 'issues.jsonl.tmp' | ||
| End | ||
|
|
||
| It 'skips commit when JSONL is unchanged' | ||
| When run bash -c "grep -- 'diff --quiet' '$SCRIPT'" | ||
| The output should include 'diff --quiet' | ||
| End | ||
|
|
||
| It 'commits with a chore prefix' | ||
| When run bash -c "grep -- 'chore(beads)' '$SCRIPT'" | ||
| The output should include 'chore(beads)' | ||
| End | ||
|
|
||
| It 'pushes to origin main' | ||
| When run bash -c "grep 'push origin main' '$SCRIPT'" | ||
| The output should include 'push origin main' | ||
| End | ||
| End | ||
|
|
||
| End |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Latent: mirror never picks up a changed
remoteUrl.The
git cloneis gated by[ ! -d "${MIRROR}/.git" ], and nothing later callsgit remote set-url. Because the mirror lives in~/.cache/beads-jsonl-mirror(persisted across home-manager rebuilds), any future change toremoteUrlindefault.nix(rename, fork, switch to SSH) will be silently ignored — fetch/push keep hitting whatever URL is baked into the existing.git/config.Trigger condition: changing
remoteUrlinhome-manager/services/dolt/default.nixwhile the cache directory already exists.Consequence: push silently goes to the wrong repo or fails with a 404/permission error until the user manually
rm -rf ~/.cache/beads-jsonl-mirror.Fix: make it idempotent by always reconciling the URL after the clone gate, e.g.: