-
Notifications
You must be signed in to change notification settings - Fork 14
/
post-commit
executable file
·39 lines (26 loc) · 1 KB
/
post-commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env bash
if [[ ! -e .git/rebase-merge/done ]]; then
# buffer the output of nix eval through a temporary file
# because that way, we can move it to the new place atomically
# vs clearing the file during eval.
# in other words, this is reimplementing sponge(1)
# why not just use sponge? because this runs in CI (which doesn't have sponge)
tmp="$(mktemp)"
nix eval --raw "git+file:.?ref=HEAD#lib.internal.docs-markdown" > $tmp
# GitHub Actions doesn't seem to have a HEAD ref (???)
if [ $? -ne 0 ]; then
echo "git didn't like the HEAD i gave it; falling back to working directory" >&2
nix eval --raw .#lib.internal.docs-markdown > $tmp
fi
mv $tmp docs.md
nix eval --raw --file fetch-refs.nix > refs.nix
git diff --quiet docs.md refs.nix
if [ $? -ne 0 ]; then
git add docs.md
git add refs.nix
git commit --no-verify --amend --no-edit
# restore the docs from the working directory if you commit with unstaged changes
nix eval --no-warn-dirty --raw .#lib.internal.docs-markdown > $tmp
mv $tmp docs.md
fi
fi