Skip to content

Commit

Permalink
fix goreleaser binary release and docker image release (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
allthatjazzleo authored Sep 16, 2024
1 parent 6268b66 commit ef5265c
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 28 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
inputs:
release_tag:
description: "The desired tag for the release (e.g. v0.1.0)."
required: true

env:
REGISTRY: ghcr.io
Expand All @@ -22,6 +27,9 @@ jobs:
runs-on: chain-runner
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.inputs.release_tag || github.ref }}

- uses: docker/setup-qemu-action@v3

Expand All @@ -43,6 +51,8 @@ jobs:
chain: mantrachain
chains-spec-file: chains.yaml
clone-key: ${{ secrets.GIT_CLONE_KEY }}
heighliner-owner: ${{ github.repository_owner }}
heighliner-tag: v1.6.4
github-organization: ${{ github.repository_owner }}
github-repo: ${{ github.event.repository.name }}
registry: ghcr.io/${{ env.OWNER_LC }}
52 changes: 50 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# This workflow creates a release using goreleaser
# via the 'make release' command.

name: Create release

on:
Expand All @@ -17,19 +15,69 @@ permissions:
contents: write

jobs:
build:
name: Build - ${{ matrix.platform.name }}
runs-on: ${{ matrix.platform.runner || 'chain-runner' }}
strategy:
matrix:
platform:
- name: Linux x86_64
ids: mantrachaind-linux-amd64
cross: false
- name: Linux aarch64
ids: mantrachaind-linux-arm64
runner: ubuntu-arm64
docker-platform: linux/arm64
cross: false
- name: MacOS x86_64 and aarch64
ids: mantrachaind-darwin-amd64,mantrachaind-darwin-arm64
cross: true

steps:
- name: Checkout Git repo
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.inputs.release_tag || github.ref }}

- name: Make goreleaser build
run: |
make goreleaser-build-local
env:
GORELEASER_IDS: ${{ matrix.platform.ids }}
GORELEASER_CROSS_DISABLE: ${{ !matrix.platform.cross }}
GORELEASER_PLATFORM: ${{ matrix.platform.docker-platform || 'linux/amd64' }}

