Skip to content

Commit

Permalink
Do not use buf's install action (too much api usage)
Browse files Browse the repository at this point in the history
  • Loading branch information
havan committed Dec 8, 2023
1 parent 5935946 commit c8cca71
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
12 changes: 11 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,17 @@ jobs:
environment: draft
steps:
- uses: actions/checkout@v4
- uses: bufbuild/buf-setup-action@v1
- name: Install Buf
run: |
# Install Buf
if [ "${{ env.buf_version }}" == "" ]; then
# Install latest version
sudo ./scripts/buf-installer.sh
else
# Install the defined version
sudo ./scripts/buf-installer.sh --version=${{ env.buf_version}}
fi
- uses: bufbuild/buf-push-action@v1
with:
input: "proto"
Expand Down
53 changes: 53 additions & 0 deletions scripts/buf-installer.sh
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 modified scripts/insert_diagram_link.sh
100644 → 100755
Empty file.

0 comments on commit c8cca71

Please sign in to comment.