Skip to content

Commit

Permalink
CI: Generate binary supported both amd and arm (#847)
Browse files Browse the repository at this point in the history
  • Loading branch information
anhductn2001 authored Apr 17, 2024
1 parent 78d6efc commit 1028159
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 43 deletions.
76 changes: 33 additions & 43 deletions .github/workflows/release_binary.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,35 @@
---
name: Release Binary

on:
release:
types: [created]

permissions:
contents: read
packages: write
name: Release Binary

jobs:
release:
permissions: write-all
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Docker compose
run: docker-compose up -d

- name: Copy binary
run: docker cp dymension_node_1:/usr/local/bin/dymd ./dymd

- name: Save sha256 sum
run: sha256sum ./dymd > ./dymd_sha256.txt

- name: Release
uses: softprops/action-gh-release@v1
with:
token: ${{ github.token }}
files: |
dymd
dymd_sha256.txt
- name: Dump docker logs on failure
if: failure()
uses: jwalton/gh-docker-logs@v2
on:
release:
types: [created]

permissions: write-all

# This workflow creates a release using goreleaser
# via the 'make release' command.

jobs:
release:
runs-on: ubuntu-latest
environment: release
steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
check-latest: true

- name: Setup release environment
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |-
echo 'GITHUB_TOKEN=${{secrets.GITHUB_TOKEN}}' > .release-env
- name: Release publish
run: make release
104 changes: 104 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
before:
hooks:
- go mod download

builds:
- id: "dymd-darwin"
main: ./cmd/dymd
binary: dymd
env:
- CGO_ENABLED=1
- CC=o64-clang
- CXX=o64-clang++
goos:
- darwin
goarch:
- amd64
flags:
- -tags=cgo
ldflags:
- -s -w -X github.com/cosmos/cosmos-sdk/version.Name=dymension -X github.com/cosmos/cosmos-sdk/version.AppName=dymd -X github.com/cosmos/cosmos-sdk/version.Version={{.Version}} -X github.com/cosmos/cosmos-sdk/version.Commit={{.Commit}}
- id: "dymd-darwin-arm64"
main: ./cmd/dymd
binary: dymd
env:
- CGO_ENABLED=1
- CC=oa64-clang
- CXX=oa64-clang++
goos:
- darwin
goarch:
- arm64
flags:
- -tags=cgo
ldflags:
- -s -w -X github.com/cosmos/cosmos-sdk/version.Name=dymension -X github.com/cosmos/cosmos-sdk/version.AppName=dymd -X github.com/cosmos/cosmos-sdk/version.Version={{.Version}} -X github.com/cosmos/cosmos-sdk/version.Commit={{.Commit}}
- id: "dymd-linux"
main: ./cmd/dymd
binary: dymd
env:
- CGO_ENABLED=1
- CC=gcc
- CXX=g++
goos:
- linux
goarch:
- amd64
flags:
- -tags=cgo
ldflags:
- -s -w -X github.com/cosmos/cosmos-sdk/version.Name=dymension -X github.com/cosmos/cosmos-sdk/version.AppName=dymd -X github.com/cosmos/cosmos-sdk/version.Version={{.Version}} -X github.com/cosmos/cosmos-sdk/version.Commit={{.Commit}}
- id: "dymd-linux-arm64"
main: ./cmd/dymd
binary: dymd
env:
- CGO_ENABLED=1
- CC=aarch64-linux-gnu-gcc
- CXX=aarch64-linux-gnu-g++
goos:
- linux
goarch:
- arm64
flags:
- -tags=cgo
ldflags:
- -s -w -X github.com/cosmos/cosmos-sdk/version.Name=dymension -X github.com/cosmos/cosmos-sdk/version.AppName=dymd -X github.com/cosmos/cosmos-sdk/version.Version={{.Version}} -X github.com/cosmos/cosmos-sdk/version.Commit={{.Commit}}
- id: "dymd-windows"
main: ./cmd/dymd
binary: dymd
env:
- CGO_ENABLED=1
- CC=x86_64-w64-mingw32-gcc
- CXX=x86_64-w64-mingw32-g++
goos:
- windows
goarch:
- amd64
flags:
- -tags=cgo
- -buildmode=exe
ldflags:
- -s -w -X github.com/cosmos/cosmos-sdk/version.Name=dymension -X github.com/cosmos/cosmos-sdk/version.AppName=dymd -X github.com/cosmos/cosmos-sdk/version.Version={{.Version}} -X github.com/cosmos/cosmos-sdk/version.Commit={{.Commit}}

archives:
- name_template: '{{ .ProjectName }}_{{ .Version }}_{{- title .Os }}_{{ .Arch }}'
format_overrides:
- goos: windows
format: zip
builds:
- dymd-darwin
- dymd-darwin-arm64
- dymd-windows
- dymd-linux
- dymd-linux-arm64

checksum:
name_template: 'checksums.txt'
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
snapshot:
name_template: "{{ .Tag }}-next"
37 changes: 37 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,43 @@ docker-build-e2e-debug:
docker-run-debug:
@DOCKER_BUILDKIT=1 docker-compose -f docker-compose.debug.yml up

###############################################################################
### Releasing ###
###############################################################################

PACKAGE_NAME:=github.com/dymensionxyz/dymension
GOLANG_CROSS_VERSION = v1.22
GOPATH ?= '$(HOME)/go'
release-dry-run:
docker run \
--rm \
--privileged \
-e CGO_ENABLED=1 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-v ${GOPATH}/pkg:/go/pkg \
-w /go/src/$(PACKAGE_NAME) \
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
--clean --skip=validate --skip=publish --snapshot

release:
@if [ ! -f ".release-env" ]; then \
echo "\033[91m.release-env is required for release\033[0m";\
exit 1;\
fi
docker run \
--rm \
--privileged \
-e CGO_ENABLED=1 \
--env-file .release-env \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-w /go/src/$(PACKAGE_NAME) \
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
release --clean --skip=validate

.PHONY: release-dry-run release

###############################################################################
### Proto ###
###############################################################################
Expand Down

0 comments on commit 1028159

Please sign in to comment.