From 2d05dada261881cae01d12d06afab7a1478c8571 Mon Sep 17 00:00:00 2001 From: Snobbish Bee <125891987+snobbee@users.noreply.github.com> Date: Fri, 27 Oct 2023 18:11:24 +0200 Subject: [PATCH 1/2] ci: integrate go releaser --- .github/workflows/release.yml | 65 ++++++++++---- .goreleaser.yaml | 165 ++++++++++++++++++++++++++++++++++ Makefile | 49 ++++++++++ 3 files changed, 260 insertions(+), 19 deletions(-) create mode 100644 .goreleaser.yaml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a700865e12..e083601e8c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,25 +1,52 @@ -name: Release +# name: Release -on: - release: - types: - - published +# on: +# release: +# types: +# - published + +# jobs: +# dispatch: +# runs-on: ubuntu-latest +# steps: +# - name: Get the tag +# id: release_tag +# run: echo ::set-output name=name::${GITHUB_REF/refs\/tags\//} + +# - uses: convictional/trigger-workflow-and-wait@v1.6.1 +# with: +# owner: sifchain +# repo: sifchain-chainops +# github_token: ${{ secrets.GIT_PAT }} +# workflow_file_name: sifnode-release.yml +# client_payload: '{ "release_tag": "${{ steps.release_tag.outputs.name }}" }' +# propagate_failure: false +# trigger_workflow: true +# wait_workflow: true +# This workflow creates a release using goreleaser +# via the 'make release' command. + +name: Create release +on: + push: + tags: + - v* +permissions: + contents: write jobs: - dispatch: + release: + name: Create release runs-on: ubuntu-latest steps: - - name: Get the tag - id: release_tag - run: echo ::set-output name=name::${GITHUB_REF/refs\/tags\//} - - - uses: convictional/trigger-workflow-and-wait@v1.6.1 + - name: Check out repository code + uses: actions/checkout@v3 with: - owner: sifchain - repo: sifchain-chainops - github_token: ${{ secrets.GIT_PAT }} - workflow_file_name: sifnode-release.yml - client_payload: '{ "release_tag": "${{ steps.release_tag.outputs.name }}" }' - propagate_failure: false - trigger_workflow: true - wait_workflow: true + fetch-depth: 0 + ref: ${{ github.event.inputs.release_tag }} + - name: Make release + run: | + sudo rm -rf dist + make release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000000..b742f43f6e --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,165 @@ +project_name: sifnoded +env: + - CGO_ENABLED=1 +builds: + - id: sifnoded-darwin-amd64 + main: ./cmd/sifnoded/main.go + binary: sifnoded + env: + - CC=o64-clang + - CGO_LDFLAGS=-L/lib + goos: + - darwin + goarch: + - amd64 + flags: + - -mod=readonly + - -trimpath + ldflags: + - -X github.com/cosmos/cosmos-sdk/version.Name=sifchain + - -X github.com/cosmos/cosmos-sdk/version.AppName=sifnoded + - -X github.com/cosmos/cosmos-sdk/version.Version={{ .Version }} + - -X github.com/cosmos/cosmos-sdk/version.Commit={{ .Commit }} + - -X github.com/cosmos/cosmos-sdk/version.BuildTags=ledger + tags: + - ledger + - id: sifnoded-darwin-arm64 + main: ./cmd/sifnoded/main.go + binary: sifnoded + env: + - CC=oa64-clang + - CGO_LDFLAGS=-L/lib + goos: + - darwin + goarch: + - arm64 + flags: + - -mod=readonly + - -trimpath + ldflags: + - -X github.com/cosmos/cosmos-sdk/version.Name=sifchain + - -X github.com/cosmos/cosmos-sdk/version.AppName=sifnoded + - -X github.com/cosmos/cosmos-sdk/version.Version=v{{ .Version }} + - -X github.com/cosmos/cosmos-sdk/version.Commit={{ .Commit }} + - -X github.com/cosmos/cosmos-sdk/version.BuildTags=ledger + tags: + - ledger + - id: sifnoded-linux-amd64 + main: ./cmd/sifnoded + binary: sifnoded + goos: + - linux + goarch: + - amd64 + env: + - CC=x86_64-linux-gnu-gcc + flags: + - -mod=readonly + - -trimpath + ldflags: + - -X github.com/cosmos/cosmos-sdk/version.Name=sifchain + - -X github.com/cosmos/cosmos-sdk/version.AppName=sifnoded + - -X github.com/cosmos/cosmos-sdk/version.Version=v{{ .Version }} + - -X github.com/cosmos/cosmos-sdk/version.Commit={{ .Commit }} + - -X github.com/cosmos/cosmos-sdk/version.BuildTags=ledger + tags: + - ledger + - id: sifnoded-linux-arm64 + main: ./cmd/sifnoded + binary: sifnoded + goos: + - linux + goarch: + - arm64 + env: + - CC=aarch64-linux-gnu-gcc + flags: + - -mod=readonly + - -trimpath + ldflags: + - -X github.com/cosmos/cosmos-sdk/version.Name=sifchain + - -X github.com/cosmos/cosmos-sdk/version.AppName=sifnoded + - -X github.com/cosmos/cosmos-sdk/version.Version=v{{ .Version }} + - -X github.com/cosmos/cosmos-sdk/version.Commit={{ .Commit }} + - -X github.com/cosmos/cosmos-sdk/version.BuildTags=ledger + tags: + - ledger +universal_binaries: + - id: sifnoded-darwin-universal + ids: + - sifnoded-darwin-amd64 + - sifnoded-darwin-arm64 + replace: false +archives: + - id: zipped + builds: + - sifnoded-darwin-universal + - sifnoded-linux-amd64 + - sifnoded-linux-arm64 + - sifnoded-darwin-amd64 + - sifnoded-darwin-arm64 + name_template: "{{.ProjectName}}-v{{ .Version }}-{{ .Os }}-{{ .Arch }}" + format: tar.gz + files: + - none* + - id: binaries + builds: + - sifnoded-darwin-universal + - sifnoded-linux-amd64 + - sifnoded-linux-arm64 + - sifnoded-darwin-amd64 + - sifnoded-darwin-arm64 + name_template: "{{.ProjectName}}-v{{ .Version }}-{{ .Os }}-{{ .Arch }}" + format: binary + files: + - none* +checksum: + name_template: "sha256sum.txt" + algorithm: sha256 +# Docs: https://goreleaser.com/customization/changelog/ +changelog: + skip: true +# Docs: https://goreleaser.com/customization/release/ +release: + github: + owner: sifchain + name: sifnode + replace_existing_draft: true + header: | + ## Overview + + < DETAILS OF THE UPDATE > + + ## 📦 Executable Files + + Available binaries files for both Linux and Darwin (covering amd64 and arm64 architectures) are listed below. For Darwin users, a universal binary named `sifnoded-v{{ .Version }}-darwin-all` can be utilized for both amd64 and arm64. + + #### 🛠 Compile from Source + + If you wish to compile the software from its source, follow these steps: + + ```bash + git clone https://github.com/sifchain/sifnode + cd sifchain && git checkout v{{ .Version }} + make install + ``` + + ## Updates & Enhancements + + For a comprehensive list of modifications, refer to the changelog [here](https://github.com/sifchain/sifnode/blob/v{{ .Version }}/CHANGELOG.md). + name_template: "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/Makefile b/Makefile index a2be8d12f6..9de3c7d911 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,8 @@ DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bu GOFLAGS:="" GOTAGS:=ledger +GO_VERSION := $(shell cat go.mod | grep -E 'go [0-9].[0-9]+' | cut -d ' ' -f 2) + ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=sifchain \ -X github.com/cosmos/cosmos-sdk/version.ServerName=sifnoded \ -X github.com/cosmos/cosmos-sdk/version.ClientName=sifnoded \ @@ -122,3 +124,50 @@ proto-check-breaking: # we should turn this back on after our first release # $(DOCKER_BUF) breaking --against $(HTTPS_GIT)#branch=master .PHONY: proto-check-breaking + +GORELEASER_IMAGE := ghcr.io/goreleaser/goreleaser-cross:v$(GO_VERSION) + +## release: Build binaries for all platforms and generate checksums +ifdef GITHUB_TOKEN +release: + docker run \ + --rm \ + -e GITHUB_TOKEN=$(GITHUB_TOKEN) \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v `pwd`:/go/src/sifnoded \ + -w /go/src/sifnoded \ + $(GORELEASER_IMAGE) \ + release \ + --clean +else +release: + @echo "Error: GITHUB_TOKEN is not defined. Please define it before running 'make release'." +endif + +## release-dry-run: Dry-run build process for all platforms and generate checksums +release-dry-run: + docker run \ + --rm \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v `pwd`:/go/src/sifnoded \ + -w /go/src/sifnoded \ + $(GORELEASER_IMAGE) \ + release \ + --clean \ + --skip-publish + +## release-snapshot: Build snapshots for all platforms and generate checksums +release-snapshot: + docker run \ + --rm \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v `pwd`:/go/src/sifnoded \ + -w /go/src/sifnoded \ + $(GORELEASER_IMAGE) \ + release \ + --clean \ + --snapshot \ + --skip-validate \ + --skip-publish + +.PHONY: release release-dry-run release-snapshot \ No newline at end of file From e7024c1e836999c22c691362606d226a62b08108 Mon Sep 17 00:00:00 2001 From: Snobbish Bee <125891987+snobbee@users.noreply.github.com> Date: Tue, 31 Oct 2023 04:30:46 +0100 Subject: [PATCH 2/2] =?UTF-8?q?build(=C3=A7):=20align=20ld=20flags?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ .goreleaser.yaml | 12 ++++++++---- Makefile | 39 +++++++++++++++++++++++---------------- go.mod | 2 +- 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 573cafffc8..9c1a9f73b8 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,5 @@ smart-contracts/yarn-error.log test/integration/output.json test/integration/sifchainrelayerdb/* *.log + +dist \ No newline at end of file diff --git a/.goreleaser.yaml b/.goreleaser.yaml index b742f43f6e..49758a9ff3 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -17,7 +17,8 @@ builds: - -trimpath ldflags: - -X github.com/cosmos/cosmos-sdk/version.Name=sifchain - - -X github.com/cosmos/cosmos-sdk/version.AppName=sifnoded + - -X github.com/cosmos/cosmos-sdk/version.ServerName=sifnoded + - -X github.com/cosmos/cosmos-sdk/version.ClientName=sifnoded - -X github.com/cosmos/cosmos-sdk/version.Version={{ .Version }} - -X github.com/cosmos/cosmos-sdk/version.Commit={{ .Commit }} - -X github.com/cosmos/cosmos-sdk/version.BuildTags=ledger @@ -38,7 +39,8 @@ builds: - -trimpath ldflags: - -X github.com/cosmos/cosmos-sdk/version.Name=sifchain - - -X github.com/cosmos/cosmos-sdk/version.AppName=sifnoded + - -X github.com/cosmos/cosmos-sdk/version.ServerName=sifnoded + - -X github.com/cosmos/cosmos-sdk/version.ClientName=sifnoded - -X github.com/cosmos/cosmos-sdk/version.Version=v{{ .Version }} - -X github.com/cosmos/cosmos-sdk/version.Commit={{ .Commit }} - -X github.com/cosmos/cosmos-sdk/version.BuildTags=ledger @@ -58,7 +60,8 @@ builds: - -trimpath ldflags: - -X github.com/cosmos/cosmos-sdk/version.Name=sifchain - - -X github.com/cosmos/cosmos-sdk/version.AppName=sifnoded + - -X github.com/cosmos/cosmos-sdk/version.ServerName=sifnoded + - -X github.com/cosmos/cosmos-sdk/version.ClientName=sifnoded - -X github.com/cosmos/cosmos-sdk/version.Version=v{{ .Version }} - -X github.com/cosmos/cosmos-sdk/version.Commit={{ .Commit }} - -X github.com/cosmos/cosmos-sdk/version.BuildTags=ledger @@ -78,7 +81,8 @@ builds: - -trimpath ldflags: - -X github.com/cosmos/cosmos-sdk/version.Name=sifchain - - -X github.com/cosmos/cosmos-sdk/version.AppName=sifnoded + - -X github.com/cosmos/cosmos-sdk/version.ServerName=sifnoded + - -X github.com/cosmos/cosmos-sdk/version.ClientName=sifnoded - -X github.com/cosmos/cosmos-sdk/version.Version=v{{ .Version }} - -X github.com/cosmos/cosmos-sdk/version.Commit={{ .Commit }} - -X github.com/cosmos/cosmos-sdk/version.BuildTags=ledger diff --git a/Makefile b/Makefile index 9de3c7d911..6668fd8e18 100644 --- a/Makefile +++ b/Makefile @@ -1,29 +1,30 @@ -CHAINNET?=betanet -BINARY?=sifnoded -GOPATH?=$(shell go env GOPATH) -GOBIN?=$(GOPATH)/bin -NOW=$(shell date +'%Y-%m-%d_%T') -COMMIT:=$(shell git log -1 --format='%H') -VERSION:=$(shell cat version) -IMAGE_TAG?=latest +CHAINNET ?= betanet +BINARY ?= sifnoded +GOPATH ?= $(shell go env GOPATH) +GOBIN ?= $(GOPATH)/bin +NOW = $(shell date +'%Y-%m-%d_%T') +COMMIT := $(shell git log -1 --format='%H') +VERSION := $(shell cat version) +IMAGE_TAG ?= latest HTTPS_GIT := https://github.com/sifchain/sifnode.git DOCKER ?= docker DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf -GOFLAGS:="" -GOTAGS:=ledger +GOFLAGS := "" +GOTAGS := ledger GO_VERSION := $(shell cat go.mod | grep -E 'go [0-9].[0-9]+' | cut -d ' ' -f 2) -ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=sifchain \ +LDFLAGS = -X github.com/cosmos/cosmos-sdk/version.Name=sifchain \ -X github.com/cosmos/cosmos-sdk/version.ServerName=sifnoded \ -X github.com/cosmos/cosmos-sdk/version.ClientName=sifnoded \ -X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \ - -X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) + -X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \ + -X github.com/cosmos/cosmos-sdk/version.BuildTags=$(GOTAGS) -BUILD_FLAGS := -ldflags '$(ldflags)' -tags '$(GOTAGS)' +BUILD_FLAGS := -ldflags '$(LDFLAGS)' -tags '$(GOTAGS)' -BINARIES=./cmd/sifnoded ./cmd/sifgen ./cmd/ebrelayer ./cmd/siftest +BINARIES = ./cmd/sifnoded ./cmd/sifgen ./cmd/ebrelayer ./cmd/siftest all: lint install @@ -90,8 +91,8 @@ rollback: ### Protobuf ### ############################################################################### -protoVer=v0.3 -protoImageName=tendermintdev/sdk-proto-gen:$(protoVer) +protoVer = v0.3 +protoImageName = tendermintdev/sdk-proto-gen:$(protoVer) proto-all: proto-format proto-lint proto-gen @@ -133,6 +134,8 @@ release: docker run \ --rm \ -e GITHUB_TOKEN=$(GITHUB_TOKEN) \ + -e LDFLAGS="$(LDFLAGS)" \ + -e GOTAGS="$(GOTAGS)" \ -v /var/run/docker.sock:/var/run/docker.sock \ -v `pwd`:/go/src/sifnoded \ -w /go/src/sifnoded \ @@ -148,6 +151,8 @@ endif release-dry-run: docker run \ --rm \ + -e LDFLAGS="$(LDFLAGS)" \ + -e GOTAGS="$(GOTAGS)" \ -v /var/run/docker.sock:/var/run/docker.sock \ -v `pwd`:/go/src/sifnoded \ -w /go/src/sifnoded \ @@ -160,6 +165,8 @@ release-dry-run: release-snapshot: docker run \ --rm \ + -e LDFLAGS="$(LDFLAGS)" \ + -e GOTAGS="$(GOTAGS)" \ -v /var/run/docker.sock:/var/run/docker.sock \ -v `pwd`:/go/src/sifnoded \ -w /go/src/sifnoded \ diff --git a/go.mod b/go.mod index fbfcc4ceb1..430d1b8889 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/Sifchain/sifnode -go 1.18 +go 1.20 require ( github.com/BurntSushi/toml v1.2.0