1
- #! /bin/bash
1
+ #! /usr/ bin/env bash
2
2
3
3
set -xe
4
4
5
+ if [ -z " ${INPUT_GITHUB_TOKEN} " ] ; then
6
+ echo " Consider setting a GITHUB_TOKEN to prevent GitHub api rate limits." >&2
7
+ fi
8
+
5
9
TFSEC_VERSION=" "
6
- if [ " $INPUT_TFSEC_VERSION " != " latest" ]; then
10
+ if [ " $INPUT_TFSEC_VERSION " != " latest" ] && [ -n " $INPUT_TFSEC_VERSION " ] ; then
7
11
TFSEC_VERSION=" /tags/${INPUT_TFSEC_VERSION} "
12
+ else
13
+ TFSEC_VERSION=" /latest"
8
14
fi
9
15
10
- wget -O - -q " $( wget -q https://api.github.com/repos/aquasecurity/tfsec/releases${TFSEC_VERSION} -O - | grep -m 1 -o -E " https://.+?tfsec-linux-amd64" | head -n1) " > tfsec-linux-amd64
11
- wget -O - -q " $( wget -q https://api.github.com/repos/aquasecurity/tfsec/releases${TFSEC_VERSION} -O - | grep -m 1 -o -E " https://.+?tfsec_checksums.txt" | head -n1) " > tfsec.checksums
12
-
13
- grep tfsec-linux-amd64 tfsec.checksums > tfsec-linux-amd64.checksum
14
- sha256sum -c tfsec-linux-amd64.checksum
15
- install tfsec-linux-amd64 /usr/local/bin/tfsec
16
-
17
16
COMMENTER_VERSION=" latest"
18
- if [ " $INPUT_COMMENTER_VERSION " != " latest" ]; then
19
- COMMENTER_VERSION=" tags/${INPUT_COMMENTER_VERSION} "
17
+ if [ " $INPUT_COMMENTER_VERSION " != " latest" ] && [ -n " $INPUT_COMMENTER_VERSION " ]; then
18
+ COMMENTER_VERSION=" /tags/${INPUT_COMMENTER_VERSION} "
19
+ else
20
+ COMMENTER_VERSION=" /latest"
20
21
fi
21
22
22
- wget -O - -q " $( wget -q https://api.github.com/repos/aquasecurity/tfsec-pr-commenter-action/releases/${COMMENTER_VERSION} -O - | grep -o -E " https://.+?commenter-linux-amd64" ) " > commenter-linux-amd64
23
- wget -O - -q " $( wget -q https://api.github.com/repos/aquasecurity/tfsec-pr-commenter-action/releases/${COMMENTER_VERSION} -O - | grep -o -E " https://.+?checksums.txt" ) " > commenter.checksums
23
+ function get_release_assets {
24
+ repo=" $1 "
25
+ version=" $2 "
26
+ args=(
27
+ -sSL
28
+ --header " Accept: application/vnd.github+json"
29
+ )
30
+ [ -n " ${INPUT_GITHUB_TOKEN} " ] && args+=(--header " Authorization: Bearer ${INPUT_GITHUB_TOKEN} " )
31
+ curl " ${args[@]} " " https://api.github.com/repos/$repo /releases${version} " | jq ' .assets[] | { name: .name, download_url: .browser_download_url }'
32
+ }
33
+
34
+ function install_release {
35
+ repo=" $1 "
36
+ version=" $2 "
37
+ binary=" $3 -linux-amd64"
38
+ checksum=" $4 "
39
+ release_assets=" $( get_release_assets " ${repo} " " ${version} " ) "
40
+
41
+ curl -sLo " ${binary} " " $( echo " ${release_assets} " | jq -r " . | select(.name == \" ${binary} \" ) | .download_url" ) "
42
+ curl -sLo " $3 -checksums.txt" " $( echo " ${release_assets} " | jq -r " . | select(.name | contains(\" $checksum \" )) | .download_url" ) "
43
+
44
+ grep " ${binary} " " $3 -checksums.txt" | sha256sum -c -
45
+ install " ${binary} " " /usr/local/bin/${3} "
46
+ }
24
47
25
- grep commenter-linux-amd64 commenter.checksums > commenter-linux-amd64.checksum
26
- sha256sum -c commenter-linux-amd64.checksum
27
- install commenter-linux-amd64 /usr/local/bin/commenter
48
+ install_release aquasecurity/tfsec " ${TFSEC_VERSION} " tfsec tfsec_checksums.txt
49
+ install_release aquasecurity/tfsec-pr-commenter-action " ${COMMENTER_VERSION} " commenter checksums.txt
28
50
29
51
if [ -n " ${GITHUB_WORKSPACE} " ]; then
30
52
cd " ${GITHUB_WORKSPACE} " || exit
@@ -41,5 +63,5 @@ if [ -n "${INPUT_TFSEC_FORMATS}" ]; then
41
63
TFSEC_OUT_OPTION=" ${TFSEC_OUT_OPTION% .* } "
42
64
fi
43
65
44
- tfsec --out=${TFSEC_OUT_OPTION} --format=${TFSEC_FORMAT_OPTION} --soft-fail ${TFSEC_ARGS_OPTION} " ${INPUT_WORKING_DIRECTORY} "
66
+ tfsec --out=${TFSEC_OUT_OPTION} --format=" ${TFSEC_FORMAT_OPTION} " --soft-fail " ${TFSEC_ARGS_OPTION} " " ${INPUT_WORKING_DIRECTORY} "
45
67
commenter
0 commit comments