Skip to content

Commit b4c44a9

Browse files
authored
Make the GitHub Action install the precise given version (#50)
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent fdc495c commit b4c44a9

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

action.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ description: Install the JSON Schema CLI
33
runs:
44
using: composite
55
steps:
6-
# TODO: Install from the latest tag at or before the current commit sha
76
- name: Install the JSON Schema CLI (latest)
87
shell: bash
98
run: |
10-
/bin/sh -c "$(curl -fsSL https://raw.githubusercontent.com/intelligence-ai/jsonschema/main/install -H 'Cache-Control: no-cache, no-store, must-revalidate')"
9+
curl --retry 5 --location --fail-early --silent --show-error \
10+
--output "${GITHUB_WORKSPACE}/install.sh" \
11+
"https://raw.githubusercontent.com/intelligence-ai/jsonschema/main/install"
12+
chmod +x "${GITHUB_WORKSPACE}/install.sh"
13+
"${GITHUB_WORKSPACE}/install.sh" "${GITHUB_REF#refs/tags/v}"
14+
rm "${GITHUB_WORKSPACE}/install.sh"

install

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,32 @@ set -o nounset
66
UNAME="$(uname)"
77
ARCH="$(uname -m)"
88

9-
if [ "$UNAME" = "Darwin" ]
10-
then
11-
if [ "$ARCH" != "arm64" ]
12-
then
13-
echo "ERROR: There are no pre-built JSON Schema CLI binaries for macOS on $ARCH" 1>&2
14-
echo "You might be able to build it from source" 1>&2
15-
exit 1
16-
fi
17-
18-
echo "---- Attempting to install the JSON Schema CLI using Homebrew" 1>&2
19-
brew install intelligence-ai/apps/jsonschema
20-
elif [ "$UNAME" = "Linux" ]
9+
if [ "$UNAME" = "Darwin" ] || [ "$UNAME" = "Linux" ]
2110
then
2211
echo "---- Fetching the pre-built JSON Schema CLI binary from GitHub Releases" 1>&2
2312
OWNER="intelligence-ai"
2413
REPOSITORY="jsonschema"
25-
LATEST_TAG="$(curl --silent "https://api.github.com/repos/$OWNER/$REPOSITORY/releases/latest" \
26-
| grep '"tag_name"' | cut -d ':' -f 2 | tr -d 'v" ,')"
27-
PACKAGE_BASE_URL="https://github.com/$OWNER/$REPOSITORY/releases/download/v$LATEST_TAG"
14+
15+
if [ $# -lt 1 ]
16+
then
17+
VERSION="$(curl --retry 5 --silent "https://api.github.com/repos/$OWNER/$REPOSITORY/releases/latest" \
18+
| grep '"tag_name"' | cut -d ':' -f 2 | tr -d 'v" ,')"
19+
else
20+
VERSION="$1"
21+
fi
22+
23+
PACKAGE_BASE_URL="https://github.com/$OWNER/$REPOSITORY/releases/download/v$VERSION"
2824
PACKAGE_PLATFORM_NAME="$(echo "$UNAME" | tr '[:upper:]' '[:lower:]')"
29-
PACKAGE_URL="$PACKAGE_BASE_URL/jsonschema-$LATEST_TAG-$PACKAGE_PLATFORM_NAME-$ARCH.zip"
25+
PACKAGE_URL="$PACKAGE_BASE_URL/jsonschema-$VERSION-$PACKAGE_PLATFORM_NAME-$ARCH.zip"
26+
echo "---- Fetching version v$VERSION from $PACKAGE_URL" 1>&2
3027
OUTPUT="/usr/local"
3128
TMP="$(mktemp -d)"
3229
clean() { rm -rf "$TMP"; }
3330
trap clean EXIT
34-
curl --location --output "$TMP/artifact.zip" "$PACKAGE_URL"
31+
curl --retry 5 --location --output "$TMP/artifact.zip" "$PACKAGE_URL"
3532
unzip "$TMP/artifact.zip" -d "$TMP/out"
3633
mkdir -p "$OUTPUT/bin"
37-
install -v -m 0755 "$TMP/out/jsonschema-$LATEST_TAG-$PACKAGE_PLATFORM_NAME-$ARCH/bin/jsonschema" "$OUTPUT/bin"
34+
install -v -m 0755 "$TMP/out/jsonschema-$VERSION-$PACKAGE_PLATFORM_NAME-$ARCH/bin/jsonschema" "$OUTPUT/bin"
3835
else
3936
echo "ERROR: I don't know how to install the JSON Schema CLI in $UNAME!" 1>&2
4037
echo "Open an issue here: https://github.com/Intelligence-AI/jsonschema/issues" 1>&2

0 commit comments

Comments
 (0)