summaryrefslogtreecommitdiff
path: root/hooks/update
blob: 1fc463d16984e0946d07bc3c3efd3b29863d03aa (plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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