forked from slsa-framework/example-package
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdownload-artifacts.sh
47 lines (39 loc) · 1.21 KB
/
download-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
#!/bin/bash
set -euo pipefail
if [ "$#" -ne 2 ]; then
echo "Usage: $0 run_id output_path"
exit 1
fi
run_id="$1"
output_path="$2"
repo=slsa-framework/example-package
mkdir -p "${output_path}"
artifacts=$($GH api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${repo}/actions/runs/${run_id}/artifacts" \
| jq -r -c '.artifacts')
arr=$(echo "$artifacts" | jq -c '.[]')
for item in ${arr}; do
artifact_id=$(echo "${item}" | jq -r '.id')
artifact_name=$(echo "${item}" | jq -r '.name')
zip_path="${output_path}/${artifact_name}.zip"
$GH api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${repo}/actions/artifacts/${artifact_id}/zip" \
> "${zip_path}"
echo "Downloaded ${zip_path}"
unzip -o "${zip_path}" -d "${output_path}"
rm "${zip_path}"
# This code is for BYOB debugging.
if [[ -e "${output_path}/folder.tgz" ]]; then
cd "${output_path}"
tar xzvf folder.tgz
rm folder.tgz
attestation_folder=$(ls | grep slsa-attestations)
mv "${attestation_folder}"/* .
rmdir "${attestation_folder}"
cd -
fi
done