From c8cca710a59bd70d4413ade4e1173ee081d453f4 Mon Sep 17 00:00:00 2001 From: Ekrem Seren Date: Fri, 8 Dec 2023 03:35:44 +0300 Subject: [PATCH] Do not use buf's install action (too much api usage) --- .github/workflows/ci.yaml | 12 +++++++- scripts/buf-installer.sh | 53 ++++++++++++++++++++++++++++++++++ scripts/insert_diagram_link.sh | 0 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100755 scripts/buf-installer.sh mode change 100644 => 100755 scripts/insert_diagram_link.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 338a03a8..6accf16a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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" diff --git a/scripts/buf-installer.sh b/scripts/buf-installer.sh new file mode 100755 index 00000000..50570564 --- /dev/null +++ b/scripts/buf-installer.sh @@ -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" + diff --git a/scripts/insert_diagram_link.sh b/scripts/insert_diagram_link.sh old mode 100644 new mode 100755