Skip to content

Commit

Permalink
Switch to goreleaser & add support for CGO cross-compilation (#1423)
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink committed Feb 23, 2024
1 parent 1d2d44c commit 7893414
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 31 deletions.
38 changes: 14 additions & 24 deletions .github/workflows/build-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,9 @@ on:
types: [published]

jobs:
releases-matrix:
release:
name: Release Go Binary
runs-on: ubuntu-latest
strategy:
matrix:
# build and publish in parallel: linux/386, linux/amd64, linux/arm64, windows/386, windows/amd64, darwin/amd64, darwin/arm64
goos: [ linux, windows, darwin ]
goarch: [ amd64, arm64 ]
exclude:
- goarch: arm64
goos: windows
steps:
- uses: actions/checkout@v3
- name: Codebase security check
Expand All @@ -25,19 +17,17 @@ jobs:
go-version: '1.20'
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
- uses: wangyoucao577/[email protected]
env:
MIXPANEL_PROJECT_TOKEN: ${{ secrets.MIXPANEL_PROJECT_TOKEN }}
LILICO_TOKEN: ${{ secrets.LILICO_TOKEN }}
APP_VERSION: $(basename ${GITHUB_REF})
BUILD_TIME: $(date --iso-8601=seconds)
VERSION: ${{github.ref_name}}
COMMIT: ${{ github.sha }}
- uses: actions/setup-go@v4
with:
pre_command: make generate
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
goversion: "1.20"
project_path: "./cmd/flow"
ldflags: -X "github.com/onflow/flow-cli/build.commit=${{ env.COMMIT }}" -X "github.com/onflow/flow-cli/build.semver=${{ env.VERSION }}" -X "github.com/onflow/flow-cli/internal/command.mixpanelToken=${{ env.MIXPANEL_PROJECT_TOKEN }}" -X "github.com/onflow/flow-cli/internal/accounts.accountToken=${{ env.LILICO_TOKEN }}"
go-version: "1.20"
- name: Setup Release Environment
run: |-
echo 'MIXPANEL_PROJECT_TOKEN=${{ secrets.MIXPANEL_PROJECT_TOKEN }}' > .release-env
echo 'LILICO_TOKEN=${{ secrets.LILICO_TOKEN }}' >> .release-env
echo 'APP_VERSION=$(basename ${GITHUB_REF})' >> .release-env
echo 'BUILD_TIME=$(date --iso-8601=seconds)' >> .release-env
echo 'VERSION=${{ github.ref_name }}' >> .release-env
echo 'COMMIT=${{ github.sha }}' >> .release-env
echo 'GITHUB_TOKEN=${{ secrets.FLOW_CLI_RELEASE }}' >> .release-env
- name: Build and Release
run: make release
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ main
*.pkey

# Local development file generation folder
imports
imports

# Goreleaser .env
.release-env
54 changes: 54 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
before:
hooks:
- make generate

builds:
- id: flow-cli
main: ./cmd/flow
goos:
- darwin
- linux
goarch:
- amd64
- arm64
env:
- CGO_FLAGS="-O2 -D__BLST_PORTABLE__"
- CGO_ENABLED=1
- CC_darwin_amd64=o64-clang
- CXX_darwin_amd64=o64-clang+
- CC_darwin_arm64=oa64-clang
- CXX_darwin_arm64=oa64-clang++
- CC_linux_amd64=x86_64-linux-gnu-gcc
- CXX_linux_amd64=x86_64-linux-gnu-g++
- CC_linux_arm64=aarch64-linux-gnu-gcc
- CXX_linux_arm64=aarch64-linux-gnu-g++
- CC_windows_amd64=x86_64-w64-mingw32-gcc
- CXX_windows_amd64=x86_64-w64-mingw32-g++
- CC_windows_arm64=aarch64-w64-mingw32-gcc
- CXX_windows_arm64=aarch64-w64-mingw32-g++
- 'CC={{ index .Env (print "CC_" .Os "_" .Arch) }}'
- 'CXX={{ index .Env (print "CXX_" .Os "_" .Arch) }}'
flags:
- -mod=readonly
ldflags:
- -X github.com/onflow/flow-cli/build.commit={{ .Env.COMMIT }} -X github.com/onflow/flow-cli/build.semver={{ .Env.VERSION }} -X github.com/onflow/flow-cli/internal/command.mixpanelToken={{ .Env.MIXPANEL_PROJECT_TOKEN }} -X github.com/onflow/flow-cli/internal/accounts.accountToken={{ .Env.LILICO_TOKEN }}

archives:
- id: golang-cross
builds:
- flow-cli
name_template: "{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}"
format: tar.gz
wrap_in_directory: false
snapshot:
name_template: "{{ .Tag }}"
changelog:
skip: true
checksum:
name_template: "checksums.txt"
release:
github:
owner: onflow
name: flow-cli
prerelease: auto
draft: false
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Configuration for goreleaser
PACKAGE_NAME := github.com/onflow/flow-cli
GOLANG_CROSS_VERSION ?= v1.20.0

# The short Git commit hash
SHORT_COMMIT := $(shell git rev-parse --short HEAD)
# The Git commit hash
Expand Down Expand Up @@ -103,3 +107,15 @@ check-tidy:
.PHONY: generate
generate: install-tools
go generate ./...

.PHONY: release
release:
docker run \
--rm \
--env-file .release-env \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-v `pwd`/sysroot:/sysroot \
-w /go/src/$(PACKAGE_NAME) \
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
release --clean
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,3 @@ require (
nhooyr.io/websocket v1.8.7 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)

// this is a woraround for the flow-go/crypto cross compliation issue
replace github.com/onflow/crypto => github.com/onflow/crypto v0.24.9
5 changes: 2 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2068,8 +2068,8 @@ github.com/onflow/cadence-tools/test v1.0.0-M3 h1:ZbKoMhXsvafJIOO/MVE7lV5INXfq2I
github.com/onflow/cadence-tools/test v1.0.0-M3/go.mod h1:Yk6OyiRMNseM6C13FpNUxTJ7GekYZMzdX5D2B10y4N8=
github.com/onflow/contract-updater/lib/go/templates v1.0.1 h1:xPj898Y8OgLLbXH8+JeKVBV6J+nqPZjiLgGM3Abucto=
github.com/onflow/contract-updater/lib/go/templates v1.0.1/go.mod h1:OXO6s0X7OW4Q6QTfAfnjoOmibEPgs0psOfMi+tPyzQE=
github.com/onflow/crypto v0.24.9 h1:jYP1qdwid0qCineFzBFlxBchg710A7RuSWpTqxaOdog=
github.com/onflow/crypto v0.24.9/go.mod h1:J/V7IEVaqjDajvF8K0B/SJPJDgAOP2G+LVLeb0hgmbg=
github.com/onflow/crypto v0.25.0 h1:BeWbLsh3ZD13Ej+Uky6kg1PL1ZIVBDVX+2MVBNwqddg=
github.com/onflow/crypto v0.25.0/go.mod h1:C8FbaX0x8y+FxWjbkHy0Q4EASCDR9bSPWZqlpCLYyVI=
github.com/onflow/fcl-dev-wallet v0.8.0-stable-cadence.1 h1:IqdUzdqFCSW0klWmA3J9c17ZyQTab9SWcWSLouX6o0Q=
github.com/onflow/fcl-dev-wallet v0.8.0-stable-cadence.1/go.mod h1:kc42jkiuoPJmxMRFjfbRO9XvnR/3XLheaOerxVMDTiw=
github.com/onflow/flixkit-go v1.1.1-0.20240214222351-03b90f7d32ef h1:nPtuUuIMBcsl9T15qWzat8hYo6lU6ip2WKoYT2p9H4w=
Expand Down Expand Up @@ -2359,7 +2359,6 @@ github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXl
github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8=
github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
github.com/supranational/blst v0.3.8-0.20220526154634-513d2456b344/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw=
github.com/supranational/blst v0.3.10/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw=
github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbeoEm4=
github.com/supranational/blst v0.3.11/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY=
Expand Down

0 comments on commit 7893414

Please sign in to comment.