From b4c44a9099f306d8548c540dfed26dec80206eee Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Mon, 3 Jun 2024 19:33:10 -0400 Subject: [PATCH] Make the GitHub Action install the precise given version (#50) Signed-off-by: Juan Cruz Viotti --- action.yml | 8 ++++++-- install | 33 +++++++++++++++------------------ 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/action.yml b/action.yml index 236279c7..4e60dac1 100644 --- a/action.yml +++ b/action.yml @@ -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" diff --git a/install b/install index ddd6d691..7fe3e6e5 100755 --- a/install +++ b/install @@ -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