Skip to content

Commit

Permalink
Merge pull request #12 from gruz0/feature/add-goreleaser
Browse files Browse the repository at this point in the history
Add goreleaser
  • Loading branch information
gruz0 authored May 19, 2024
2 parents 1be6f57 + 9c60c26 commit bf83e3c
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: "Release a tag"
on:
push:
tags:
- v*

jobs:
release:
runs-on: ubuntu-latest
env:
GO_VERSION: '1.22'
steps:
- uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Unshallow
run: git fetch --prune --unshallow

- name: Create release
uses: goreleaser/goreleaser-action@v5
with:
version: latest
args: release --clean --timeout=90m
env:
GITHUB_TOKEN: ${{ secrets.WEB3SAFE_GORELEASER_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
bin/

dist/
58 changes: 58 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
project_name: web3safe

version: 1

builds:
- binary: web3safe
main: ./cmd/web3safe
flags:
- -trimpath
ldflags: -s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}}
env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
ignore:
- goos: darwin
goarch: 386

archives:
- format: tar.gz
wrap_in_directory: true
format_overrides:
- goos: windows
format: zip
name_template: '{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
files:
- README.md

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

checksum:
name_template: '{{ .ProjectName }}-{{ .Version }}-checksums.txt'

changelog:
sort: asc
filters:
exclude:
- '(?i)^docs?:'
- '(?i)^docs\([^:]+\):'
- '(?i)^docs\[[^:]+\]:'
- '^tests?:'
- '(?i)^dev:'
- '(?i)^chore:'
- Merge pull request
- Merge branch

release:
github:
owner: gruz0
name: web3safe

source:
enabled: true
name_template: '{{ .ProjectName }}-{{ .Version }}-source'
56 changes: 56 additions & 0 deletions cmd/web3safe/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,27 @@ import (
"errors"
"fmt"
"os"
"runtime/debug"

"github.com/gruz0/web3safe/internal/app"
"github.com/gruz0/web3safe/internal/utils"
)

var (
goVersion = "unknown" //nolint:gochecknoglobals

// Populated by goreleaser during build.
version = "unknown"
commit = "?" //nolint:gochecknoglobals
date = "" //nolint:gochecknoglobals
)

func main() {
if len(os.Args) == 1 {
printVersion()
os.Exit(utils.ExitSuccess)
}

success, err := app.Run(os.Args)
if err != nil {
var appError *app.Error
Expand All @@ -29,3 +44,44 @@ func main() {

os.Exit(utils.ExitError)
}

func printVersion() {
buildInfo, available := debug.ReadBuildInfo()
if !available {
return
}

var revision string

for _, setting := range buildInfo.Settings {
// The `vcs.xxx` information is only available with `go build`.
// This information is not available with `go install` or `go run`.
switch setting.Key {
case "vcs.time":
date = setting.Value
case "vcs.revision":
revision = setting.Value
}
}

if revision == "" {
revision = "unknown"
}

if date == "" {
date = "(unknown)"
}

goVersion = buildInfo.GoVersion
version = buildInfo.Main.Version
commit = revision

fmt.Fprintf(
os.Stdout,
"web3safe has version %s built with %s from %s on %s\n",
version,
goVersion,
commit,
date,
)
}

0 comments on commit bf83e3c

Please sign in to comment.