-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathdownload-artifacts.sh
More file actions
57 lines (48 loc) · 1.33 KB
/
download-artifacts.sh
File metadata and controls
57 lines (48 loc) · 1.33 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
#!/bin/bash
set -euo pipefail
if [ "$#" -ne 2 ]; then
echo "Usage: $0 run_id output_path"
exit 1
fi
# Verify GH_TOKEN is set.
if [[ -z "${GH_TOKEN:-}" ]]; then
echo "GH_TOKEN is unset"
exit 1
fi
# Set the gh CLI.
if [[ -z "${GH:-}" ]]; then
GH="gh"
fi
# Script inputs
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
mv ./*-slsa-attestations/* .
rmdir ./*-slsa-attestations
cd -
fi
done