-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Expand file tree
/
Copy pathpackage.sh
More file actions
executable file
·145 lines (117 loc) · 3.49 KB
/
Copy pathpackage.sh
File metadata and controls
executable file
·145 lines (117 loc) · 3.49 KB
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
#!/usr/bin/env bash
set -e
set -u
set -o pipefail
ROOTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
readonly ROOTDIR
# shellcheck source=SCRIPTDIR/.util/tools.sh
source "${ROOTDIR}/scripts/.util/tools.sh"
# shellcheck source=SCRIPTDIR/.util/print.sh
source "${ROOTDIR}/scripts/.util/print.sh"
function main() {
local stack version cached output profile exclude include
stack="cflinuxfs4"
cached="false"
output="${ROOTDIR}/build/buildpack.zip"
profile=""
exclude=""
include=""
while [[ "${#}" != 0 ]]; do
case "${1}" in
--stack)
stack="${2}"
shift 2
;;
--version)
version="${2}"
shift 2
;;
--cached)
cached="true"
shift 1
;;
--output)
output="${2}"
shift 2
;;
--profile)
profile="${2}"
shift 2
;;
--exclude)
exclude="${2}"
shift 2
;;
--include)
include="${2}"
shift 2
;;
--help|-h)
shift 1
usage
exit 0
;;
"")
# skip if the argument is empty
shift 1
;;
*)
util::print::error "unknown argument \"${1}\""
esac
done
if [[ -z "${version:-}" ]]; then
version=$(cat "${ROOTDIR}/VERSION" 2>/dev/null || echo "0.0.0")
echo "No version specified, using VERSION file: ${version}"
fi
package::buildpack "${version}" "${cached}" "${stack}" "${output}" "${profile}" "${exclude}" "${include}"
}
function usage() {
cat <<-USAGE
package.sh --version <version> [OPTIONS]
Packages the buildpack into a .zip file.
OPTIONS
--help -h prints the command usage
--version <version> -v <version> specifies the version number to use when packaging the buildpack
--cached cache the buildpack dependencies (default: false)
--stack <stack> specifies the stack (default: cflinuxfs4)
--output <file> output file path (default: build/buildpack.zip)
--profile <name> packaging profile from manifest.yml (e.g. minimal, standard)
--exclude <dep1,dep2,...> comma-separated dependency names to exclude (cached only)
--include <dep1,dep2,...> comma-separated dependency names to restore, overriding profile exclusions (cached only)
USAGE
}
function package::buildpack() {
local version cached stack output profile exclude include
version="${1}"
cached="${2}"
stack="${3}"
output="${4}"
profile="${5:-}"
exclude="${6:-}"
include="${7:-}"
mkdir -p "$(dirname "${output}")"
util::tools::buildpack-packager::install --directory "${ROOTDIR}/.bin"
echo "Building buildpack (version: ${version}, stack: ${stack}, cached: ${cached}, output: ${output})"
local stack_flag
stack_flag="--any-stack"
if [[ "${stack}" != "any" ]]; then
stack_flag="--stack=${stack}"
fi
local profile_flag="" exclude_flag="" include_flag=""
[[ -n "${profile}" ]] && profile_flag="--profile=${profile}"
[[ -n "${exclude}" ]] && exclude_flag="--exclude=${exclude}"
[[ -n "${include}" ]] && include_flag="--include=${include}"
local file
file="$(
"${ROOTDIR}/.bin/buildpack-packager" build \
"--version=${version}" \
"--cached=${cached}" \
"${stack_flag}" \
${profile_flag:+"${profile_flag}"} \
${exclude_flag:+"${exclude_flag}"} \
${include_flag:+"${include_flag}"} \
| xargs -n1 | grep -e '\.zip$'
)"
mv "${file}" "${output}"
}
main "${@:-}"