-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcheck
executable file
·29 lines (22 loc) · 914 Bytes
/
check
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
#!/bin/bash
set -e
exec 3>&1 # make stdout available as fd 3 for the result
exec 1>&2 # redirect all output to stderr for logging
payload=$(mktemp "$TMPDIR/resource-check.XXXXXX")
cat > "$payload" <&0
source_project=$(jq -r '.source.project // empty' < "$payload")
if [[ "${source_project}X" == "X" ]]; then
>&2 echo "Source parameter 'project' is missing"
exit 1
fi
curl -sf "https://releases.hashicorp.com/${source_project}/index.json" > /dev/null || (
>&2 echo "Unknown hashicorp project '$source_project'"
exit 1
)
>&2 echo "Looking up versions of '${source_project}'"
latest_version=$(curl -s "https://releases.hashicorp.com/${source_project}/index.json" \
| jq -r '.versions | keys[]' \
| grep -v "beta" | grep -v "rc" | grep -v "alpha" | grep -v "+" \
| sort -V | tail -n1)
>&2 echo "Latest version $latest_version"
jq -n --arg version "${latest_version}" '[{ version: $version }]' >&3