fuzzyworld

fuzzyworld-tools / files / server / hooks / post-receive

post-receive

1.4 KB · history · blame

1#!/bin/bash
2# Shared post-receive hook for every ~/git/<name>.git (via core.hooksPath).
3# Publishing runs detached, so the push returns at once; output goes to ~/fw/logs/<name>.log.
4name=$(basename "$(cd "${GIT_DIR:-.}" && pwd)" .git)
5vis=$(git config --get fuzzyworld.visibility)
6log="$HOME/fw/logs/$name.log"
7mkdir -p "$HOME/fw/logs"
8updates=$(cat) # stdin: "<old> <new> <ref>" lines
9{ echo "== $(date '+%F %T') push"; echo "$updates"; } >> "$log"
10
11# CI: queue a job for each pushed branch or tag whose commit has a .fw-ci.yml (or, not yet renamed,
12# .gitlab-ci.yml) or a package.json.
13# Runners (runner/fw-runner.py) take jobs from ~/fw/queue/pending/ through server/runner-api.
14if [ "$(git config --get fuzzyworld.ci)" != off ]; then
15 while read -r old new ref; do
16 case "$ref" in refs/heads/*|refs/tags/*) ;; *) continue ;; esac
17 [ "$new" = 0000000000000000000000000000000000000000 ] && continue
18 sha=$(git rev-parse -q --verify "$new^{commit}") || continue
19 git cat-file -e "$sha:.fw-ci.yml" 2>/dev/null || git cat-file -e "$sha:.gitlab-ci.yml" 2>/dev/null ||
20 git cat-file -e "$sha:package.json" 2>/dev/null || continue
21 "$HOME/bin/fw" ci-queue "$name" "$ref" "$sha" >> "$log" 2>&1
22 done <<< "$updates"
23fi
24
25unset GIT_DIR GIT_QUARANTINE_PATH
26setsid nohup "$HOME/bin/fw" publish "$name" >> "$log" 2>&1 < /dev/null &
27if [ "$vis" = public ]; then
28 echo "fw: updating https://code.fuzzyworld.net/$name/ in the background (log: ~/fw/logs/$name.log)"
29fi