-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not use buf's install action (too much api usage)
- Loading branch information
Showing
3 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/bin/bash | ||
|
||
BIN="/usr/local/bin" | ||
GITHUB_API_URL="https://api.github.com/repos/bufbuild/buf/releases/latest" | ||
GITHUB_RELEASES_URL="https://api.github.com/repos/bufbuild/buf/releases" | ||
|
||
# Function to fetch latest version | ||
fetch_latest_version() { | ||
curl -sSL $GITHUB_API_URL | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' | sed 's/v//' | ||
} | ||
|
||
# Function to list all versions | ||
list_versions() { | ||
curl -sSL $GITHUB_RELEASES_URL | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' | ||
} | ||
|
||
# Argument parsing | ||
VERSION="" | ||
LIST_VERSIONS=false | ||
for i in "$@" | ||
do | ||
case $i in | ||
--version=*) | ||
VERSION="${i#*=}" | ||
shift | ||
;; | ||
--list) | ||
LIST_VERSIONS=true | ||
shift | ||
;; | ||
*) | ||
# unknown option | ||
;; | ||
esac | ||
done | ||
|
||
# Logic for listing versions | ||
if [ "$LIST_VERSIONS" = true ]; then | ||
list_versions | ||
exit 0 | ||
fi | ||
|
||
# Set the default version to the latest if not specified | ||
if [ -z "$VERSION" ]; then | ||
VERSION=$(fetch_latest_version) | ||
fi | ||
|
||
# Installation | ||
echo "Installing buf version $VERSION..." | ||
curl -sSL "https://github.com/bufbuild/buf/releases/download/v${VERSION}/buf-$(uname -s)-$(uname -m)" \ | ||
-o "${BIN}/buf" && \ | ||
chmod +x "${BIN}/buf" | ||
|
Empty file.