Skip to content

Commit 3fef7b2

Browse files
authored
Goreleaser (dennis-tra#62)
* move prefix generation code into ./cmd folder Should avoid confusion as came up in dennis-tra#60 * fix: goreleaser configuration dennis-tra#60 related * refactor: goreleaser configuration
1 parent 7d840d9 commit 3fef7b2

File tree

9 files changed

+108
-24
lines changed

9 files changed

+108
-24
lines changed

.github/workflows/goreleaser.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: goreleaser
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
goreleaser:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checking out repository
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Setting up Go
21+
uses: actions/setup-go@v4
22+
23+
- name: Running GoReleaser
24+
uses: goreleaser/goreleaser-action@v5
25+
with:
26+
distribution: goreleaser
27+
version: latest
28+
args: release --clean
29+
env:
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.goreleaser.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,22 @@
88

99
version: 1
1010

11+
project_name: nebula
12+
1113
builds:
12-
- env:
13-
- CGO_ENABLED=0
14+
- id: nebula
15+
main: ./cmd/nebula
16+
binary: nebula
17+
env:
18+
- CGO_ENABLED=1
1419
goos:
1520
- linux
1621
- windows
1722
- darwin
1823

24+
release:
25+
draft: true
26+
1927
archives:
2028
- format: tar.gz
2129
# this name template makes the OS and Arch compatible with the results of `uname`.

Makefile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
default: all
1+
GIT_SHA := $(shell git rev-parse --short HEAD)
2+
DATE := $(shell date "+%Y-%m-%dT%H:%M:%SZ")
3+
USER := $(shell id -un)
4+
VERSION := $(shell git describe --tags --abbrev=0)
25

36
all: clean build
47

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

1013
build:
11-
go build -ldflags "-X main.RawVersion=`cat version`" -o dist/nebula github.com/dennis-tra/nebula-crawler/cmd/nebula
12-
13-
build-linux:
14-
GOOS=linux GOARCH=amd64 make build
14+
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
1515

1616
format:
1717
gofumpt -w -l .
@@ -20,13 +20,13 @@ clean:
2020
rm -r dist || true
2121

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

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

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

3131
tools:
3232
go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/[email protected]

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,14 @@ make database
372372
make test
373373
```
374374

375+
## Release Checklist
376+
377+
- [ ] Merge everything into `main`
378+
- [ ] Create a new tag with the new version
379+
- [ ] Push tag to GitHub
380+
381+
This will trigger the [`goreleaser.yml`](./.github/workflows/goreleaser.yml) workflow which pushes creates a new _draft_ release in GitHub.
382+
375383
## Related Efforts
376384

377385
- [`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)).

cmd/nebula/cmd.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@ const (
2424
flagCategoryNetwork = "Network Specific Configuration:"
2525
)
2626

27-
// RawVersion and build tag of the Nebula command line tool.
28-
var RawVersion = "dev"
27+
var (
28+
version = "dev"
29+
commit = "none"
30+
date = "unknown"
31+
builtBy = "local"
32+
)
2933

3034
var rootConfig = &config.Root{
31-
RawVersion: RawVersion,
3235
Debug: false,
3336
LogLevel: 4,
3437
LogFormat: "text",
@@ -52,6 +55,10 @@ var rootConfig = &config.Root{
5255
ProtocolsCacheSize: 100,
5356
ProtocolsSetCacheSize: 200,
5457
},
58+
RawVersion: version,
59+
BuildCommit: commit,
60+
BuildDate: date,
61+
BuiltBy: builtBy,
5562
}
5663

5764
func main() {
@@ -65,7 +72,7 @@ func main() {
6572
6673
},
6774
},
68-
Version: rootConfig.Version(),
75+
Version: fmt.Sprintf("v%s (%s)", rootConfig.Version(), rootConfig.BuildAuthor()),
6976
Before: Before,
7077
Flags: []cli.Flag{
7178
&cli.BoolFlag{

gen.go renamed to cmd/prefix/gen.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
"github.com/ethereum/go-ethereum/crypto"
99
)
1010

11-
//go:generate mockgen -source=libp2p/driver_crawler.go -destination=libp2p/mock_host_test.go -package=libp2p
12-
1311
func main() {
1412
// How many bits do we want to break?
1513
bits := 16

config/config.go

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"runtime/debug"
77
"strconv"
8+
"strings"
89
"time"
910

1011
"github.com/ethereum/go-ethereum/p2p/enode"
@@ -68,9 +69,6 @@ const (
6869

6970
// Root contains general user configuration.
7071
type Root struct {
71-
// The version string of nebula
72-
RawVersion string
73-
7472
// Enables debug logging (equivalent to log level 5)
7573
Debug bool
7674

@@ -109,6 +107,18 @@ type Root struct {
109107

110108
// TracerProvider is the tracer provider to use when initialising tracing
111109
TracerProvider trace.TracerProvider
110+
111+
// 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)
112+
RawVersion string
113+
114+
// The commit hash used to build the Nebula binary (set by GoReleaser or in Makefile)
115+
BuildCommit string
116+
117+
// The date when Nebula was built (set by GoReleaser or in Makefile)
118+
BuildDate string
119+
120+
// Who built Nebula (set by GoReleaser or in Makefile)
121+
BuiltBy string
112122
}
113123

114124
// Version returns the actual version string which includes VCS information
@@ -119,17 +129,27 @@ func (r *Root) Version() string {
119129
for _, setting := range info.Settings {
120130
switch setting.Key {
121131
case "vcs.revision":
122-
shortCommit = setting.Value[:7]
132+
shortCommit = setting.Value
133+
if len(shortCommit) > 8 {
134+
shortCommit = shortCommit[:8]
135+
}
123136
case "vcs.modified":
124137
dirty, _ = strconv.ParseBool(setting.Value)
125138
}
126139
}
127140
}
128141

129-
versionStr := "v" + r.RawVersion
142+
versionStr := r.RawVersion
130143

131-
if shortCommit != "" {
132-
versionStr += "+" + shortCommit
144+
if r.BuildCommit != "" {
145+
if len(r.BuildCommit) > 8 {
146+
r.BuildCommit = r.BuildCommit[:8]
147+
}
148+
shortCommit = r.BuildCommit
149+
}
150+
151+
if !strings.HasSuffix(versionStr, shortCommit) {
152+
versionStr += "-" + shortCommit
133153
}
134154

135155
if dirty {
@@ -139,6 +159,17 @@ func (r *Root) Version() string {
139159
return versionStr
140160
}
141161

162+
func (r *Root) BuildAuthor() string {
163+
if r.BuildDate != "" && r.BuiltBy != "" {
164+
return fmt.Sprintf("built at %s by %s", r.BuildDate, r.BuiltBy)
165+
} else if r.BuildDate != "" {
166+
return fmt.Sprintf("built at %s", r.BuildDate)
167+
} else if r.BuiltBy != "" {
168+
return fmt.Sprintf("built by %s", r.BuiltBy)
169+
}
170+
return ""
171+
}
172+
142173
// String prints the configuration as a json string
143174
func (r *Root) String() string {
144175
data, _ := json.MarshalIndent(r, "", " ")

mockgen.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package nebula
2+
3+
//go:generate mockgen -source=libp2p/driver_crawler.go -destination=libp2p/mock_host_test.go -package=libp2p

version

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)