Skip to content

Commit

Permalink
Goreleaser (celestiaorg#2661)
Browse files Browse the repository at this point in the history
## 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 <Ismail.Khoffi@gmail.com>
Co-authored-by: ramin <raminkeene@gmail.com>
  • Loading branch information
3 people authored Sep 13, 2023
1 parent 9260a8b commit 25ac002
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 5 deletions.
42 changes: 37 additions & 5 deletions .github/workflows/ci_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,51 @@ jobs:
go-ci:
uses: ./.github/workflows/go-ci.yml

# Make a release if this is a manually trigger job, i.e. workflow_dispatch
release:
# If this was a workflow dispatch event, we need to generate and push a tag
# for goreleaser to grab
version_bump:
needs: [hadolint, yamllint, markdown-lint, go-ci]
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_dispatch' }}
permissions: "write-all"
steps:
- uses: actions/checkout@v4
- name: Bump version and push tag
# Placing the if condition here is a workaround for needing to block
# on this step during workflow dispatch events but the step not
# needing to run on tags. If we had the if condition on the full
# version_bump section, it would skip and not run, which would result
# in goreleaser not running either.
if: ${{ github.event_name == 'workflow_dispatch' }}
uses: mathieudutour/github-tag-action@v6.0

- name: Version Release
uses: celestiaorg/.github/.github/actions/version-release@v0.2.2
with:
github-token: ${{secrets.GITHUB_TOKEN}}
version-bump: ${{inputs.version}}
github_token: ${{ secrets.GITHUB_TOKEN }}
default_bump: ${{ inputs.version }}

# Generate the release with goreleaser to include pre-built binaries
goreleaser:
needs: version_bump
runs-on: ubuntu-latest
if: |
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'push' && contains(github.ref, 'refs/tags/'))
permissions: "write-all"
steps:
- uses: actions/checkout@v3
- run: git fetch --force --tags
- uses: actions/setup-go@v4
with:
go-version: 1.21
# Generate the binaries and release
- uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# TODO: permission issue, but not worth fixing as this should be refactored
# into the celestiaorg/.github repo, at which point any permission issues will
Expand Down
55 changes: 55 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
before:
hooks:
- go mod tidy
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
archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of
# uname.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
checksum:
name_template: "checksums.txt"
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
9 changes: 9 additions & 0 deletions .yamllint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
# Built from docs https://yamllint.readthedocs.io/en/stable/configuration.html
extends: default

rules:
# 120 chars should be enough, but don't fail if a line is longer
line-length:
max: 120
level: warning
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,20 @@ telemetry-infra-up:
telemetry-infra-down:
PWD="${DIR_FULLPATH}/docker/telemetry" docker-compose -f ./docker/telemetry/docker-compose.yml down
.PHONY: telemetry-infra-down

## goreleaser: List Goreleaser commands and checks if GoReleaser is installed.
goreleaser: Makefile
@echo " Choose a goreleaser command to run:"
@sed -n 's/^## goreleaser/goreleaser/p' $< | column -t -s ':' | sed -e 's/^/ /'
@goreleaser --version
.PHONY: goreleaser

## goreleaser-build: Builds the celestia binary using GoReleaser for your local OS.
goreleaser-build:
goreleaser build --snapshot --clean --single-target
.PHONY: goreleaser-build

## 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.
goreleaser-release:
goreleaser release --clean --fail-fast --skip-publish
.PHONY: goreleaser-release

0 comments on commit 25ac002

Please sign in to comment.