forked from egen/hashicorp-release-resource
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check
executable file
·30 lines (23 loc) · 1.02 KB
/
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
30
#!/bin/bash
set -eo pipefail
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 --raw-output '.source.project // empty' < "${payload}")
if [[ -z "${source_project}" ]]; then
>&2 echo "Source parameter 'project' is missing"
exit 1
fi
curl --silent --fail --show-error --location --output /dev/null \
--url "https://releases.hashicorp.com/${source_project}/index.json" || (
>&2 echo "Unknown hashicorp project '${source_project}'"
exit 1
)
>&2 echo "Looking up versions of '${source_project}'"
latest_version=$(curl --silent --fail --url "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 --null-input --arg version "${latest_version}" '[ { version: $version } ]' >&3