summaryrefslogtreecommitdiff
path: root/Biz/Ci.sh
blob: c6b1f7aafeda9c9e103e71e8f48d3de45fb05bed (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
#!/usr/bin/env bash
#
# A simple ci that saves its results in a git note, formatted according to
# RFC-2822, more or less.
#
# To run this manually, exec the script. It will by default run the tests for
# HEAD, whatever you currently have checked out.
#
# It would be cool to use a zero-knowledge proof mechanism here to prove that
# so-and-so ran the tests, but I'll have to research how to do that.
#
# ensure we don't exit on bild failure, only on CI script error
  set +e
  set -u
##
  [[ -n $(git status -s) ]] && { echo fail: dirty worktree; exit 1; }
##
  at=$(date -R)
  user=$(git config --get user.name)
  mail=$(git config --get user.email)
##
  commit=$(git notes --ref=ci show HEAD || true)
  if [[ -n "$commit" ]]
  then
    if grep -q "Lint-is: good" <<< "$commit"
    then
      exit 0
    fi
    if grep -q "Test-is: good" <<< "$commit"
    then
      exit 0
    fi
  fi
##
  runlint="$CODEROOT"/_/bin/lint
  [[ ! -f "$runlint" ]] && bild "${BILD_ARGS:-""}" "${CODEROOT:?}"/Biz/Lint.hs
  if "$runlint" "${CODEROOT:?}"/**/*
  then
    lint_result="good"
  else
    lint_result="fail"
  fi
##
  if bild "${BILD_ARGS:-""}" --test "${CODEROOT:?}"/**/*
  then
    test_result="good"
  else
    test_result="fail"
  fi
##
  read -r -d '' note <<EOF
Lint-is: $lint_result
Test-is: $test_result
Test-by: $user <$mail>
Test-at: $at
EOF
##
  git notes --ref=ci append -m "$note"
##
# exit 1 if failure
  [[ ! "$lint_result" == "fail" && ! "$test_result" == "fail" ]]
##