-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci_build.sh
executable file
·158 lines (126 loc) · 4.6 KB
/
ci_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
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
#!/bin/bash
# exit script on any error
set -eo pipefail
RELEASE_ARTEFACTS_DIR="${BUILD_DIR}/release_artefacts"
RELEASE_MANIFEST="${RELEASE_ARTEFACTS_DIR}/release-artefacts.txt"
# Shell Colour constants for use in 'echo -e'
# e.g. echo -e "My message ${GREEN}with just this text in green${NC}"
# shellcheck disable=SC2034
{
RED='\033[1;31m'
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
BLUE='\033[1;34m'
NC='\033[0m' # No Colour
}
create_file_hash() {
local -r file="$1"
local -r hash_file="${file}.sha256"
local dir
dir="$(dirname "${file}")"
local filename
filename="$(basename "${file}")"
echo -e "Creating a SHA-256 hash for file ${GREEN}${filename}${NC} in ${GREEN}${dir}${NC}"
# Go to the dir where the file is so the hash file doesn't contain the full
# path
pushd "${dir}" > /dev/null
sha256sum "${filename}" > "${hash_file}"
popd > /dev/null
echo -e "Created hash file ${GREEN}${hash_file}${NC}, containing:"
echo -e "-------------------------------------------------------"
cat "${hash_file}"
echo -e "-------------------------------------------------------"
}
copy_release_artefact() {
local source="$1"; shift
local dest="$1"; shift
local description="$1"; shift
echo -e "${GREEN}Copying release artefact ${BLUE}${source}${GREEN}" \
"to ${BLUE}${dest}${NC}"
mkdir -p "${RELEASE_ARTEFACTS_DIR}"
cp "${source}" "${dest}"
local filename
if [[ -f "${dest}" ]]; then
filename="$(basename "${dest}")"
else
filename="$(basename "${source}")"
fi
# Add an entry to a manifest file for the release artefacts
echo "${filename} - ${description}" \
>> "${RELEASE_MANIFEST}"
}
# Put all release artefacts in a dir to make it easier to upload them to
# Github releases. Some of them are needed by the stack builds in
# stroom-resources
gather_release_artefacts() {
mkdir -p "${RELEASE_ARTEFACTS_DIR}"
echo "Copying release artefacts to ${RELEASE_ARTEFACTS_DIR}"
# The zip dist config is inside the zip dist. We need the docker dist
# config so stroom-resources can use it.
# Stroom
copy_release_artefact \
"${BUILD_DIR}/CHANGELOG.md" \
"${RELEASE_ARTEFACTS_DIR}/" \
"Change log for this release"
copy_release_artefact \
"${BUILD_DIR}/tag_release.sh" \
"${RELEASE_ARTEFACTS_DIR}/" \
"The script for initiating a release"
copy_release_artefact \
"${BUILD_DIR}/log_change.sh" \
"${RELEASE_ARTEFACTS_DIR}/" \
"The script for recording a change entry"
# Now generate hashes for all the zips
for file in "${RELEASE_ARTEFACTS_DIR}"/*.sh; do
create_file_hash "${file}"
done
}
set_version_and_date() {
local file="$1"; shift
echo -e "${GREEN}Setting BUILD_VERSION to ${BLUE}${BUILD_VERSION}${GREEN}" \
"in file ${BLUE}${file}${NC}"
echo -e "${GREEN}Setting BUILD_DATE to ${BLUE}${BUILD_DATE}${GREEN}" \
"in file ${BLUE}${file}${NC}"
sed \
--in-place'' \
--regexp-extended \
--expression "s/<BUILD_VERSION>/${BUILD_VERSION}/" \
--expression "s/<BUILD_DATE>/${BUILD_DATE}/" \
"${file}"
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Script proper starts here
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# establish what version of stroom we are building
if [ -n "$BUILD_TAG" ]; then
# Tagged commit so use that as our stroom version, e.g. v6.0.0
BUILD_VERSION="${BUILD_TAG}"
else
# No tag so use the branch name as the version, e.g. dev
BUILD_VERSION="${BUILD_BRANCH}"
fi
BUILD_DATE="$(date --iso-8601=seconds)"
pushd "${BUILD_DIR}" > /dev/null
# Dump all the env vars to the console for debugging
echo -e "HOME: [${GREEN}${HOME}${NC}]"
echo -e "PWD: [${GREEN}$(pwd)${NC}]"
echo -e "BUILD_DIR: [${GREEN}${BUILD_DIR}${NC}]"
echo -e "BUILD_COMMIT: [${GREEN}${BUILD_COMMIT}${NC}]"
echo -e "BUILD_BRANCH: [${GREEN}${BUILD_BRANCH}${NC}]"
echo -e "BUILD_TAG: [${GREEN}${BUILD_TAG}${NC}]"
echo -e "BUILD_IS_PULL_REQUEST: [${GREEN}${BUILD_IS_PULL_REQUEST}${NC}]"
echo -e "BUILD_VERSION: [${GREEN}${BUILD_VERSION}${NC}]"
echo -e "RELEASE_ARTEFACTS_DIR: [${GREEN}${RELEASE_ARTEFACTS_DIR}${NC}]"
echo -e "git version: [${GREEN}$(git --version)${NC}]"
ls -l
set_version_and_date "./tag_release.sh"
set_version_and_date "./log_change.sh"
# If it is a tagged build copy all the files needed for the github release
# artefacts
if [ -n "$BUILD_TAG" ]; then
gather_release_artefacts
else
echo -e "${GREEN}Not a release so nothing to do${NC}"
fi
exit 0
# vim:sw=2:ts=2:et: