From ef5265c70698b2c45ba896b1f3b6dd4e788ad49d Mon Sep 17 00:00:00 2001 From: Leo Pang <34628052+allthatjazzleo@users.noreply.github.com> Date: Mon, 16 Sep 2024 10:52:22 +0800 Subject: [PATCH] fix goreleaser binary release and docker image release (#79) --- .github/workflows/docker.yml | 10 ++ .github/workflows/release.yml | 52 +++++++++- .goreleaser.yaml | 18 +--- Makefile | 19 ++-- chains.yaml | 3 - scripts/ci-goreleaser/.goreleaser.yaml | 119 ++++++++++++++++++++++ scripts/ci-goreleaser/.goreleaser_hook.sh | 8 ++ scripts/ci-goreleaser/goreleaser.go | 3 + 8 files changed, 204 insertions(+), 28 deletions(-) create mode 100644 scripts/ci-goreleaser/.goreleaser.yaml create mode 100755 scripts/ci-goreleaser/.goreleaser_hook.sh create mode 100644 scripts/ci-goreleaser/goreleaser.go diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index f14df585..73cc0f71 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -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 @@ -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 @@ -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 }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dffeafe7..78f72c76 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,6 +1,4 @@ # This workflow creates a release using goreleaser -# via the 'make release' command. - name: Create release on: @@ -17,8 +15,49 @@ 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 @@ -26,6 +65,13 @@ jobs: 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 @@ -33,3 +79,5 @@ jobs: 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 diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 24bedd80..231e3714 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -80,6 +80,7 @@ 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 @@ -87,8 +88,6 @@ builds: - linux goarch: - amd64 - env: - - CC=x86_64-linux-gnu-gcc flags: - -mod=readonly - -trimpath @@ -113,6 +112,7 @@ 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 @@ -120,8 +120,6 @@ builds: - linux goarch: - arm64 - env: - - CC=aarch64-linux-gnu-gcc flags: - -mod=readonly - -trimpath @@ -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 @@ -162,7 +152,6 @@ archives: - none* - id: binaries builds: - # - mantrachaind-darwin-universal - mantrachaind-linux-amd64 - mantrachaind-linux-arm64 - mantrachaind-darwin-amd64 @@ -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 diff --git a/Makefile b/Makefile index b45f68bc..149690e9 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 \ @@ -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 diff --git a/chains.yaml b/chains.yaml index ce66b45c..be72673c 100644 --- a/chains.yaml +++ b/chains.yaml @@ -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 diff --git a/scripts/ci-goreleaser/.goreleaser.yaml b/scripts/ci-goreleaser/.goreleaser.yaml new file mode 100644 index 00000000..0d105b5b --- /dev/null +++ b/scripts/ci-goreleaser/.goreleaser.yaml @@ -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!' diff --git a/scripts/ci-goreleaser/.goreleaser_hook.sh b/scripts/ci-goreleaser/.goreleaser_hook.sh new file mode 100755 index 00000000..1f8cf159 --- /dev/null +++ b/scripts/ci-goreleaser/.goreleaser_hook.sh @@ -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/ diff --git a/scripts/ci-goreleaser/goreleaser.go b/scripts/ci-goreleaser/goreleaser.go new file mode 100644 index 00000000..38dd16da --- /dev/null +++ b/scripts/ci-goreleaser/goreleaser.go @@ -0,0 +1,3 @@ +package main + +func main() {}