forked from theforeman/foreman-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release_module
executable file
·63 lines (55 loc) · 2.37 KB
/
release_module
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
#!/bin/bash -e
die() {
echo $* >&2
exit 1
}
if [ $# -ne 2 -o x$1 = "x-h" -o x$1 = "x--help" ]; then
echo "usage: $0 <module name> <version>"
echo
echo " update CHANGELOG.md before running this script and git add or commit it"
echo " only local changes will be made, no git pushes"
echo
die "incorrect arguments supplied"
fi
MODULE=$1
VERSION=$2
test -d modules/$MODULE || die "no such module $MODULE"
test -e modules/$MODULE/CHANGELOG.md || die "no CHANGELOG.md found in $MODULE"
test -e modules/$MODULE/Modulefile || test -e modules/$MODULE/metadata.json || die "no Modulefile/metadata.json found in $MODULE"
if test -e modules/$MODULE/Modulefile; then
grep -q '^version' modules/$MODULE/Modulefile || die "no version found in Modulefile"
else
grep -q '"version":' modules/$MODULE/metadata.json || die "no version found in metadata.json"
fi
grep -xq "## ${VERSION}" modules/$MODULE/CHANGELOG.md || die "no '## ${VERSION}' found in CHANGELOG. Do this first, and add to your index or commit it."
(cd modules/$MODULE && git rev-parse $VERSION >/dev/null 2>&1) && die "tag for ${VERSION} already exists"
branch=$(cd modules/$MODULE && git rev-parse --abbrev-ref HEAD)
[[ x${branch} = xmaster || ${branch} =~ ^[0-9.]+-stable$ ]] || die "$MODULE isn't on master or stable branch"
(cd modules/$MODULE && [ x$(git diff --shortstat -- CHANGELOG.md | wc -l) = x0 ] ) || die "CHANGELOG.md isn't in the git index or committed"
[[ "$VERSION" =~ ^[0-9\.]+$ ]] || die "invalid version number"
type puppet >/dev/null 2>&1 || die "puppet not installed"
TMPDIR=$(mktemp -d)
trap "rm -rf $TMPDIR" EXIT ERR
pushd modules/$MODULE >/dev/null
if test -e Modulefile; then
sed -i "/^version/ s/ .*/ '${VERSION}'/" Modulefile
git add Modulefile
else
sed -i "/\"version\"/ s/\"[0-9\.]\+\"/\"${VERSION}\"/" metadata.json
git add metadata.json
fi
git ci -m "Release ${VERSION}"
git tag -m "Release ${VERSION}" $VERSION
git archive $VERSION | (cd $TMPDIR && tar -xf -)
popd >/dev/null
# Use a clean copy, as p-m-build isn't good at ignoring files
puppet module build $TMPDIR
PKGS=$(cd $TMPDIR/pkg && echo *.tar.gz)
cp -a $TMPDIR/pkg/* pkg/
echo
echo Built pkg/$PKGS
echo
echo 'Next steps:'
echo " 1. (cd modules/${MODULE} && git push origin && git push origin ${VERSION})"
echo " 2. visit http://forge.puppetlabs.com/theforeman/${MODULE} and log in"
echo " 3. click Upload a New Release, and upload $(pwd)/pkg/$PKGS"