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
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ repos:
hooks:
- id: license-eye
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
rev: v6.0.0
hooks:
- id: pretty-format-json
args:
Expand All @@ -34,7 +34,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v4.2.0
rev: v4.3.0
hooks:
- id: conventional-pre-commit
stages:
Expand All @@ -45,7 +45,7 @@ repos:
- id: markdown-toc
exclude: ^src
- repo: https://github.com/DavidAnson/markdownlint-cli2
rev: v0.18.1
rev: v0.20.0
hooks:
- id: markdownlint-cli2
exclude: ^src
Expand Down
2 changes: 1 addition & 1 deletion src/buf/devcontainer-feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
}
},
"installsAfter": [
"ghcr.io/devcontainers-extra/features/gh-release"
"ghcr.io/devcontainers-extra/features/curl-apt-get:1"
]
}
57 changes: 35 additions & 22 deletions src/buf/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,40 @@ if [[ "$INSTALL_PROTOC_GEN_BUF_LINT" == "true" ]]; then
binary_names="$binary_names,protoc-gen-buf-lint"
fi

source ./library_scripts.sh

# nanolayer is a cli utility which keeps container layers as small as possible
# source code: https://github.com/devcontainers-contrib/nanolayer
# `ensure_nanolayer` is a bash function that will find any existing nanolayer installations,
# and if missing - will download a temporary copy that automatically get deleted at the end
# of the script
ensure_nanolayer nanolayer_location "v0.4.45"

$nanolayer_location \
install \
devcontainer-feature \
"ghcr.io/devcontainers-extra/features/gh-release:1.0.26" \
--option repo='bufbuild/buf' \
--option binaryNames="$binary_names" \
--option version="$VERSION" \
--option assetRegex='.*\.tar\.gz' \
--option libName='buf'

rm /usr/local/bin/buf

ln -s /usr/local/lib/buf/buf/bin/buf /usr/local/bin/buf
BIN="/usr/local/bin"
REPO_OWNER="bufbuild"
REPO_NAME="buf"
VERSION="${VERSION:-"latest"}" # Default to latest if not set

# Resolve "latest" to a real tag
if [ "${VERSION}" = "latest" ]; then
echo "Fetching latest version from GitHub..."
API_URL="https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/releases/latest"

# Extract tag_name from JSON response
VERSION=$(curl -sL "${API_URL}" | grep '"tag_name":' | cut -d : -f 2,3 | tr -d \", | tr -d '[:space:]')

if [ -z "${VERSION}" ]; then
echo "Error: Failed to fetch the latest version tag from GitHub."
exit 1
fi
fi

VERSION="${VERSION#v}"
IFS=',' read -ra BINARIES <<< "$binary_names"

for binary in "${BINARIES[@]}"; do
echo "Downloading ${binary}..."
DOWNLOAD_URL="https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/v${VERSION}/${binary}-$(uname -s)-$(uname -m)"

if ! curl -fsSL "$DOWNLOAD_URL" -o "${BIN}/${binary}"; then
echo "Error: Failed to download ${binary} version v${VERSION}."
echo "URL: ${DOWNLOAD_URL}"
rm -f "${BIN}/${binary}"
exit 1
fi

chmod +x "${BIN}/${binary}"
done

echo 'Done!'
Loading