summaryrefslogtreecommitdiff
path: root/hooks/update
blob: 7ffc5ce872c53082caca12cffbf9556957993971 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/sh

# disfluid, implementation of the Solid specification
# Copyright (C) 2020, 2021  Vivien Kraus

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.

# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

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$refname" != "xrefs/heads/master"
then
    >&2 echo "No CI for $refname, it’s not master"
    exit 0
fi

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

>&2 echo "Checking all refs in range $span."

CHANNEL=$(mktemp -d 2>/dev/null || mktemp -d -t "channel")
>&2 echo "The channel is in $CHANNEL."

cat > "$CHANNEL/guix-channels-for-build.scm" <<EOF
(list (channel
       (name 'guix)
       (url "https://git.savannah.gnu.org/git/guix.git")
       (introduction (make-channel-introduction
		      "9edb3f66fd807b096b48283debdcddccfea34bad"
		      (openpgp-fingerprint
		       "BBB0 2DDF 2CEA F6A8 0D1D  E643 A2A0 6DF2 A33A 54FA")))))
EOF

for ref in $(guix time-machine -C "$CHANNEL/guix-channels-for-build.scm" \
                  -- environment --ad-hoc git -- git rev-list --reverse $span)
do
    >&2 echo "Checking new commit $ref."
    if test "x$ref" = "x0e29ddc3c41870e14da87770a429a94f80dd4110"
    then
	>&2 echo "This is the root, skipping."
    else
	>&2 echo "Running CI for $ref..."
	guix time-machine -C "$CHANNEL/guix-channels-for-build.scm" \
             -- environment --ad-hoc git \
             -- git archive "-o" "$CHANNEL/source.tar.gz" "$ref" guix ci.scm || exit 1
        (cd "$CHANNEL" ; \
         rm -rf "source" ; \
         mkdir "source" ; \
         cd "source" ; \
         guix time-machine -C "$CHANNEL/guix-channels-for-build.scm" \
              -- environment --ad-hoc tar \
              -- tar xf ../source.tar.gz)
	export CI_REF="$ref"
	if OUTCOME=$(guix time-machine -C "$CHANNEL/guix-channels-for-build.scm" \
                          -- build -L "$CHANNEL/source/guix" -f "$CHANNEL/source/ci.scm")
	then
	    >&2 echo "CI ran: $OUTCOME."
	else
	    rm -rf $CHANNEL
	    exit 1
	fi
    fi
done

rm -rf $CHANNEL