Skip to content

Commit

Permalink
feat: Add build script for Gex (#11)
Browse files Browse the repository at this point in the history
* Add build-gex script

* Add github workflow for generating gex bins

* Add setup-go action to gen-gex workflow
  • Loading branch information
Ehsan-saradar authored Oct 18, 2023
1 parent 504ddaa commit 298d0f1
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 4 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/gen-gex-binaries.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion gex/data_darwin_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion gex/data_darwin_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion gex/data_linux_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion gex/data_linux_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Binary file removed gex/gex-v1.3.0-amd64-darwin.tar.gz
Binary file not shown.
Binary file removed gex/gex-v1.3.0-amd64-linux.tar.gz
Binary file not shown.
Binary file removed gex/gex-v1.3.0-arm64-darwin.tar.gz
Binary file not shown.
Binary file removed gex/gex-v1.3.0-arm64-linux.tar.gz
Binary file not shown.
46 changes: 46 additions & 0 deletions scripts/gen-gex
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 298d0f1

Please sign in to comment.