-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcreate.sh
executable file
·70 lines (60 loc) · 1.59 KB
/
create.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
#!/bin/bash
# Creates specified trusted artifacts
set -o errexit
set -o nounset
set -o pipefail
tar_opts=-czf
if [[ -v DEBUG ]]; then
tar_opts=-cvzf
set -o xtrace
fi
# contains {result path}={artifact source path} pairs
artifact_pairs=()
while [[ $# -gt 0 ]]; do
case $1 in
--store)
store="$2"
shift
shift
;;
--results)
result_path="$2"
shift
shift
;;
-*)
echo "Unknown option $1"
exit 1
;;
*)
artifact_pairs+=("$1")
shift
;;
esac
done
for artifact_pair in "${artifact_pairs[@]}"; do
result_path="${artifact_pair/=*}"
path="${artifact_pair/*=}"
if [ -f "${path}/.skip-trusted-artifacts" ]; then
echo WARN: found skip file in "${path}"
continue
fi
archive="$(mktemp).tar.gz"
log "creating tar archive %s with files from %s" "${archive}" "${path}"
if [ ! -r "${path}" ]; then
# non-existent paths result in empty archives
tar "${tar_opts}" "${archive}" --files-from /dev/null
elif [ -d "${path}" ]; then
# archive the whole directory
tar "${tar_opts}" "${archive}" -C "${path}" .
else
# archive a single file
tar "${tar_opts}" "${archive}" -C "${path%/*}" "${path##*/}"
fi
sha256sum_output="$(sha256sum "${archive}")"
digest="${sha256sum_output/ */}"
artifact="${store}/sha256-${digest}.tar.gz"
mv "${archive}" "${artifact}"
echo -n "file:sha256-${digest}" > "${result_path}"
echo Created artifact from "${path} (sha256:${digest})"
done