forked from Opetushallitus/koski
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dist.sh
executable file
·53 lines (46 loc) · 1.29 KB
/
dist.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
#!/bin/bash
set -euo pipefail
version=${1:-}
BASE_DIR=$(git rev-parse --show-toplevel)
function usage() {
echo "Usage: `basename $0` <version>"
echo " where <version> is application's new version"
exit 1
}
function buildversiontxt() {
cat >$BASE_DIR/target/dist/web/static/buildversion.txt <<EOL
artifactId=koski
version=$version
vcsRevision=`git rev-parse HEAD`
buildDate=`date`
EOL
}
function create_version() {
mkdir -p $BASE_DIR/target
if [ "$cleandist" = "true" ]; then
echo "cleaning dist directory"
rm -rf $BASE_DIR/target/dist/web && rm -rf $BASE_DIR/target/dist
fi
git archive --format=tar --prefix=dist/ HEAD | (cd $BASE_DIR/target && tar xf -)
cp -rp $BASE_DIR/web/node_modules $BASE_DIR/target/dist/web/ || true
buildversiontxt
if [ "$version" == "local" ]; then
(cd $BASE_DIR/target/dist && make front && mvn install -DskipTests=true)
else
(cd $BASE_DIR/target/dist && mvn versions:set -DnewVersion=$version)
(cd $BASE_DIR/target/dist && make clean front && mvn deploy -DskipTests=true)
git tag $version
git push origin $version
fi
}
if [ -z "$version" ]; then
usage
fi
if GIT_DIR=$BASE_DIR/.git git show-ref --tags | egrep -q "refs/tags/$1$"
then
echo "Version already exists. All versions: "
git tag
exit 1
else
create_version
fi