- name: Store artifact
uses: actions/upload-artifact@v4
with:
name: release-${{ github.sha }}-${{ matrix.platform.name }}
path: dist/*/
retention-days: 1

release:
name: Create release
needs: [build]
runs-on: chain-runner
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.inputs.release_tag || github.ref }}

# Download all artifacts
- uses: actions/download-artifact@v4
with:
path: dist-merged
pattern: release-${{ github.sha }}-*
merge-multiple: true
- name: Make release
run: |
make release
env:
REPO_OWNER: ${{ github.repository_owner }}
REPO_NAME: ${{ github.event.repository.name }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GORELEASER_SKIP: validate
GORELEASER_CONFIG: ./scripts/ci-goreleaser/.goreleaser.yaml
18 changes: 2 additions & 16 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,14 @@ builds:
binary: mantrachaind
hooks:
pre:
- apk add --update linux-headers
- wget https://github.com/CosmWasm/wasmvm/releases/download/{{ .Env.COSMWASM_VERSION }}/libwasmvm_muslc.x86_64.a -O /lib/libwasmvm_muslc.x86_64.a
# verify checksum
- sha256sum /lib/libwasmvm_muslc.x86_64.a | grep $(cat /tmp/checksums.txt | grep libwasmvm_muslc.x86_64 | cut -d ' ' -f 1) || exit 1
goos:
- linux
goarch:
- amd64
env:
- CC=x86_64-linux-gnu-gcc
flags:
- -mod=readonly
- -trimpath
Expand All @@ -113,15 +112,14 @@ builds:
binary: mantrachaind
hooks:
pre:
- apk add --update linux-headers
- wget https://github.com/CosmWasm/wasmvm/releases/download/{{ .Env.COSMWASM_VERSION }}/libwasmvm_muslc.aarch64.a -O /lib/libwasmvm_muslc.aarch64.a
# verify checksum
- sha256sum /lib/libwasmvm_muslc.aarch64.a | grep $(cat /tmp/checksums.txt | grep libwasmvm_muslc.aarch64 | cut -d ' ' -f 1) || exit 1
goos:
- linux
goarch:
- arm64
env:
- CC=aarch64-linux-gnu-gcc
flags:
- -mod=readonly
- -trimpath
Expand All @@ -141,17 +139,9 @@ builds:
- muslc
- osusergo

universal_binaries:
- id: mantrachaind-darwin-universal
ids:
- mantrachaind-darwin-amd64
- mantrachaind-darwin-arm64
replace: false

archives:
- id: zipped
builds:
# - mantrachaind-darwin-universal
- mantrachaind-linux-amd64
- mantrachaind-linux-arm64
- mantrachaind-darwin-amd64
Expand All @@ -162,7 +152,6 @@ archives:
- none*
- id: binaries
builds:
# - mantrachaind-darwin-universal
- mantrachaind-linux-amd64
- mantrachaind-linux-arm64
- mantrachaind-darwin-amd64
Expand Down Expand Up @@ -207,9 +196,6 @@ release:
mode: replace
draft: true

snapshot:
name_template: SNAPSHOT-{{ .Commit }}

# Docs: https://goreleaser.com/customization/announce/
# We could automatically announce the release in
# - discord
Expand Down
19 changes: 12 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,12 @@ test-connect: build-image
###############################################################################
### Release ###
###############################################################################
ifeq ($(strip $(GORELEASER_CROSS_DISABLE)),true)
GORELEASER_IMAGE := goreleaser/goreleaser:v2.3.1
else
GORELEASER_IMAGE := ghcr.io/goreleaser/goreleaser-cross:v$(GO_VERSION)
endif
GORELEASER_PLATFORM ?= linux/amd64
COSMWASM_VERSION := $(shell go list -m github.com/CosmWasm/wasmvm/v2 | sed 's/.* //')
REPO_OWNER ?= MANTRA-Chain
REPO_NAME ?= mantrachain
Expand All @@ -170,16 +175,16 @@ release:
-e REPO_NAME=$(REPO_NAME) \
-v `pwd`:/go/src/mantrachaind \
-w /go/src/mantrachaind \
--platform=linux/amd64 \
--platform=$(GORELEASER_PLATFORM) \
$(GORELEASER_IMAGE) \
release \
release $(if $(GORELEASER_SKIP),--skip=$(GORELEASER_SKIP)) $(if $(GORELEASER_CONFIG),--config=$(GORELEASER_CONFIG)) \
--clean
else
release:
@echo "Error: $(MISSING_TOKEN) is not defined. Please define it before running 'make release'."
endif

# uses goreleaser to create static binaries for linux an darwin on local machine
# uses goreleaser to create static binaries for linux and darwin on local machine
# platform is set because not setting it results in broken builds for linux-amd64
goreleaser-build-local:
docker run \
Expand All @@ -190,11 +195,11 @@ goreleaser-build-local:
-e REPO_NAME=$(REPO_NAME) \
-v `pwd`:/go/src/mantrachaind \
-w /go/src/mantrachaind \
--platform=linux/amd64 \
--platform=$(GORELEASER_PLATFORM) \
$(GORELEASER_IMAGE) \
release \
--snapshot \
--skip=publish \
build $(if $(GORELEASER_IDS),$(shell echo $(GORELEASER_IDS) | tr ',' ' ' | sed 's/[^ ]*/--id=&/g')) \
--skip=validate \
--clean \
--timeout 90m \
--verbose

Expand Down
3 changes: 0 additions & 3 deletions chains.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
github-organization: MANTRA-Chain
github-repo: mantrachain
dockerfile: cosmos
# TODO: should fix in heighliner cosmos/dockerfile once heighliner v1.6.4 is released
build-target: |
[ -f /lib/libwasmvm_muslc.a ] && cp /lib/libwasmvm_muslc.a /lib/libwasmvm_muslc.x86_64.a
[ -f /usr/aarch64-linux-musl/lib/libwasmvm_muslc.a ] && cp /usr/aarch64-linux-musl/lib/libwasmvm_muslc.a /usr/aarch64-linux-musl/lib/libwasmvm_muslc.aarch64.a
LEDGER_ENABLED=true BUILD_TAGS='muslc osusergo' LINK_STATICALLY=true make build
binaries:
- build/mantrachaind
Expand Down
119 changes: 119 additions & 0 deletions scripts/ci-goreleaser/.goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
---
version: 2
project_name: mantrachaind

