-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathgit-post-receive-hook-notes
More file actions
executable file
·42 lines (38 loc) · 1.53 KB
/
Copy pathgit-post-receive-hook-notes
File metadata and controls
executable file
·42 lines (38 loc) · 1.53 KB
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
#!/bin/bash -e
# Simple post-receive hook that triggers a laminar run
# for every commit pushed to every branch, and annotates
# the commit with the run number using a git note.
# On the cloned repository, useful config is
# git config --add remote.origin.fetch "+refs/notes/*:refs/notes/*"
# to automatically fetch all notes from the origin, and
# git config --add notes.displayRef "refs/notes/*"
# to display all notes in the git log by default
# The laminar job to trigger
LAMINAR_JOB=my-project
# Default notes ref is refs/notes/commits
NOTES_REF=refs/notes/ci
# For each ref pushed...
while read old new ref; do
# Skip tags, notes, etc. Only do heads.
# Extend this to only trigger on specific branches.
if [[ $ref != refs/heads/* ]]; then
continue
fi
# Otherwise, for each new commit in the ref...
# (to only trigger on the newest, set commit=$new and delete the loop)
git rev-list $([[ $old =~ ^0+$ ]] && echo $new || echo $old..$new) | while read commit; do
# Queue the laminar run
run=$(laminarc queue $LAMINAR_JOB commit=$commit ref=$ref)
echo "Started Laminar $run for commit $commit to ref $ref"
# Add a git note about the run
blob=$(echo -n "Laminar-Run: $run" | git hash-object -w --stdin)
if last_note=$(git show-ref -s $NOTES_REF); then
git read-tree $last_note
p_arg=-p
fi
git update-index --add --cacheinfo 100644 $blob $commit
tree=$(git write-tree)
new_note=$(echo "Notes added by post-receive hook" | git commit-tree $tree $p_arg $last_note)
git update-ref $NOTES_REF $new_note $last_note
done
done