aboutsummaryrefslogtreecommitdiff
path: root/aux/ci
diff options
context:
space:
mode:
Diffstat (limited to 'aux/ci')
-rwxr-xr-xaux/ci/ci-build.sh25
-rwxr-xr-xaux/ci/git-post-receive.sh16
-rwxr-xr-xaux/ci/git-pre-push.sh9
-rwxr-xr-xaux/ci/report.sh52
4 files changed, 75 insertions, 27 deletions
diff --git a/aux/ci/ci-build.sh b/aux/ci/ci-build.sh
index b6769a9..396fbff 100755
--- a/aux/ci/ci-build.sh
+++ b/aux/ci/ci-build.sh
@@ -1,12 +1,20 @@
#!/bin/sh
set -eux
-PACKAGE="$1"
+PROJECT="$1"
LOGS_DIR="$2"
-read -r _ SHA _ # oldrev newrev refname
+SHA="$3"
FILENAME="$(date -Is)-$SHA.log"
LOGFILE="$LOGS_DIR/$FILENAME"
+mkdtemp() {
+ name="$(echo 'mkstemp(template)' |
+ m4 -D template="${TMPDIR:-/tmp}/m4-tmpname.")"
+ rm -f "$name"
+ mkdir "$name"
+ echo "$name"
+}
+
{
echo "Starting CI job at: $(date -Is)"
@@ -26,24 +34,25 @@ EOF
git notes append -m "$NOTE"
cd -
- sh aux/ci/report.sh "$PACKAGE"
- rsync -a public/ "/srv/http/$PACKAGE/" --delete
+ git fetch origin refs/notes/*:refs/notes/*
+ sh aux/ci/report.sh -n "$PROJECT" -o public
+ rsync -av public/ "/srv/http/$PROJECT/" --delete
- printf "\n>>>\n>>> CI logs added as Git note.\n>>>\n>>> Run status was %s" "$STATUS"
+ printf "\n>>>\n>>> CI logs added as Git note."
+ printf "\n>>>\n>>> Run status was %s\n\n" "$STATUS"
}
trap finish EXIT
unset GIT_DIR
REMOTE="$PWD"
- cd "$(mktemp -d)"
+ cd "$(mkdtemp)"
git clone "$REMOTE" .
git config --global user.email git@euandre.org
git config --global user.name 'EuAndreh CI'
- git fetch origin refs/notes/*:refs/notes/*
git annex get ||:
if [ -f aux/guix/with-container.sh ]; then
- RUNNER='./aux/guix/with-container.sh'
+ RUNNER='sh aux/guix/with-container.sh'
else
RUNNER='sh -c'
fi
diff --git a/aux/ci/git-post-receive.sh b/aux/ci/git-post-receive.sh
index ee8075f..92bba73 100755
--- a/aux/ci/git-post-receive.sh
+++ b/aux/ci/git-post-receive.sh
@@ -4,11 +4,19 @@ set -eu
for n in $(seq 0 $((GIT_PUSH_OPTION_COUNT - 1))); do
opt="$(eval "echo \$GIT_PUSH_OPTION_$n")"
if [ "$opt" = skip-ci ] || [ "$opt" = ci-skip ]; then
- printf "\n'%s' option detected, not running ci-build.sh\n\n" "$opt"
+ printf "\n'%s' option detected, not running ci-build.sh\n\n" \
+ "$opt"
exit 0
fi
done
-PACKAGE="$(basename "$PWD" | cut -d. -f1)" # remove .git suffix
-LOGS_DIR="/opt/ci/$PACKAGE/logs"
-"/opt/ci/$PACKAGE/ci-build.sh" "$PACKAGE" "$LOGS_DIR"
+# shellcheck disable=2034
+read -r _oldrev SHA _refname
+
+PROJECT="$(basename "$PWD" | cut -d. -f1)" # remove .git suffix
+LOGS_DIR="/opt/ci/$PROJECT/logs"
+sh "/opt/ci/$PROJECT/ci-build.sh" "$PROJECT" "$LOGS_DIR" "$SHA" ||:
+
+echo 'To retrigger the build, run:'
+echo "cd /srv/http/$PROJECT.git/"
+echo "sh /opt/ci/$PROJECT/ci-build.sh" "$PROJECT" "$LOGS_DIR" "$SHA"
diff --git a/aux/ci/git-pre-push.sh b/aux/ci/git-pre-push.sh
index e73b9b8..eaaa7bd 100755
--- a/aux/ci/git-pre-push.sh
+++ b/aux/ci/git-pre-push.sh
@@ -2,12 +2,13 @@
set -eux
TLD="$(cat aux/tld.txt)"
+. aux/lib.sh
-PACKAGE="$(basename "$PWD")"
-LOGS_DIR="/opt/ci/$PACKAGE/logs"
-REMOTE_GIT_DIR="/srv/git/$PACKAGE.git"
+PROJECT="$(basename "$PWD")"
+LOGS_DIR="/opt/ci/$PROJECT/logs"
+REMOTE_GIT_DIR="/srv/http/$PROJECT.git"
-DESCRIPTION="$(mktemp)"
+DESCRIPTION="$(mkstemp)"
if [ -f description ]
then
cp description "$DESCRIPTION"
diff --git a/aux/ci/report.sh b/aux/ci/report.sh
index 65d3335..7fa3d08 100755
--- a/aux/ci/report.sh
+++ b/aux/ci/report.sh
@@ -1,23 +1,48 @@
#!/bin/sh
set -eu
-PROJECT_UC="$1"
+TLD="$(cat aux/tld.txt)"
+. aux/lib.sh
+
+while getopts 'n:o:' flag; do
+ case "$flag" in
+ n)
+ PROJECT="$OPTARG"
+ ;;
+ o)
+ OUTDIR="$OPTARG"
+ ;;
+ *)
+ exit 2
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+assert_arg() {
+ if [ -z "$1" ]; then
+ echo "Missing $2" >&2
+ exit 2
+ fi
+}
+
+assert_arg "${PROJECT:-}" '-n PROJECT'
+assert_arg "${OUTDIR:-}" '-o OUTDIR'
PASS='✅'
FAIL='❌'
-mkdir -p public/ci-logs public/ci-data
+mkdir -p "$OUTDIR/ci-logs" "$OUTDIR/ci-data"
-OUT="$(mktemp)"
+OUT="$(mkstemp)"
chmod 644 "$OUT"
-git fetch origin refs/notes/*:refs/notes/* ||:
-
for c in $(git notes list | cut -d\ -f2); do
DATA="$(git notes --ref=refs/notes/ci-data show "$c")"
FILENAME="$(echo "$DATA" | cut -d\ -f2)"
- echo "$DATA" > "public/ci-data/$FILENAME"
- git notes --ref=refs/notes/ci-logs show "$c" > "public/ci-logs/$FILENAME"
+ echo "$DATA" > "$OUTDIR/ci-data/$FILENAME"
+ git notes --ref=refs/notes/ci-logs show "$c" \
+ > "$OUTDIR/ci-logs/$FILENAME"
done
cat <<EOF >> "$OUT"
@@ -25,8 +50,10 @@ cat <<EOF >> "$OUT"
<html lang="en">
<head>
<meta charset="UTF-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1" />
+ <meta name="viewport"
+ content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/svg+xml" href="favicon.svg" />
+ <title>CI logs for $PROJECT</title>
<style>
pre {
@@ -36,12 +63,15 @@ cat <<EOF >> "$OUT"
</head>
<body>
<h1>
- CI logs for $PROJECT_UC
+ CI logs for
+ <a href="https://$TLD/$PROJECT/en/">
+ $PROJECT
+ </a>
</h1>
<ul>
EOF
-for f in $(find public/ci-data/ -type f | LANG=C.UTF-8 sort -r); do
+for f in $(find "$OUTDIR/ci-data/" -type f | LANG=C.UTF-8 sort -r); do
DATA="$(cat "$f")"
STATUS="$(echo "$DATA" | cut -d\ -f1)"
FILENAME="$(echo "$DATA" | cut -d\ -f2)"
@@ -67,4 +97,4 @@ cat <<EOF >> "$OUT"
</html>
EOF
-mv "$OUT" public/ci.html
+mv "$OUT" "$OUTDIR/ci.html"