Skip to content

Commit

Permalink
feat: add go protoc plugin install script
Browse files Browse the repository at this point in the history
  • Loading branch information
zepatrik committed Nov 23, 2020
1 parent cacb0c2 commit 4408b6a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
11 changes: 9 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ inputs:
required: false
bufArgs:
description: The arguments to pass to buf
default: generate
default: check lint
required: false
protocPlugins:
description: The protoc language plugins to install, space separated. See README for supported plugins.
default: ""
required: false

runs:
Expand All @@ -19,7 +23,10 @@ runs:
- name: Maybe install and definitely invoke buf
shell: bash
run: |
source ${{ github.action_path }}/scripts/install-buf.sh ${{ inputs.bufVersion }}
REPO_DIR="$(pwd)"
cd ${{ github.action_path }}
source scripts/install-buf.sh ${{ inputs.bufVersion }} ${{ inputs.protocPlugins }}
cd $REPO_DIR
buf ${{ inputs.bufArgs }}
branding:
Expand Down
19 changes: 19 additions & 0 deletions scripts/executor-info.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

UNAME_OS=$(uname -s)
UNAME_ARCH=$(uname -m)

NORMALIZED_OS=$UNAME_OS
if [ "$NORMALIZED_OS" = "Linux" ]; then
NORMALIZED_OS="linux"
fi

NORMALIZED_ARCH=$UNAME_ARCH
if [ "$NORMALIZED_ARCH" = "x86_64" ]; then
NORMALIZED_ARCH="amd64"
fi

export UNAME_OS
export UNAME_ARCH
export NORMALIZED_OS
export NORMALIZED_ARCH
15 changes: 13 additions & 2 deletions scripts/install-buf.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
#!/bin/bash
set -euo pipefail

UNAME_OS=$(uname -s)
UNAME_ARCH=$(uname -m)
source scripts/executor-info.sh

BUF_VERSION=$1

IFS=" " read -r -a PROTOC_PLUGINS <<< "$2"
for part in "${PROTOC_PLUGINS[@]}"; do
IFS="@" read -r -a langAndVersion <<< "$part"

if [ "${#langAndVersion[@]}" != 2 ]; then
echo "Malformed plugin specifier \"$part\", expected e.g. [email protected]"
exit 1
fi

bash "scripts/install-${langAndVersion[0]}-plugin.sh" "${langAndVersion[1]}"
done

if [ ! -f ".bin/buf" ]; then
echo "Installing buf $BUF_VERSION for OS $UNAME_OS Arch $UNAME_ARCH"
mkdir -p .bin
Expand Down
13 changes: 13 additions & 0 deletions scripts/install-go-plugin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

source scripts/executor-info.sh

GO_PROTOC_VERSION=$1

if [ ! -f ".bin/protoc-gen-go" ] || .bin/protoc-gen-go --version | grep -q "$GO_PROTOC_VERSION"; then
echo "Installing protobuf-gen-go $GO_PROTOC_VERSION for OS $UNAME_OS Arch $UNAME_ARCH"
mkdir -p .bin
curl --fail -sSL "https://github.com/protocolbuffers/protobuf-go/releases/download/$GO_PROTOC_VERSION/protoc-gen-go.$GO_PROTOC_VERSION.$NORMALIZED_OS.$NORMALIZED_ARCH.tar.gz" -o .bin/protoc-gen-go.tar.gz
tar -xf .bin/protoc-gen-go.tar.gz -C .bin
chmod +x .bin/protoc-gen-go
fi

0 comments on commit 4408b6a

Please sign in to comment.