Skip to content

Commit

Permalink
switch to goreleaser
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink committed Feb 21, 2024
1 parent b066d2e commit c34aba8
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 12 deletions.
41 changes: 29 additions & 12 deletions .github/workflows/build-release.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
name: Build Release

on:
release:
types: [published]

jobs:
releases-matrix:
Expand All @@ -17,14 +13,7 @@ jobs:
- goarch: arm64
goos: windows
steps:
- uses: actions/checkout@v3
- name: Codebase security check
continue-on-error: true
uses: snyk/actions/golang@master
with:
go-version: '1.20'
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}

- name: Determine C compiler
run: |
if [ "${{ matrix.goarch }}" = "arm64" ]; then
Expand Down Expand Up @@ -54,3 +43,31 @@ jobs:
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 }}"
name: Build Release

on:
release:
types: [published]

jobs:
release:
name: Release Go Binary
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Codebase security check
continue-on-error: true
uses: snyk/actions/golang@master
with:
go-version: '1.20'
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
- name: setup dependencies
uses: actions/setup-go@v2
- name: release dry run
run: make release-dry-run
- name: setup release environment
run: |-
echo 'GITHUB_TOKEN=${{secrets.GORELEASER_ACCESS_TOKEN}}' > .release-env
- name: release publish
run: make release
41 changes: 41 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
builds:
- id: darwin-amd64
main: ./cmd/flow
goos:
- darwin
goarch:
- amd64
env:
- PKG_CONFIG_SYSROOT_DIR=/sysroot/macos/amd64
- PKG_CONFIG_PATH=/sysroot/macos/amd64/usr/local/lib/pkgconfig
- CC=o64-clang
- CXX=o64-clang++
flags:
- -mod=readonly
ldflags:
- -s -w -X main.version={{.Version}}
- -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:
- darwin-amd64
name_template: "{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}"
format: zip
wrap_in_directory: true
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'

release:
github:
owner: goreleaser
name: golang-cross-example
prerelease: auto
draft: false
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
PACKAGE_NAME := github.com/onflow/flow-cli
GOLANG_CROSS_VERSION ?= v1.22.0

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

.PHONY: release-dry-run
release-dry-run:
@docker run \
--rm \
-e CGO_ENABLED=1 \
-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} \
--clean --skip=validate --skip=publish

.PHONY: release
release:
docker run \
--rm \
-e CGO_ENABLED=1 \
-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

0 comments on commit c34aba8

Please sign in to comment.