forked from kisspuppet/puppet-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish.sh
186 lines (165 loc) · 4.45 KB
/
publish.sh
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/bash
work_dir=/tmp/puppet-publish
echo_title () {
echo
echo
echo "###########################################"
echo "$1"
echo
}
showhelp () {
cat << EOF
This script tags and publishes a module:
- On the Puppet forge, with Maestrodev's Puppet Blacksmith https://github.com/maestrodev/puppet-blacksmith
- On GitHub using local credentials
Usage:
$0 [OPTIONS]
Available OPTIONS
[-m module_name] - Name of the module to publish. Must be in pwd
[-f|--force] [-nf|--no-force] Default: disabled - Enable/Disable forcing of the publising even with test errors
[-b|--bump] [-nb|--no-bump] - Enable/Disable bumping of the module version
[-t|--tag] [-nt|--no-tag] - Enable/Disable tagging of the module
[-fx|--fix] [-nofx|--no-fix] - Enable/Disable removal of optional dependencies for the Forge version
[-c|--check] [-nc|--no-check] - Enable/Disable module testing before any operation
[-s|--sync-master] [-ns|--no-sync-master] - Enable/Disable merging of version branch on master
[-u|--update-collection] [-nu|--no-update-collection] - Enable/Disable automatic update of gitsubmodule on the containing modules collection
EOF
}
force=false
bump=true
tag=true
fix=true
check=true
forge=true
github=true
syncmaster=true
updatecollection=true
while [ $# -gt 0 ]; do
case "$1" in
-m)
module=$2
shift 2 ;;
-f|--force)
force=true
shift ;;
-nf|--no-force)
force=false
shift ;;
-b|--bump)
bump=true
shift ;;
-nb|--no-bump)
bump=false
shift ;;
-t|--tag)
tag=true
shift ;;
-nt|--no-tag)
tag=false
shift ;;
-fx|--fix)
fix=true
shift ;;
-nfx|--no-fix)
fix=false
shift ;;
-c|--check)
check=true
shift ;;
-nc|--no-check)
check=false
shift ;;
-s|--sync-master)
syncmaster=true
shift ;;
-ns|--no-sync-master)
syncmaster=false
shift ;;
-u|--update-collection)
updatecollection=true
shift ;;
-nu|--no-update-collection)
updatecollection=false
shift ;;
esac
done
if [ $module ] ; then
cd $module
fi
modulename=$(basename `pwd`)
branch=$(git branch --no-column | grep '*' | cut -c 3-)
if [ ! -f manifests/init.pp ] ; then
echo_title "SOMETHING WRONG"
echo "I don't find manifests/init.pp "
echo "Run this script from a module directory or specify -m modulename"
showhelp
exit 1
fi
if [ $check == 'true' ] ; then
pwd
rake -f ../Example42-tools/Rakefile_blacksmith module:clean
rake spec_clean
echo_title "LINT TESTS"
rake lint
echo_title "SPEC TESTS"
rake spec
fi
if [ $force != 'true' ] ; then
echo_title "PROCEED? "
read -p "Do you want to continue with tagging and publishing? (Y/n) " answer
answer=${answer:-y}
if [ $answer != 'y' ] ; then
echo "OK, try later!"
exit 1
fi
fi
if [ $bump == 'true' ] ; then
echo_title "VERSION BUMP"
rake -f ../Example42-tools/Rakefile_blacksmith module:bump || exit 1
fi
if [ $tag == 'true' ] ; then
echo_title "MODULE TAG"
rake -f ../Example42-tools/Rakefile_blacksmith module:tag || exit 1
version=$(git describe --abbrev=0 --tags)
git commit -a -m "Release $version"
fi
if [ $forge == 'true' ] ; then
echo_title "PUBLISH TO THE FORGE"
if [ $fix == 'true' ] ; then
[ -d $work_dir ] || mkdir -p $work_dir
cp Modulefile $work_dir/Modulefile.tmp
grep -Ev 'example42/(monitor|firewall)' $work_dir/Modulefile.tmp > Modulefile
fi
rake -f ../Example42-tools/Rakefile_blacksmith module:push || exit 1
if [ $fix == 'true' ] ; then
mv $work_dir/Modulefile.tmp Modulefile
fi
fi
if [ $github == 'true' ] ; then
echo_title "PUBLISH TO GITHUB"
git push origin $branch --tags
fi
if [ $updatecollection == 'true' ] ; then
echo_title "UPDATING SUBMODULE ON COLLECTION REPO"
cd ../
git add $modulename
git commit -m "Updated $modulename $version"
git push
cd $modulename
fi
if [ $syncmaster == 'true' ] ; then
if [ "x$branch" != "xmaster" ] ; then
echo_title "MERGING $branch to master"
read -p "Do you want to merge $branch on master? (Y/n) " answer
answer=${answer:-y}
if [ $answer != 'y' ] ; then
git checkout master
git merge $branch master
read -p "Do you want to merge $branch on master? (Y/n) " answer
answer=${answer:-y}
if [ $answer != 'y' ] ; then
git push origin master
fi
fi
fi
fi