builds:
- id: mantrachaind-darwin-amd64
main: ./scripts/ci-goreleaser/goreleaser.go
binary: mantrachaind
goos:
- darwin
goarch:
- amd64
hooks:
post:
- ./scripts/ci-goreleaser/.goreleaser_hook.sh {{ .Arch }} {{ .Os }} {{ .ProjectName }}

- id: mantrachaind-darwin-arm64
main: ./scripts/ci-goreleaser/goreleaser.go
binary: mantrachaind
goos:
- darwin
goarch:
- arm64
hooks:
post:
- ./scripts/ci-goreleaser/.goreleaser_hook.sh {{ .Arch }} {{ .Os }} {{ .ProjectName }}

- id: mantrachaind-linux-amd64
main: ./scripts/ci-goreleaser/goreleaser.go
binary: mantrachaind
goos:
- linux
goarch:
- amd64
hooks:
post:
- ./scripts/ci-goreleaser/.goreleaser_hook.sh {{ .Arch }} {{ .Os }} {{ .ProjectName }}

- id: mantrachaind-linux-arm64
main: ./scripts/ci-goreleaser/goreleaser.go
binary: mantrachaind
goos:
- linux
goarch:
- arm64
hooks:
post:
- ./scripts/ci-goreleaser/.goreleaser_hook.sh {{ .Arch }} {{ .Os }} {{ .ProjectName }}

archives:
- id: zipped
builds:
- mantrachaind-linux-amd64
- mantrachaind-linux-arm64
- mantrachaind-darwin-amd64
- mantrachaind-darwin-arm64
name_template: "{{.ProjectName}}-{{ .Version }}-{{ .Os }}-{{ .Arch }}"
format: tar.gz
files:
- none*
- id: binaries
builds:
- mantrachaind-linux-amd64
- mantrachaind-linux-arm64
- mantrachaind-darwin-amd64
- mantrachaind-darwin-arm64
name_template: "{{.ProjectName}}-{{ .Version }}-{{ .Os }}-{{ .Arch }}"
format: binary
files:
- none*

checksum:
name_template: "sha256sum.txt"
algorithm: sha256

# Docs: https://goreleaser.com/customization/changelog/
changelog:
disable: true

# Docs: https://goreleaser.com/customization/release/
release:
github:
owner: "{{ .Env.REPO_OWNER }}"
name: "{{ .Env.REPO_NAME }}"
replace_existing_draft: true
header: |
< DESCRIPTION OF RELEASE >
## Changelog
See the full changelog [here](https://github.com/{{ .Env.REPO_OWNER }}/{{ .Env.REPO_NAME }}/blob/v{{ .Version }}/CHANGELOG.md)
#### 🔨 Build from source
If you prefer to build from source, you can use the following commands:
````bash
git clone https://github.com/{{ .Env.REPO_OWNER }}/{{ .Env.REPO_NAME }}
cd mantrachain && git checkout v{{ .Version }}
make install
````
name_template: "Mantrachain v{{.Version}}"
mode: replace
draft: true

# Docs: https://goreleaser.com/customization/announce/
# We could automatically announce the release in
# - discord
# - slack
# - twitter
# - webhooks
# - telegram
# - reddit
#
# announce:
# discord:
# enabled: true
# message_template: 'New {{.Tag}} is out!'
8 changes: 8 additions & 0 deletions scripts/ci-goreleaser/.goreleaser_hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

go_arch=$1
go_os=$2
project_name=$3

# copy build directory to the corresponding directory
cp -r dist-merged/${project_name}-${go_os}-${go_arch}* dist/
3 changes: 3 additions & 0 deletions scripts/ci-goreleaser/goreleaser.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package main

func main() {}

0 comments on commit ef5265c

Please sign in to comment.