diff --git a/src/difftastic/devcontainer-feature.json b/src/difftastic/devcontainer-feature.json index c5f9b51..333f146 100644 --- a/src/difftastic/devcontainer-feature.json +++ b/src/difftastic/devcontainer-feature.json @@ -1,7 +1,7 @@ { "name": "Difftastic", "id": "difftastic", - "version": "1.0.0", + "version": "1.0.1", "description": "Syntax-aware structural diffs that are much easier to read than plain text diffs.", "options": { "version": { diff --git a/src/difftastic/install.sh b/src/difftastic/install.sh index c4fd2de..1aa97e7 100644 --- a/src/difftastic/install.sh +++ b/src/difftastic/install.sh @@ -28,21 +28,23 @@ check_packages() { fi } -# Make sure we have curl and jq -check_packages curl jq ca-certificates +# Make sure we have the download and extraction dependencies +check_packages curl jq ca-certificates tar -# Function to get the latest version from GitHub API -get_latest_version() { - curl -s "${GITHUB_API_REPO_URL}/latest" | jq -r ".tag_name" +# Fetch release metadata from GitHub API +get_release() { + curl -fsSL "${GITHUB_API_REPO_URL}/$1" } # Check if a version is passed as an argument if [ -z "$DIFFTASTIC_VERSION" ] || [ "$DIFFTASTIC_VERSION" == "latest" ]; then # No version provided, get the latest version - DIFFTASTIC_VERSION=$(get_latest_version) + RELEASE=$(get_release latest) + DIFFTASTIC_VERSION=$(jq -er '.tag_name' <<< "$RELEASE") echo "No version provided or 'latest' specified, installing the latest version: $DIFFTASTIC_VERSION" else echo "Installing version from environment variable: $DIFFTASTIC_VERSION" + RELEASE=$(get_release "tags/${DIFFTASTIC_VERSION}") fi # Determine the OS and architecture @@ -75,15 +77,21 @@ case "$OS" in ;; esac -# Construct the download URL -DOWNLOAD_URL="https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${DIFFTASTIC_VERSION}/difft-${ARCH}-${OS}.tar.gz" +# Releases before 0.71.0 omit the version from the asset name. +DOWNLOAD_URL=$(jq -er \ + --arg legacy_name "difft-${ARCH}-${OS}.tar.gz" \ + --arg versioned_name "difft-${DIFFTASTIC_VERSION}-${ARCH}-${OS}.tar.gz" \ + '.assets | map(select(.name == $legacy_name or .name == $versioned_name)) | + if length == 1 then .[0].browser_download_url + else error("Expected exactly one matching difftastic release asset") + end' <<< "$RELEASE") # Create a temporary directory for the download TMP_DIR=$(mktemp -d) cd "$TMP_DIR" || exit echo "Downloading difftastic from $DOWNLOAD_URL" -curl -sSL "$DOWNLOAD_URL" -o "difft.tar.gz" +curl -fsSL "$DOWNLOAD_URL" -o "difft.tar.gz" # Extract the tarball echo "Extracting difftastic..." diff --git a/test/_global/crane-specific-version.sh b/test/_global/crane-specific-version.sh index 86c7d36..c657d44 100644 --- a/test/_global/crane-specific-version.sh +++ b/test/_global/crane-specific-version.sh @@ -2,6 +2,6 @@ set -e source dev-container-features-test-lib -check "crane with specific version" /bin/bash -c "crane version | grep '0.13.0'" +check "crane with specific version" /bin/bash -c "crane version | grep -Fx '0.22.1'" reportResults diff --git a/test/_global/difftastic-versioned-asset.sh b/test/_global/difftastic-versioned-asset.sh new file mode 100644 index 0000000..dee1153 --- /dev/null +++ b/test/_global/difftastic-versioned-asset.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -e + +source dev-container-features-test-lib +check "difftastic with versioned release asset" /bin/bash -c "difft --version | grep -F 'Difftastic 0.71.0'" +reportResults diff --git a/test/_global/scenarios.json b/test/_global/scenarios.json index f1dd3ab..dbe3413 100644 --- a/test/_global/scenarios.json +++ b/test/_global/scenarios.json @@ -70,7 +70,7 @@ "image": "mcr.microsoft.com/devcontainers/base:ubuntu", "features": { "crane": { - "version": "v0.13.0" + "version": "v0.22.1" } } }, @@ -320,6 +320,14 @@ } } }, + "difftastic-versioned-asset": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "features": { + "difftastic": { + "version": "0.71.0" + } + } + }, "delta-specific-version": { "image": "mcr.microsoft.com/devcontainers/base:ubuntu", "features": {