Skip to content

Commit 29534c4

Browse files
authored
Integrate goreleaser (#62)
1 parent b428a0b commit 29534c4

File tree

6 files changed

+88
-9
lines changed

6 files changed

+88
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
sx
2+
dist/

.goreleaser.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
gomod:
2+
proxy: true
3+
builds:
4+
- env:
5+
- CGO_ENABLED=1
6+
goos:
7+
- linux
8+
goarch:
9+
- amd64
10+
flags:
11+
- -trimpath
12+
ldflags:
13+
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}}
14+
mod_timestamp: '{{ .CommitTimestamp }}'
15+
hooks:
16+
post: upx {{.Path}}
17+
archives:
18+
- files:
19+
- none*
20+
checksum:
21+
algorithm: sha256
22+
changelog:
23+
sort: asc
24+
filters:
25+
exclude:
26+
- '^docs:'
27+
- '^test:'

command/root.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ import (
2525
)
2626

2727
var rootCmd = &cobra.Command{
28-
Use: "sx",
29-
Short: "Fast, modern, easy-to-use network scanner",
30-
Version: "0.1.0",
28+
Use: "sx",
29+
Short: "Fast, modern, easy-to-use network scanner",
3130
// Parse common flags
3231
PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) {
3332
if len(cliInterfaceFlag) > 0 {
@@ -187,7 +186,8 @@ func validatePacketScanStdin() (err error) {
187186
return
188187
}
189188

190-
func Main() {
189+
func Main(version string) {
190+
rootCmd.Version = version
191191
if err := rootCmd.Execute(); err != nil {
192192
os.Exit(1)
193193
}

go.sum

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
8080
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
8181
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
8282
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
83-
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
8483
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
8584
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
8685
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
@@ -172,7 +171,6 @@ github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zM
172171
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
173172
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
174173
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
175-
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
176174
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
177175
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
178176
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -247,7 +245,6 @@ golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnf
247245
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
248246
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
249247
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
250-
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8=
251248
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
252249
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
253250
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=

main.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
package main
22

3-
import "github.com/v-byte-cpu/sx/command"
3+
import (
4+
"fmt"
5+
6+
"github.com/v-byte-cpu/sx/command"
7+
)
8+
9+
// will be injected during release
10+
var (
11+
version = "dev"
12+
commit = ""
13+
)
414

515
func main() {
6-
command.Main()
16+
command.Main(buildVersion(version, commit))
17+
}
18+
19+
func buildVersion(version, commit string) string {
20+
result := version
21+
if commit != "" {
22+
result = fmt.Sprintf("%s\ncommit: %s", result, commit)
23+
}
24+
return result
725
}

main_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
)
8+
9+
func TestBuildVersion(t *testing.T) {
10+
t.Parallel()
11+
12+
tests := []struct {
13+
name string
14+
version string
15+
commit string
16+
expected string
17+
}{
18+
{
19+
name: "VersionOnly",
20+
version: "0.1.0",
21+
expected: "0.1.0",
22+
},
23+
{
24+
name: "VersionAndCommit",
25+
version: "0.1.0",
26+
commit: "1234567",
27+
expected: "0.1.0\ncommit: 1234567",
28+
},
29+
}
30+
for _, tt := range tests {
31+
t.Run(tt.name, func(t *testing.T) {
32+
result := buildVersion(tt.version, tt.commit)
33+
require.Equal(t, tt.expected, result)
34+
})
35+
}
36+
}

0 commit comments

Comments
 (0)