-
Notifications
You must be signed in to change notification settings - Fork 303
/
Copy pathgenerate-acknowledgements.sh
executable file
·75 lines (58 loc) · 2.17 KB
/
generate-acknowledgements.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
#!/usr/bin/env bash
set -euo pipefail
echo 'Generating OSS attributions'
# Note that go-licenses output can vary by GOOS and GOARCH.
# https://github.com/google/go-licenses/issues/187
echo "GOOS=${GOOS:-not set}"
echo "GOARCH=${GOARCH:-not set}"
cd $(git rev-parse --show-toplevel)
if [[ ! -f "./go.mod" ]]; then
echo "Couldn't find go.mod - are you in the agent repository?"
exit 1
fi
# Ensure modules are downloaded
go mod download
# Get go-licenses tool
if ! command -v go-licenses >/dev/null; then
go install github.com/google/go-licenses@latest
GO_LICENSES="$(go env GOPATH)/bin/go-licenses"
else
GO_LICENSES="$(command -v go-licenses)"
fi
# Create temporary directory and file
# TEMPFILE is not in TEMPDIR, because this causes infinite recursion later on.
export TEMPDIR="$(mktemp -d /tmp/generate-acknowledgements.XXXXXX)"
export TEMPFILE="$(mktemp /tmp/acknowledgements.XXXXXX)"
trap "rm -fr ${TEMPDIR} ${TEMPFILE}" EXIT
"${GO_LICENSES}" save . --save_path="${TEMPDIR}" --force
# Build acknowledgements file
cat > "${TEMPFILE}" <<EOF
# Buildkite Agent OSS Attributions
The Buildkite Agent would not be possible without open-source software.
Licenses for the libraries used are reproduced below.
EOF
addfile() {
printf "\n\n---\n\n## %s\n\n\`\`\`\n" "${2:-${1#${TEMPDIR}/}}" >> "${TEMPFILE}"
cat "$1" >> "${TEMPFILE}"
printf "\n\`\`\`\n" >> "${TEMPFILE}"
}
## The Go standard library also counts.
license_path="$(go env GOROOT)/LICENSE"
if [[ ! -f $license_path ]]; then
# Homebrew and/or macOS does it different? Try up a directory.
echo "Could not find Go's LICENSE file at $license_path"
license_path="$(go env GOROOT)/../LICENSE"
fi
if [[ ! -f $license_path ]]; then
echo "Could not find Go's LICENSE file at $license_path"
exit 1
fi
addfile "$license_path" "Go standard library"
# Now add all the modules that go-licenses found.
export -f addfile
find "${TEMPDIR}" -type f -print | sort | xargs -I {} bash -c 'addfile "{}"'
# Finally, gzip the file to reduce output binary size, and move into place
gzip -f "${TEMPFILE}"
mv "${TEMPFILE}.gz" clicommand/ACKNOWLEDGEMENTS.md.gz
echo -e "\nGenerated \033[33mclicommand/ACKNOWLEDGEMENTS.md.gz\033[0m 🧑💼"
exit 0