-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-build-artifacts.sh
executable file
·107 lines (98 loc) · 2.6 KB
/
generate-build-artifacts.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
#!/usr/bin/env bash
# Generate the project build artifacts
#
# Copyright 2024 林博仁(Buo-ren Lin) <[email protected]>
# SPDX-License-Identifier: CC-BY-SA-4.0 OR LicenseRef-Apache-2.0-If-Not-Used-In-Template-Projects
set \
-o errexit \
-o nounset
script="${BASH_SOURCE[0]}"
if ! script="$(
realpath \
--strip \
"${script}"
)"; then
printf \
'Error: Unable to determine the absolute path of the program.\n' \
1>&2
exit 1
fi
script_dir="${script%/*}"
project_dir="${script_dir%/*}"
project_dirname="${project_dir##*/}"
if ! test -e "${script_dir}/venv"; then
printf \
'Info: Initializing the Python virtual environment...\n'
if ! python3 -m venv "${script_dir}/venv"; then
printf \
'Error: Unable to initialize the Python virtual environment.\n' \
1>&2
exit 2
fi
fi
printf \
'Info: Activating the Python virtual environment...\n'
# Out of scope
# shellcheck source=/dev/null
if ! source "${script_dir}/venv/bin/activate"; then
printf \
'Error: Unable to activate the Python virtual environment.\n' \
1>&2
exit 2
fi
printf \
'Info: Installing git-archive-all...\n'
if ! pip show git-archive-all &>/dev/null; then
if ! pip install git-archive-all; then
printf \
'Error: Unable to install git-archive-all.\n' \
1>&2
exit 2
fi
fi
printf \
'Info: Determining the build datestamp...\n'
if ! datestamp="$(date +%Y%m%d-%H%M%S)"; then
printf \
'Error: Unable to determine the build datestamp.\n' \
1>&2
exit 2
fi
printf \
'Info: Determining the project version...\n'
git_describe_opts=(
--always
--dirty
--tags
)
if ! version_describe="$(
git describe \
"${git_describe_opts[@]}"
)"; then
version_describe="unknown-${datestamp}"
printf \
'Warning: Unable to determine the project version, will use "%s" as a fallback.\n' \
"${version_describe}" \
1>&2
fi
project_version="${version_describe#v}"
printf \
'Info: Generating the project archive...\n'
project_id="${CI_PROJECT_NAME:-"${PROJECT_ID:-"${project_dirname}"}"}"
release_id="${project_id}-${project_version}"
git_archive_all_opts=(
# Add an additional layer of folder for containing the archive
# contents
--prefix="${release_id}/"
)
if ! \
git-archive-all \
"${git_archive_all_opts[@]}" \
"${release_id}.tar.gz"; then
printf \
'Error: Unable to generate the project archive.\n' \
1>&2
exit 2
fi
printf \
'Info: Operation completed without errors.\n'