Skip to content
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
2 changes: 1 addition & 1 deletion src/difftastic/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
26 changes: 17 additions & 9 deletions src/difftastic/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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..."
Expand Down
2 changes: 1 addition & 1 deletion test/_global/crane-specific-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions test/_global/difftastic-versioned-asset.sh
Original file line number Diff line number Diff line change
@@ -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
10 changes: 9 additions & 1 deletion test/_global/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"crane": {
"version": "v0.13.0"
"version": "v0.22.1"
}
}
},
Expand Down Expand Up @@ -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": {
Expand Down
Loading