-
Notifications
You must be signed in to change notification settings - Fork 2
/
entrypoint.sh
executable file
·63 lines (48 loc) · 1.33 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
#!/usr/bin/env bash
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail
IFS=$'\n\t'
API_TOKEN=$1
TITLE=$2
LABELS=$3
TIME=$4
WORKSPACE_ID=$5
BASE_URL=$6
if [[ -z $API_TOKEN ]]; then
echo "A valid Fiberplane API token is required to post a event" >&2
exit 1
fi
if [[ -z $TITLE ]]; then
echo "Please specify a title for the event" >&2
exit 1
fi
if [[ -z $LABELS ]]; then
echo "Please specify at least a single label for the event" >&2
exit 1
fi
if [[ -z $WORKSPACE_ID ]]; then
echo "Please specify the workspace ID to which the event should be posted to" >&2
exit 1
fi
if [[ -z $BASE_URL ]]; then
echo "A valid Fiberplane API base url is required" >&2
exit 1
fi
additional_args=()
# https://stackoverflow.com/a/10586169/11494565
IFS='|' read -r -a labels_array <<< "$LABELS"
# https://stackoverflow.com/a/8880633/11494565
for i in "${labels_array[@]}"
do
additional_args+=(--label "$i")
done
if [[ -n $TIME ]]; then
additional_args+=(--time "$TIME")
fi
echo "api_token = '$API_TOKEN'" > config.toml
export CONFIG="$(pwd)/config.toml"
export API_BASE="$BASE_URL"
export DISABLE_VERSION_CHECK=true
output=$(/usr/bin/fp events create -v --title "$TITLE" --workspace-id "$WORKSPACE_ID" "${additional_args[@]}" --output json)
id=$(jq -n '$in.id' --argjson in "$output")
echo "id=$id" >> $GITHUB_OUTPUT