-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnightly_build.sh
executable file
·99 lines (84 loc) · 2.63 KB
/
nightly_build.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
#! /usr/bin/env sh
# Copyright (C) 2021 Nathan Paul Simons ([email protected])
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Intended to be run nightly, eg in cron:
# m h dom mon dow command
# 0 0 * * * $HOME/Projects/$PROJNAME/nightly_build.sh
# Debugging/error checking options; see the bash manual page for details.
# Set the prompt for trace output.
# This sets the execution trace prompt string (PS4) to the program name
# ($0), "line" and line number ($LINENO) within the program.
if test ${LINENO:-set} != set; then
PS4='$0 line $LINENO: '
else
PS4='$0: '
fi
# Print shell input lines as they are read.
set -o verbose
# Print expanded commands.
set -o xtrace
# Exit immediately if a simple command fails.
set -o errexit
# Don't overwrite existing files.
# NOTE: this only applies to shell-script things like redirection; the
# executables called below will still be able to overwrite files.
set -o noclobber
# Treat unset variables as an error.
set -o nounset
# Fail if any command in a pipeline fails; non-POSIX shell extension.
if test ${BASH_VERSION:-set} != set; then
set -o pipefail
fi
umask 0077
YEAR="`date +'%Y'`"
MONTH="`date +'%m'`"
DAY="`date +'%d'`"
DATE="$YEAR-$MONTH-$DAY"
GITREPO_URI="file:///path/to/repos"
PROJNAME="__TEMPLATE__"
BASEDIRNAME="$PROJNAME-$DATE"
TOPLEVEL="`mktemp -d`"
TMPDIRNAME="$TOPLEVEL/$BASEDIRNAME"
mkdir --parent $TMPDIRNAME;
cd $TMPDIRNAME
# Build and test the $PROJNAME library and unit tests and run them.
git clone --quiet $GITREPO_URI/$PROJNAME/
cd $PROJNAME
sh ./run_tests.sh
cd ../
# Make a backup of this repository and build.
BACKUPDIR="$HOME/Backups/nightly_builds/$YEAR/$MONTH/$DAY"
mkdir \
--parent \
$BACKUPDIR
mv \
--interactive \
--verbose \
$PROJNAME \
$BACKUPDIR/
chmod \
--recursive \
--verbose \
ugo-w \
$BACKUPDIR/$PROJNAME
cd /
rm -Rf $TOPLEVEL
# Local Variables:
# mode: Shell-Script
# sh-indentation: 4
# indent-tabs-mode: nil
# sh-basic-offset: 4
# End:
# vi: fileformat=unix filetype=sh shiftwidth=4 tabstop=4 expandtab