Skip to content

Commit

Permalink
Make the GitHub Action install the precise given version (#50)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti authored Jun 3, 2024
1 parent fdc495c commit b4c44a9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
8 changes: 6 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ description: Install the JSON Schema CLI
runs:
using: composite
steps:
# TODO: Install from the latest tag at or before the current commit sha
- name: Install the JSON Schema CLI (latest)
shell: bash
run: |
/bin/sh -c "$(curl -fsSL https://raw.githubusercontent.com/intelligence-ai/jsonschema/main/install -H 'Cache-Control: no-cache, no-store, must-revalidate')"
curl --retry 5 --location --fail-early --silent --show-error \
--output "${GITHUB_WORKSPACE}/install.sh" \
"https://raw.githubusercontent.com/intelligence-ai/jsonschema/main/install"
chmod +x "${GITHUB_WORKSPACE}/install.sh"
"${GITHUB_WORKSPACE}/install.sh" "${GITHUB_REF#refs/tags/v}"
rm "${GITHUB_WORKSPACE}/install.sh"
33 changes: 15 additions & 18 deletions install
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,32 @@ set -o nounset
UNAME="$(uname)"
ARCH="$(uname -m)"

if [ "$UNAME" = "Darwin" ]
then
if [ "$ARCH" != "arm64" ]
then
echo "ERROR: There are no pre-built JSON Schema CLI binaries for macOS on $ARCH" 1>&2
echo "You might be able to build it from source" 1>&2
exit 1
fi

echo "---- Attempting to install the JSON Schema CLI using Homebrew" 1>&2
brew install intelligence-ai/apps/jsonschema
elif [ "$UNAME" = "Linux" ]
if [ "$UNAME" = "Darwin" ] || [ "$UNAME" = "Linux" ]
then
echo "---- Fetching the pre-built JSON Schema CLI binary from GitHub Releases" 1>&2
OWNER="intelligence-ai"
REPOSITORY="jsonschema"
LATEST_TAG="$(curl --silent "https://api.github.com/repos/$OWNER/$REPOSITORY/releases/latest" \
| grep '"tag_name"' | cut -d ':' -f 2 | tr -d 'v" ,')"
PACKAGE_BASE_URL="https://github.com/$OWNER/$REPOSITORY/releases/download/v$LATEST_TAG"

if [ $# -lt 1 ]
then
VERSION="$(curl --retry 5 --silent "https://api.github.com/repos/$OWNER/$REPOSITORY/releases/latest" \
| grep '"tag_name"' | cut -d ':' -f 2 | tr -d 'v" ,')"
else
VERSION="$1"
fi

PACKAGE_BASE_URL="https://github.com/$OWNER/$REPOSITORY/releases/download/v$VERSION"
PACKAGE_PLATFORM_NAME="$(echo "$UNAME" | tr '[:upper:]' '[:lower:]')"
PACKAGE_URL="$PACKAGE_BASE_URL/jsonschema-$LATEST_TAG-$PACKAGE_PLATFORM_NAME-$ARCH.zip"
PACKAGE_URL="$PACKAGE_BASE_URL/jsonschema-$VERSION-$PACKAGE_PLATFORM_NAME-$ARCH.zip"
echo "---- Fetching version v$VERSION from $PACKAGE_URL" 1>&2
OUTPUT="/usr/local"
TMP="$(mktemp -d)"
clean() { rm -rf "$TMP"; }
trap clean EXIT
curl --location --output "$TMP/artifact.zip" "$PACKAGE_URL"
curl --retry 5 --location --output "$TMP/artifact.zip" "$PACKAGE_URL"
unzip "$TMP/artifact.zip" -d "$TMP/out"
mkdir -p "$OUTPUT/bin"
install -v -m 0755 "$TMP/out/jsonschema-$LATEST_TAG-$PACKAGE_PLATFORM_NAME-$ARCH/bin/jsonschema" "$OUTPUT/bin"
install -v -m 0755 "$TMP/out/jsonschema-$VERSION-$PACKAGE_PLATFORM_NAME-$ARCH/bin/jsonschema" "$OUTPUT/bin"
else
echo "ERROR: I don't know how to install the JSON Schema CLI in $UNAME!" 1>&2
echo "Open an issue here: https://github.com/Intelligence-AI/jsonschema/issues" 1>&2
Expand Down

0 comments on commit b4c44a9

Please sign in to comment.