forked from tj-actions/json2file
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
68 lines (53 loc) · 1.81 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
#!/usr/bin/env bash
set -euo pipefail
download_with_retries() {
local DELAY=10
local OUTPUT_FILE=$1
for i in $(seq 1 5); do
curl --connect-timeout 300 -sLf https://github.com/tj-actions/json2file/releases/download/"$LATEST_VERSION"/json2file_"$LATEST_VERSION"_"$TARGET"."$ARCHIVE" -o "$OUTPUT_FILE" && break
sleep $DELAY
echo "$i retries"
done
}
if [[ -z "$INPUT_BIN_PATH" ]]; then
echo "Downloading json2file binary..."
LATEST_VERSION=v1.3.0
# Download the latest version
WINDOWS_TARGET=x86_64-pc-windows-gnu
LINUX_TARGET=x86_64-unknown-linux-musl
MACOS_TARGET=x86_64-apple-darwin
ARCHIVE=zip
TEMP_DIR=$(mktemp -d)
if [[ $(uname -s) == "Linux" ]]; then
TARGET=$LINUX_TARGET
ARCHIVE=tar.gz
elif [[ $(uname -s) == "Darwin" ]]; then
TARGET=$MACOS_TARGET
else
TARGET=$WINDOWS_TARGET
fi
if [[ "$ARCHIVE" == "zip" ]]; then
download_with_retries "$TEMP_DIR"/json2file.zip
unzip -q "$TEMP_DIR"/json2file.zip -d "$TEMP_DIR"
else
download_with_retries "$TEMP_DIR"/json2file.tar.gz
tar -xzf "$TEMP_DIR"/json2file.tar.gz -C "$TEMP_DIR"
fi
chmod +x "$TEMP_DIR"/json2file
INPUT_BIN_PATH=$TEMP_DIR/json2file
fi
echo "Parsing inputs..."
INPUT_OUTPUTS="$(echo "$INPUT_OUTPUTS" | jq -r @json)"
INPUT_KEYS="$(echo "$INPUT_KEYS" | tr '\n' ' ' | xargs)"
EXTRA_ARGS=""
if [[ "$INPUT_SKIP_MISSING_KEYS" == "true" ]]; then
EXTRA_ARGS="$EXTRA_ARGS --skip-missing-keys"
fi
echo "Generating output using $INPUT_BIN_PATH..."
# shellcheck disable=SC2086
$INPUT_BIN_PATH $EXTRA_ARGS --keys="$INPUT_KEYS" --outputs="$INPUT_OUTPUTS" --directory="$INPUT_DIRECTORY" --extension="$INPUT_EXTENSION" && exit_status=$? || exit_status=$?
rm -f "$INPUT_BIN_PATH"
if [[ $exit_status -ne 0 ]]; then
echo "::error::Error generating output files from JSON"
exit 1;
fi