summaryrefslogtreecommitdiff
path: root/hooks
diff options
context:
space:
mode:
authorVivien Kraus <vivien@planete-kraus.eu>2020-01-01 00:00:00 +0100
committerVivien Kraus <vivien@planete-kraus.eu>2021-06-19 15:36:55 +0200
commit443c2c3357e491da1b520d3979798092cf2e6fb2 (patch)
treeb0349aa58c588f15ae809235df8670e8af4870a0 /hooks
parent0e29ddc3c41870e14da87770a429a94f80dd4110 (diff)
Set up the project infrastructure
Diffstat (limited to 'hooks')
-rw-r--r--hooks/ChangeLog8
-rwxr-xr-xhooks/update58
2 files changed, 66 insertions, 0 deletions
diff --git a/hooks/ChangeLog b/hooks/ChangeLog
new file mode 100644
index 0000000..2a86088
--- /dev/null
+++ b/hooks/ChangeLog
@@ -0,0 +1,8 @@
+2020-12-04 Vivien Kraus <vivien@planete-kraus.eu>
+
+ * update: build with 4 cores
+
+2020-11-25 Vivien Kraus <vivien@planete-kraus.eu>
+
+ * pre-commit: Check that the code is indented in the pre-commit hook.
+
diff --git a/hooks/update b/hooks/update
new file mode 100755
index 0000000..1fc463d
--- /dev/null
+++ b/hooks/update
@@ -0,0 +1,58 @@
+#!/bin/sh
+
+refname="$1"
+oldrev="$2"
+newrev="$3"
+zero=$(guix environment --ad-hoc git -- git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')
+span="^$oldrev $newrev"
+if test "x$oldrev" = "x$zero"
+then
+ >&2 echo "Creating a new branch, $refname..."
+ span="$newrev"
+fi
+
+if test "x$newrev" = "x$zero"
+then
+ >&2 echo "Deleting a branch, that's OK."
+ exit 0
+fi
+
+if test "x$refname" = "xrefs/notes/dist"
+then
+ >&2 echo "Error: the server does not accept dist notes."
+ exit 1
+fi
+
+>&2 echo "Checking all refs in range $span."
+
+for ref in $(guix environment --ad-hoc git -- git rev-list $span)
+do
+ # If there is not already a note on the refs/notes/dist ref, then we
+ # should run the CI.
+ >&2 echo "Checking new commit $ref."
+ if git notes --ref="refs/notes/dist" list "$ref"
+ then
+ >&2 echo "CI already ran for $ref, skipping."
+ else
+ >&2 echo "This commit has not seen CI yet."
+ CLONEREPO=$(mktemp -d 2>/dev/null || mktemp -d -t "clone")
+ REPO=$(pwd)
+ cd "$CLONEREPO"
+ guix environment --ad-hoc --pure git -- git clone "$REPO" .
+ guix environment --ad-hoc --container git -- git checkout "$ref"
+ guix environment --ad-hoc --container git -- git checkout-index -a -f --prefix=source/
+ if OUTCOME=$(guix build -c 4 -L guix -f ci.scm)
+ then
+ cd $REPO
+ export BLOB="$(git hash-object -w $OUTCOME/*.tar.gz)"
+ >&2 echo "Adding blob $BLOB as the results of the CI."
+ guix environment --ad-hoc --container git -- git notes --ref=refs/notes/dist add \
+ --allow-empty -f -C "$BLOB" "$ref"
+ rm -rf $CLONEREPO
+ else
+ cd $REPO
+ rm -rf $CLONEREPO
+ exit 1
+ fi
+ fi
+done