diff --git a/.github/workflows/gen-gex-binaries.yml b/.github/workflows/gen-gex-binaries.yml new file mode 100644 index 0000000..940a7a8 --- /dev/null +++ b/.github/workflows/gen-gex-binaries.yml @@ -0,0 +1,34 @@ +name: Generate nodetime binaries + +on: + push: + branches: + - main + paths: + - 'gex/*.go' + - 'scripts/gen-gex' + +jobs: + gen-gex: + name: "Generate gex binaries" + runs-on: ubuntu-latest + concurrency: gen-gex + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-go@v4 + if: env.GIT_DIFF + with: + go-version: '1.21' + + - run: ./scripts/gen-gex + + - name: Create Pull Request + id: cpr + uses: peter-evans/create-pull-request@v4 + with: + title: "feat(gex): update binaries" + commit-message: "feat(gex): update binaries" + body: "" + branch: feat/gen-gex + delete-branch: true diff --git a/gex/data_darwin_amd64.go b/gex/data_darwin_amd64.go index dc3d8a8..98970b6 100644 --- a/gex/data_darwin_amd64.go +++ b/gex/data_darwin_amd64.go @@ -2,5 +2,5 @@ package gex import _ "embed" // embed is required for binary embedding. -//go:embed gex-v1.3.0-amd64-darwin.tar.gz +//go:embed gex-amd64-darwin.tar.gz var binaryCompressed []byte diff --git a/gex/data_darwin_arm64.go b/gex/data_darwin_arm64.go index 7919b0b..1cf5b24 100644 --- a/gex/data_darwin_arm64.go +++ b/gex/data_darwin_arm64.go @@ -2,5 +2,5 @@ package gex import _ "embed" // embed is required for binary embedding. -//go:embed gex-v1.3.0-arm64-darwin.tar.gz +//go:embed gex-arm64-darwin.tar.gz var binaryCompressed []byte diff --git a/gex/data_linux_amd64.go b/gex/data_linux_amd64.go index dc171dd..09cb44f 100644 --- a/gex/data_linux_amd64.go +++ b/gex/data_linux_amd64.go @@ -2,5 +2,5 @@ package gex import _ "embed" // embed is required for binary embedding. -//go:embed gex-v1.3.0-amd64-linux.tar.gz +//go:embed gex-amd64-linux.tar.gz var binaryCompressed []byte diff --git a/gex/data_linux_arm64.go b/gex/data_linux_arm64.go index db42d86..2ff54cc 100644 --- a/gex/data_linux_arm64.go +++ b/gex/data_linux_arm64.go @@ -2,5 +2,5 @@ package gex import _ "embed" // embed is required for binary embedding. -//go:embed gex-v1.3.0-arm64-linux.tar.gz +//go:embed gex-arm64-linux.tar.gz var binaryCompressed []byte diff --git a/gex/gex-v1.3.0-amd64-darwin.tar.gz b/gex/gex-v1.3.0-amd64-darwin.tar.gz deleted file mode 100644 index c3b356e..0000000 Binary files a/gex/gex-v1.3.0-amd64-darwin.tar.gz and /dev/null differ diff --git a/gex/gex-v1.3.0-amd64-linux.tar.gz b/gex/gex-v1.3.0-amd64-linux.tar.gz deleted file mode 100644 index 6a471a7..0000000 Binary files a/gex/gex-v1.3.0-amd64-linux.tar.gz and /dev/null differ diff --git a/gex/gex-v1.3.0-arm64-darwin.tar.gz b/gex/gex-v1.3.0-arm64-darwin.tar.gz deleted file mode 100644 index 8781726..0000000 Binary files a/gex/gex-v1.3.0-arm64-darwin.tar.gz and /dev/null differ diff --git a/gex/gex-v1.3.0-arm64-linux.tar.gz b/gex/gex-v1.3.0-arm64-linux.tar.gz deleted file mode 100644 index 441fe35..0000000 Binary files a/gex/gex-v1.3.0-arm64-linux.tar.gz and /dev/null differ diff --git a/scripts/gen-gex b/scripts/gen-gex new file mode 100755 index 0000000..bb4a387 --- /dev/null +++ b/scripts/gen-gex @@ -0,0 +1,46 @@ +#!/bin/bash + +# This script builds Gex for multiple platforms and creates a tarball for each platform. +# It clones the Gex repository, checks out the specified version, and builds the binary for each platform. +# The resulting tarballs are saved in the gex directory. + +set -e + +GIT_REPOSITORY="https://github.com/cosmos/gex.git" +GOROOT=$(go env GOROOT) +WORKDIR=$(pwd) +PLATFORMS="darwin/amd64 darwin/arm64 linux/amd64 linux/arm64" + +# Cleans up temporary files and directories +clean_up() { + test -d "$tmp_dir" && rm -fr "$tmp_dir" +} + +# Creates a temporary directory and sets up a trap to clean it up on exit +tmp_dir=$(mktemp -d -t gex.XXXXXX) +trap "clean_up $tmp_dir" EXIT + +# Clones the Gex repository into the temporary directory and checkout the latest version +git clone --quiet ${GIT_REPOSITORY} ${tmp_dir} +cd ${tmp_dir} +version=$(git tag --list --sort=version:refname 'v*' | tail -1) +git checkout --quiet ${version} +echo "Latest Version: ${version}" + +# Builds Gex for each platform and creates a tarball for each one +for platform in ${PLATFORMS} +do + goos=${platform%/*} + goarch=${platform#*/} + + GOOS=$goos GOARCH=$goarch go build -o gex-${goarch}-${goos} 2>&1 + + # The sorting, owner, group and mtime is to ensure md5 equality of the tar output + # From: https://stackoverflow.com/questions/32997526/how-to-create-a-tar-file-that-omits-timestamps-for-its-contents + # piping into gzip with --no-name is to ensure md5 equality of the compressed tar ball (if not you get different hash every time). + # From: https://stackoverflow.com/questions/36464358/why-do-the-md5-hashes-of-two-tarballs-of-the-same-file-differ + TZ=UTC0 tar --sort=name --owner=root:0 --group=root:0 --mtime='2019-01-01 00:00:00' -cvf - gex-${goarch}-${goos} | gzip --no-name > gex-${goarch}-${goos}.tar.gz +done + +# Moves the tarballs to the gex directory +mv gex-*.tar.gz ${WORKDIR}/gex \ No newline at end of file