Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the GitHub Action install the precise given version #50

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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