]> git.openstreetmap.org Git - chef.git/blob - cookbooks/chef/templates/default/post-receive.erb
Bump cookstyle from 7.30.3 to 7.30.4
[chef.git] / cookbooks / chef / templates / default / post-receive.erb
1 #!/bin/zsh
2
3 # DO NOT EDIT - This file is being maintained by Chef
4
5 umask 0002
6 unset GIT_DIR
7
8 knife="/opt/chef/embedded/bin/knife"
9
10 while read oldrev newrev refname
11 do
12   if [[ "$refname" = "refs/heads/master" ]]
13   then
14     cd /var/lib/chef/<%= @repository %>
15
16     rm -f cookbooks/*/metadata.json(N)
17
18     git pull --rebase --quiet
19
20     oldrev=$(git merge-base $oldrev $newrev)
21
22     for change in "${(f)$(git diff --name-status $oldrev..$newrev)}"
23     do
24       action=${change[1]}
25       file=${change[3,-1]}
26
27       if [[ $file == roles/*.rb ]]
28       then
29         case "$action" in
30           A|M) $knife role from file "${file}";;
31           D) $knife role delete -y "${file:t:r}";;
32         esac
33       elif [[ $file == data_bags/*/*.json ]]
34       then
35         case "$action" in
36           A|M) 
37             $knife data bag create "${file:h:t}"
38             $knife data bag from file "${file:h:t}" "${file:t}";;
39           D)
40             $knife data bag delete -y "${file:h:t}" "${file:t:r}";;
41         esac
42       elif [[ $file == cookbooks/* ]]
43       then
44         cookbook="${${file#[^/]*/}%%/*}"
45     
46         if [[ -d "cookbooks/${cookbook}" ]]
47         then
48           updated_cookbooks+=("$cookbook")
49         else
50           deleted_cookbooks+=("$cookbook")
51         fi
52       fi
53     done
54
55     if [[ -n "$updated_cookbooks" ]]
56     then
57       $knife cookbook upload "${(ou)updated_cookbooks[@]}"
58     fi
59
60     if [[ -n "$deleted_cookbooks" ]]
61     then
62       for cookbook in "${(ou)deleted_cookbooks[@]}"
63       do
64         $knife cookbook delete -y "$cookbook"
65       done
66     fi
67   fi
68 done