fuzzyworld-tools / files / server / hooks / post-receive
post-receive
| 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. |
| 4 | name=$(basename "$(cd "${GIT_DIR:-.}" && pwd)" .git) |
| 5 | vis=$(git config --get fuzzyworld.visibility) |
| 6 | log="$HOME/fw/logs/$name.log" |
| 7 | mkdir -p "$HOME/fw/logs" |
| 8 | updates=$(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. |
| 14 | if [ "$(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" |
| 23 | fi |
| 24 | |
| 25 | unset GIT_DIR GIT_QUARANTINE_PATH |
| 26 | setsid nohup "$HOME/bin/fw" publish "$name" >> "$log" 2>&1 < /dev/null & |
| 27 | if [ "$vis" = public ]; then |
| 28 | echo "fw: updating https://code.fuzzyworld.net/$name/ in the background (log: ~/fw/logs/$name.log)" |
| 29 | fi |