Skip to content

Commit 25ac002

Browse files
MSeveyliamsiramin
authored
Goreleaser (celestiaorg#2661)
## Overview **UPDATE** This PR adds building binaries to the release process by using [goreleaser](https://goreleaser.com/). The CI release process is largely unchanged. Releases can be trigger by either manually triggering the `ci_release` workflow, or they can be triggered by pushing a version tag. If the team has not been using the CI to generate releases, so I added a `make goreleaser-release` command to build the binaries for the release locally so that they can be manually uploaded. Result of running `make goreleaser-release`: ``` build └── goreleaser ├── artifacts.json ├── celestia-node_Darwin_arm64.tar.gz ├── celestia-node_Darwin_x86_64.tar.gz ├── celestia-node_Linux_arm64.tar.gz ├── celestia-node_Linux_x86_64.tar.gz ├── celestia-node_darwin_amd64_v1 │   └── celestia ├── celestia-node_darwin_arm64 │   └── celestia ├── celestia-node_linux_amd64_v1 │   └── celestia ├── celestia-node_linux_arm64 │   └── celestia ├── checksums.txt ├── config.yaml └── metadata.json ``` The `.goreleaser.yaml` file is 90% stock generated from `goreleaser init`. The celestia node specific items are: ```yaml builds: - main: ./cmd/celestia binary: celestia env: # NOTE: goreleaser doesn't fully support CGO natively. If CGO is needed # for any node features, this should be removed and a workaround might # need to be created. # REF: https://goreleaser.com/limitations/cgo/ - CGO_ENABLED=0 - VersioningPath={{ "github.com/celestiaorg/celestia-node/nodebuilder/node" }} goos: - linux - darwin goarch: - amd64 - arm64 ldflags: # Ref: https://goreleaser.com/customization/templates/#common-fields # # .CommitDate is used to help with reproducible builds, ensuring that the # same date is always used # # .FullCommit is git commit hash goreleaser is using for the release # # .Version is the version being released - -X "{{ .Env.VersioningPath }}.buildTime={{ .CommitDate }}" - -X "{{ .Env.VersioningPath }}.lastCommit={{ .FullCommit }}" - -X "{{ .Env.VersioningPath }}.semanticVersion={{ .Version }}" dist: ./build/goreleaser ``` For building locally, i added a `make goreleaser-build` command. The binaries are put into a `build/goreleaser` directory. The `make goreleaser` command lists the `goreleaser` commands and also checks the version as a way to verify you have `goreleaser` installed. Result of running `make goreleaser-build`: ``` build └── goreleaser ├── artifacts.json ├── celestia-node_darwin_amd64_v1 │ └── celestia ├── config.yaml └── metadata.json ``` Successful github action run: https://github.com/MSevey/celestia-node/actions/runs/6123729144/job/16622244813 Example release generated: https://github.com/MSevey/celestia-node/releases Created celestiaorg#2445 as a follow up discussion how to add signing. --------- Co-authored-by: Ismail Khoffi <[email protected]> Co-authored-by: ramin <[email protected]>
1 parent 9260a8b commit 25ac002

File tree

4 files changed

+118
-5
lines changed

4 files changed

+118
-5
lines changed

.github/workflows/ci_release.yml

+37-5
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,51 @@ jobs:
5050
go-ci:
5151
uses: ./.github/workflows/go-ci.yml
5252

53-
# Make a release if this is a manually trigger job, i.e. workflow_dispatch
54-
release:
53+
# If this was a workflow dispatch event, we need to generate and push a tag
54+
# for goreleaser to grab
55+
version_bump:
5556
needs: [hadolint, yamllint, markdown-lint, go-ci]
5657
runs-on: ubuntu-latest
57-
if: ${{ github.event_name == 'workflow_dispatch' }}
5858
permissions: "write-all"
5959
steps:
6060
- uses: actions/checkout@v4
61+
- name: Bump version and push tag
62+
# Placing the if condition here is a workaround for needing to block
63+
# on this step during workflow dispatch events but the step not
64+
# needing to run on tags. If we had the if condition on the full
65+
# version_bump section, it would skip and not run, which would result
66+
# in goreleaser not running either.
67+
if: ${{ github.event_name == 'workflow_dispatch' }}
68+
uses: mathieudutour/[email protected]
69+
6170
- name: Version Release
6271
uses: celestiaorg/.github/.github/actions/[email protected]
6372
with:
64-
github-token: ${{secrets.GITHUB_TOKEN}}
65-
version-bump: ${{inputs.version}}
73+
github_token: ${{ secrets.GITHUB_TOKEN }}
74+
default_bump: ${{ inputs.version }}
75+
76+
# Generate the release with goreleaser to include pre-built binaries
77+
goreleaser:
78+
needs: version_bump
79+
runs-on: ubuntu-latest
80+
if: |
81+
github.event_name == 'workflow_dispatch' ||
82+
(github.event_name == 'push' && contains(github.ref, 'refs/tags/'))
83+
permissions: "write-all"
84+
steps:
85+
- uses: actions/checkout@v3
86+
- run: git fetch --force --tags
87+
- uses: actions/setup-go@v4
88+
with:
89+
go-version: 1.21
90+
# Generate the binaries and release
91+
- uses: goreleaser/goreleaser-action@v4
92+
with:
93+
distribution: goreleaser
94+
version: latest
95+
args: release --clean
96+
env:
97+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6698

6799
# TODO: permission issue, but not worth fixing as this should be refactored
68100
# into the celestiaorg/.github repo, at which point any permission issues will

.goreleaser.yaml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# This is an example .goreleaser.yml file with some sensible defaults.
2+
# Make sure to check the documentation at https://goreleaser.com
3+
before:
4+
hooks:
5+
- go mod tidy
6+
builds:
7+
- main: ./cmd/celestia
8+
binary: celestia
9+
env:
10+
# NOTE: goreleaser doesn't fully support CGO natively. If CGO is needed
11+
# for any node features, this should be removed and a workaround might
12+
# need to be created.
13+
# REF: https://goreleaser.com/limitations/cgo/
14+
- CGO_ENABLED=0
15+
- VersioningPath={{ "github.com/celestiaorg/celestia-node/nodebuilder/node" }}
16+
goos:
17+
- linux
18+
- darwin
19+
goarch:
20+
- amd64
21+
- arm64
22+
ldflags:
23+
# Ref: https://goreleaser.com/customization/templates/#common-fields
24+
#
25+
# .CommitDate is used to help with reproducible builds, ensuring that the
26+
# same date is always used
27+
#
28+
# .FullCommit is git commit hash goreleaser is using for the release
29+
#
30+
# .Version is the version being released
31+
- -X "{{ .Env.VersioningPath }}.buildTime={{ .CommitDate }}"
32+
- -X "{{ .Env.VersioningPath }}.lastCommit={{ .FullCommit }}"
33+
- -X "{{ .Env.VersioningPath }}.semanticVersion={{ .Version }}"
34+
dist: ./build/goreleaser
35+
archives:
36+
- format: tar.gz
37+
# this name template makes the OS and Arch compatible with the results of
38+
# uname.
39+
name_template: >-
40+
{{ .ProjectName }}_
41+
{{- title .Os }}_
42+
{{- if eq .Arch "amd64" }}x86_64
43+
{{- else if eq .Arch "386" }}i386
44+
{{- else }}{{ .Arch }}{{ end }}
45+
{{- if .Arm }}v{{ .Arm }}{{ end }}
46+
checksum:
47+
name_template: "checksums.txt"
48+
snapshot:
49+
name_template: "{{ incpatch .Version }}-next"
50+
changelog:
51+
sort: asc
52+
filters:
53+
exclude:
54+
- "^docs:"
55+
- "^test:"

.yamllint.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
# Built from docs https://yamllint.readthedocs.io/en/stable/configuration.html
3+
extends: default
4+
5+
rules:
6+
# 120 chars should be enough, but don't fail if a line is longer
7+
line-length:
8+
max: 120
9+
level: warning

Makefile

+17
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,20 @@ telemetry-infra-up:
189189
telemetry-infra-down:
190190
PWD="${DIR_FULLPATH}/docker/telemetry" docker-compose -f ./docker/telemetry/docker-compose.yml down
191191
.PHONY: telemetry-infra-down
192+
193+
## goreleaser: List Goreleaser commands and checks if GoReleaser is installed.
194+
goreleaser: Makefile
195+
@echo " Choose a goreleaser command to run:"
196+
@sed -n 's/^## goreleaser/goreleaser/p' $< | column -t -s ':' | sed -e 's/^/ /'
197+
@goreleaser --version
198+
.PHONY: goreleaser
199+
200+
## goreleaser-build: Builds the celestia binary using GoReleaser for your local OS.
201+
goreleaser-build:
202+
goreleaser build --snapshot --clean --single-target
203+
.PHONY: goreleaser-build
204+
205+
## goreleaser-release: Builds the release celestia binaries as defined in .goreleaser.yaml. This requires there be a git tag for the release in the local git history.
206+
goreleaser-release:
207+
goreleaser release --clean --fail-fast --skip-publish
208+
.PHONY: goreleaser-release

0 commit comments

Comments
 (0)