-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·116 lines (93 loc) · 2.58 KB
/
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
#! ./src/oi
# shellcheck shell=bash
# ==============================================================================
# Build distributable archive.
# ==============================================================================
set -o errexit; # Exit script when a command exits with non-zero status
set -o nounset; # Exit script on use of an undefined variable
set -o pipefail; # Return exit status of the last command in the pipe that failed
# ==============================================================================
readonly OUT_DIR="${PWD}/dist";
readonly TMP_DIR="${PWD}/tmp/build/oi";
FILE_NAME="oi";
VERSION="";
function build::cleanup {
#
# Cleanup temporary files after a build has completed.
#
rm -rf "$(dirname "${TMP_DIR}")";
}
function build::prep {
#
# Prepare to build archives.
#
rm -rf "${OUT_DIR}" "$(dirname "${TMP_DIR}")";
mkdir -p "${OUT_DIR}";
mkdir -p "${TMP_DIR}";
cp -a "${PWD}/src/." "${TMP_DIR}";
cp -a "${PWD}/LICENSE" "${TMP_DIR}/LICENSE";
}
function build::set-version {
#
# Generate the version file..
#
# Arguments:
# $1 Version to use.
#
local version="${1}";
if [[ -z "${version}" ]]; then
version="0.0.0";
fi
oi::log.info "setting version as ${version}...";
printf '#! /usr/bin/env zsh\n# shellcheck shell=bash\nreadonly OI_VERSION="%s";\nexport OI_VERSION;\n' "${version}" > "${TMP_DIR}/version.sh";
}
function build::tar {
#
# Build tarball.
#
# Arguments:
# $1 Name of the archive file without extension.
#
local extension="tar.gz";
local file_name="${1}";
local out_file="${OUT_DIR}/${file_name}.${extension}";
oi::log.info "creating tarball..."
touch "${out_file}";
pushd "$(dirname "${TMP_DIR}")";
tar --exclude="\*/.\*" -czvf "${out_file}" ./; # cspell:ignore czvf
popd;
oi::log.success "created ${out_file}";
}
function build::zip {
#
# Build zip archive.
#
# Arguments:
# $1 Name of the archive file without extension.
#
local extension="zip";
local file_name="${1}";
local out_file="${OUT_DIR}/${file_name}.${extension}";
oi::log.info "creating zip archive..."
pushd "$(dirname "${TMP_DIR}")";
zip -r "${out_file}" ".";
popd;
oi::log.success "created ${out_file}";
}
while [[ "${1:-}" != "" ]]; do
case $1 in
*)
VERSION="${1}";
shift;
;;
esac
done
if [[ -n "${VERSION}" ]]; then
FILE_NAME="${FILE_NAME}-${VERSION}";
fi
build::prep;
build::set-version "${VERSION}";
build::tar "${FILE_NAME}";
build::zip "${FILE_NAME}";
build::cleanup
oi::log.success "build completed! distribution artifacts can be found in ${OUT_DIR}"