This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·72 lines (57 loc) · 2.4 KB
/
entrypoint.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
#!/bin/sh -e
readonly ACTION_WORKING_DIR='/opt/action'
readonly EXPORT_FILE_NAME='RESULT.md'
# Downloads the latest artifact generated by a workflow ID, identified by its name,
# on the specified repository and branch.
# Parameters:
# $1: repository, in format owner/name
# $2: branch
# $3: numeric ID of the workflow that generated the artifact
# $4: name of the artifact to download
download_latest_artifact() {
echo "Downloading latest $4 artifact"
echo "::debug::Getting API endpoint for latest $4 artifact (repository: $1, branch: $2, workflow ID: $3)"
latest_artifacts_endpoint=$(wget${INPUT_TOKEN:+ --header "Authorization: Bearer $INPUT_TOKEN"} -nv -O - \
"https://api.github.com/repos/$1/actions/runs?branch=$2&status=completed" \
| jq '.workflow_runs | map(select(.workflow_id == '"$3"' and .conclusion == "success"))' \
| jq -r 'sort_by(.updated_at) | reverse | .[0].artifacts_url')
if [ "$latest_artifacts_endpoint" = 'null' ]; then
echo "Could not get the information API endpoint for the latest $4 artifacts" >&2
return 1
fi
echo "::debug::Getting latest $4 artifact download URL from endpoint"
latest_artifact_download_url=$(wget${INPUT_TOKEN:+ --header "Authorization: Bearer $INPUT_TOKEN"} -nv -O - \
"$latest_artifacts_endpoint" \
| jq '.artifacts | map(select(.name == "'"$4"'"))' \
| jq -r '.[0].archive_download_url')
if [ -z "$latest_artifact_download_url" ]; then
echo "Could not get the download URL for the latest $4 artifact" >&2
return 2
fi
temp_file=$(mktemp)
wget --header="Authorization: Bearer $INPUT_TOKEN" -nv -O "$temp_file" "$latest_artifact_download_url"
echo "::debug::Extracting $4 artifact archive"
unzip -o "$temp_file"
rm -f "$temp_file"
}
cd "$ACTION_WORKING_DIR"
case "$INPUT_VERSION" in
'latest')
download_latest_artifact 'sya-ri/PackAdvice' 'master' 23192113 "PackAdvice executable (Linux, x64)"
;;
*)
echo "::error::Not found version: $INPUT_VERSION"
;;
esac
chmod +x packadvice
# Print PackAdvice version
echo '::group::PackAdvice version'
./packadvice --version 2>&1
echo '::endgroup::'
echo "::group::PackAdvice output"
./packadvice --output "$EXPORT_FILE_NAME" "$GITHUB_WORKSPACE/$INPUT_PATH" 2>&1
echo '::endgroup::'
if [ "$INPUT_COMMENT" = 'true' ]; then
node comment.mjs "$EXPORT_FILE_NAME"
fi
cd "$GITHUB_WORKSPACE"