Skip to content

Commit

Permalink
refactor: goreleaser configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
dennis-tra committed May 4, 2024
1 parent b698223 commit fcc8e27
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 20 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: goreleaser

on:
push:
tags:
- '*'

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checking out repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setting up Go
uses: actions/setup-go@v4

- name: Running GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
default: all
GIT_SHA := $(shell git rev-parse --short HEAD)
DATE := $(shell date "+%Y-%m-%dT%H:%M:%SZ")
USER := $(shell id -un)
VERSION := $(shell git describe --tags --abbrev=0)

all: clean build

Expand All @@ -8,10 +11,7 @@ test:
go test `go list ./... | grep -v maxmind | grep -v discvx`

build:
go build -ldflags "-X main.RawVersion=`cat version`" -o dist/nebula github.com/dennis-tra/nebula-crawler/cmd/nebula

build-linux:
GOOS=linux GOARCH=amd64 make build
go build -ldflags "-X main.version=${VERSION} -X main.commit=${GIT_SHA} -X main.date=${DATE} -X main.builtBy=${USER}" -o dist/nebula github.com/dennis-tra/nebula-crawler/cmd/nebula

format:
gofumpt -w -l .
Expand All @@ -20,13 +20,13 @@ clean:
rm -r dist || true

docker:
docker build -t dennistra/nebula:latest -t dennistra/nebula:`cat version` .
docker build -t dennistra/nebula:latest -t dennistra/nebula:${GIT_SHA} .

docker-linux:
docker build --platform linux/amd64 -t 019120760881.dkr.ecr.us-east-1.amazonaws.com/probelab:nebula-sha6bc3e96 .
docker build --platform linux/amd64 -t 019120760881.dkr.ecr.us-east-1.amazonaws.com/probelab:nebula-sha${GIT_SHA} .

docker-push: docker-linux
docker push dennistra/nebula:latest dennistra/nebula:`cat version`
docker push dennistra/nebula:latest dennistra/nebula:${GIT_SHA}

tools:
go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/[email protected]
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,14 @@ make database
make test
```

## Release Checklist

- [ ] Merge everything into `main`
- [ ] Create a new tag with the new version
- [ ] Push tag to GitHub

This will trigger the [`goreleaser.yml`](./.github/workflows/goreleaser.yml) workflow which pushes creates a new _draft_ release in GitHub.

## Related Efforts

- [`wiberlin/ipfs-crawler`](https://github.com/wiberlin/ipfs-crawler) - A crawler for the IPFS network, code for their paper ([arXiv](https://arxiv.org/abs/2002.07747)).
Expand Down
15 changes: 11 additions & 4 deletions cmd/nebula/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ const (
flagCategoryNetwork = "Network Specific Configuration:"
)

// RawVersion and build tag of the Nebula command line tool.
var RawVersion = "dev"
var (
version = "dev"
commit = "none"
date = "unknown"
builtBy = "local"
)

var rootConfig = &config.Root{
RawVersion: RawVersion,
Debug: false,
LogLevel: 4,
LogFormat: "text",
Expand All @@ -52,6 +55,10 @@ var rootConfig = &config.Root{
ProtocolsCacheSize: 100,
ProtocolsSetCacheSize: 200,
},
RawVersion: version,
BuildCommit: commit,
BuildDate: date,
BuiltBy: builtBy,
}

func main() {
Expand All @@ -65,7 +72,7 @@ func main() {
Email: "[email protected]",
},
},
Version: rootConfig.Version(),
Version: fmt.Sprintf("v%s (%s)", rootConfig.Version(), rootConfig.BuildAuthor()),
Before: Before,
Flags: []cli.Flag{
&cli.BoolFlag{
Expand Down
45 changes: 38 additions & 7 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"runtime/debug"
"strconv"
"strings"
"time"

"github.com/ethereum/go-ethereum/p2p/enode"
Expand Down Expand Up @@ -68,9 +69,6 @@ const (

// Root contains general user configuration.
type Root struct {
// The version string of nebula
RawVersion string

// Enables debug logging (equivalent to log level 5)
Debug bool

Expand Down Expand Up @@ -109,6 +107,18 @@ type Root struct {

// TracerProvider is the tracer provider to use when initialising tracing
TracerProvider trace.TracerProvider

// The raw version of Nebula in the for X.Y.Z. Raw, because it's missing, e.g., commit information (set by GoReleaser or in Makefile)
RawVersion string

// The commit hash used to build the Nebula binary (set by GoReleaser or in Makefile)
BuildCommit string

// The date when Nebula was built (set by GoReleaser or in Makefile)
BuildDate string

// Who built Nebula (set by GoReleaser or in Makefile)
BuiltBy string
}

// Version returns the actual version string which includes VCS information
Expand All @@ -119,17 +129,27 @@ func (r *Root) Version() string {
for _, setting := range info.Settings {
switch setting.Key {
case "vcs.revision":
shortCommit = setting.Value[:7]
shortCommit = setting.Value
if len(shortCommit) > 8 {
shortCommit = shortCommit[:8]
}
case "vcs.modified":
dirty, _ = strconv.ParseBool(setting.Value)
}
}
}

versionStr := "v" + r.RawVersion
versionStr := r.RawVersion

if shortCommit != "" {
versionStr += "+" + shortCommit
if r.BuildCommit != "" {
if len(r.BuildCommit) > 8 {
r.BuildCommit = r.BuildCommit[:8]
}
shortCommit = r.BuildCommit
}

if !strings.HasSuffix(versionStr, shortCommit) {
versionStr += "-" + shortCommit
}

if dirty {
Expand All @@ -139,6 +159,17 @@ func (r *Root) Version() string {
return versionStr
}

func (r *Root) BuildAuthor() string {
if r.BuildDate != "" && r.BuiltBy != "" {
return fmt.Sprintf("built at %s by %s", r.BuildDate, r.BuiltBy)
} else if r.BuildDate != "" {
return fmt.Sprintf("built at %s", r.BuildDate)
} else if r.BuiltBy != "" {
return fmt.Sprintf("built by %s", r.BuiltBy)
}
return ""
}

// String prints the configuration as a json string
func (r *Root) String() string {
data, _ := json.MarshalIndent(r, "", " ")
Expand Down
1 change: 0 additions & 1 deletion version

This file was deleted.

0 comments on commit fcc8e27

Please sign in to comment.