diff --git a/.github/workflows/gen-protoc-binaries.yml b/.github/workflows/gen-protoc-binaries.yml new file mode 100644 index 0000000..21fbed8 --- /dev/null +++ b/.github/workflows/gen-protoc-binaries.yml @@ -0,0 +1,60 @@ +name: Generate protoc binaries + +on: + push: + branches: + - main + paths: + - 'protoc/*.go' + - 'protoc/include/**/*.proto' + - 'scripts/gen-protoc' + - 'scripts/data/gen-protoc/**' + +jobs: + gen-protoc: + name: "Generate protoc binaries" + runs-on: ${{ matrix.runner.runs-on }} + concurrency: gen-protoc-${{ matrix.runner.os }}-${{ matrix.runner.arch }} + strategy: + fail-fast: false + matrix: + runner: + - runs-on: ubuntu-latest + os: linux + defaults-shell: bash + arch: amd64 + - runs-on: [ self-hosted, linux, arm64 ] + os: linux + defaults-shell: bash + arch: arm64 + - runs-on: macos-10.15 # building it at the latest version breaks compability for older versions + os: darwin + defaults-shell: /bin/bash -l {0} + arch: amd64 + - runs-on: [ self-hosted, macOS ] + os: darwin + defaults-shell: /usr/bin/arch -arch arm64e /bin/bash -l {0} + arch: arm64 + defaults: + run: + shell: ${{ matrix.runner.defaults-shell }} + steps: + - uses: actions/checkout@v3 + + - run: | + if [[ "${{ matrix.runner.os }}" == "darwin" ]]; then + brew install jq autoconf automake libtool + else + sudo apt install -y jq autoconf automake libtool curl make g++ unzip + fi + + - name: Build protoc files + run: ./scripts/gen-protoc + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v4 + with: + title: "feat(protoc): update binaries ${{ matrix.runner.os }}-${{ matrix.runner.arch }}" + commit-message: "feat(protoc): update binaries ${{ matrix.runner.os }}-${{ matrix.runner.arch }}" + body: "" + branch: feat/gen-protoc-${{ matrix.runner.os }}-${{ matrix.runner.arch }} diff --git a/scripts/data/gen-protoc/version-darwin-amd64 b/scripts/data/gen-protoc/version-darwin-amd64 new file mode 100644 index 0000000..3331c19 --- /dev/null +++ b/scripts/data/gen-protoc/version-darwin-amd64 @@ -0,0 +1 @@ +v3.10.0 diff --git a/scripts/data/gen-protoc/version-darwin-arm64 b/scripts/data/gen-protoc/version-darwin-arm64 new file mode 100644 index 0000000..3331c19 --- /dev/null +++ b/scripts/data/gen-protoc/version-darwin-arm64 @@ -0,0 +1 @@ +v3.10.0 diff --git a/scripts/data/gen-protoc/version-linux-amd64 b/scripts/data/gen-protoc/version-linux-amd64 new file mode 100644 index 0000000..3331c19 --- /dev/null +++ b/scripts/data/gen-protoc/version-linux-amd64 @@ -0,0 +1 @@ +v3.10.0 diff --git a/scripts/data/gen-protoc/version-linux-arm64 b/scripts/data/gen-protoc/version-linux-arm64 new file mode 100644 index 0000000..3331c19 --- /dev/null +++ b/scripts/data/gen-protoc/version-linux-arm64 @@ -0,0 +1 @@ +v3.10.0 diff --git a/scripts/gen-protoc b/scripts/gen-protoc new file mode 100755 index 0000000..a7a2bc4 --- /dev/null +++ b/scripts/gen-protoc @@ -0,0 +1,80 @@ +#!/bin/bash + +# Downloads latest protoc source, builds it and puts them in the right place + +set -e + +[[ $(command -v curl) ]] || { echo "'curl' not found!" ; dep_check="false" ;} +[[ $(command -v wget) ]] || { echo "'wget' not found!" ; dep_check="false" ;} +[[ $(command -v unzip) ]] || { echo "'unzip' not found!" ; dep_check="false" ;} + +# Build tools +[[ $(command -v make) ]] || { echo "'make' not found!" ; dep_check="false" ;} +[[ $(command -v automake) ]] || { echo "'automake' not found!" ; dep_check="false" ;} + +[[ ${dep_check} = "false" ]] && { echo "Some dependencie(s) isn't installed yet. Please install that dependencie(s)" ; exit 1 ;} + +gh_protoc_release_url="https://api.github.com/repos/protocolbuffers/protobuf/releases/latest" +setdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)" # this line powered by stackoverflow +kernelname="$(uname -s | tr '[:upper:]' '[:lower:]' || { echo 'kernel name can not defined' ; exit 1 ;})" +machinetype=$(uname -m) +case $machinetype in + "x86_64") arch="amd64" + ;; + "aarch64") arch="arm64" + ;; + "arm64") arch="arm64" + ;; + *) echo "$machinetype is not supported"; exit 1; + ;; +esac +fname=protoc-$kernelname-$arch + +# Check dir else create save dir +if [[ $(basename "${setdir}") = "scripts" ]] ; then + if [[ $(basename "$(dirname "${setdir}")") != "ignite-files" ]] ; then + echo "Attention: you are running the script out of ignite-files project please run it this script in: https://github.com/ignite/ignite-files" + exit 1 + fi +else + echo "$setdir" + echo "Attention: you are running the script out of ignite-files project please run it this script in: https://github.com/ignite/ignite-files" + exit 1 +fi + +# Check if we have the newest version already +version_file=$(dirname "${setdir}")/scripts/data/gen-protoc/version-"$kernelname"-"$arch" +newest_version="v3.20.0" +download_url="https://github.com/protocolbuffers/protobuf/releases/download/v3.20.0/protobuf-all-3.20.0.tar.gz" +current_version=$(cat "$version_file") + +if [[ "$newest_version" == "$current_version" ]] ; then + echo "Newest version already built, exiting early, all good" + exit 0 +fi + +# Check and Create Temp Directory +tmpdir=$(mktemp -d) +cd "$tmpdir" + +outputdir="$tmpdir/protocout" +mkdir "$outputdir" +mkdir protobuf # Where we will build + +# Fetch releases, go through assets (release artifacts) and find the relevant one +wget -c "$download_url" -O - | tar xzC protobuf --strip-components=1 #skipping first folder + +# Ok, let's build! +# Build instructions taken from: https://github.com/protocolbuffers/protobuf/blob/main/src/README.md +cd protobuf +./configure CXXFLAGS="-DNDEBUG" --prefix="$outputdir" --disable-shared # Static linked libraries so it works on all machines +make clean +make -j$(nproc) +make install + +cp "$outputdir"/bin/protoc "$(dirname "${setdir}")/protoc/${fname}" + +cd "$(dirname "${setdir}")"/protoc && tar -czf "${fname}.tar.gz" ${fname} && rm -f ${fname} +echo "$newest_version" > "$version_file" #Update version file so we don't have to rebuild this + +rm -rf "$tmpdir"