Skip to content

Commit e15d182

Browse files
authored
chore: Add version (#137)
- add version and tidy up the Makefile - update the goreleaser to remove the deprecated stuff - update the docker file so it actually works
1 parent f623a5f commit e15d182

File tree

10 files changed

+27
-56
lines changed

10 files changed

+27
-56
lines changed

.golangci.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
run:
22
timeout: 3m
3-
go: 1.20
3+
go: 1.23.4
44
modules-download-mode: vendor
55

66
linters:
@@ -26,8 +26,6 @@ linters:
2626
- unused
2727
- unconvert
2828
- unparam
29-
- vet
30-
- vetshadow
3129
- wastedassign
3230

3331
linters-settings:

.goreleaser.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ builds:
99
main: ./cmd/squealer
1010
binary: squealer
1111
ldflags:
12-
- "-X github.com/owenrumney/squealer/version.Version={{.Version}} -s -w -extldflags '-fno-PIC -static'"
12+
- "-X github.com/owenrumney/squealer/pkg/version.Version={{.Version}} -s -w -extldflags '-fno-PIC -static'"
1313
env:
1414
- CGO_ENABLED=0
1515
- GOFLAGS=-mod=vendor
@@ -27,7 +27,7 @@ checksum:
2727
name_template: '{{ .ProjectName }}_checksums.txt'
2828

2929
snapshot:
30-
name_template: "{{ .Tag }}-next"
30+
version_template: "{{ .Tag }}-next"
3131

3232
changelog:
3333
sort: asc
@@ -38,7 +38,7 @@ changelog:
3838

3939
archives:
4040
-
41-
format: binary
41+
formats: [ binary ]
4242
name_template: "{{ .Binary}}.{{ .Os }}.{{ .Arch }}"
4343

4444
release:

Dockerfile

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
FROM alpine:3.21.2
22

3-
# use a non-privileged user
4-
USER nobody
3+
# Set the working directory
4+
WORKDIR /usr/bin
55

6-
# work somewhere where we can write
6+
# Copy the binary to the working directory
77
COPY squealer /usr/bin/squealer
88

9-
# set the default entrypoint -- when this container is run, use this command
10-
ENTRYPOINT [ "squealer" ]
11-
12-
# as we specified an entrypoint, this is appended as an argument (i.e., `sqealer --help`)
13-
CMD [ "--help" ]
14-
15-
9+
# Set the default entrypoint
10+
ENTRYPOINT [ "squealer" ]

Makefile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@ build: test
1010
test:
1111
go test -v -covermode=atomic -coverpkg ./... -coverprofile coverage.txt ./...
1212

13-
.PHONY: push-image
14-
push-image:
15-
./scripts/publish-image.sh
1613

1714
.PHONY: image
1815
image:
19-
docker build --build-arg squealer_version=$(TRAVIS_TAG) -t $(IMAGE) .
16+
docker build --build-arg squealer_version=development -t $(IMAGE) .
2017

2118
.PHONY: lint
2219
quality:

internal/app/squealer/cmd/flags.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var (
1313
toHash string
1414
commitListFile string
1515
format string
16+
showVersion bool
1617
)
1718

1819
func configureFlags(command *cobra.Command) {
@@ -21,6 +22,7 @@ func configureFlags(command *cobra.Command) {
2122
command.PersistentFlags().BoolVar(&noGit, "no-git", noGit, "Scan as a directory rather than a git history.")
2223
command.PersistentFlags().BoolVar(&debug, "debug", debug, "Include debug output.")
2324
command.PersistentFlags().BoolVar(&everything, "everything", everything, "Scan all commits.... everywhere.")
25+
command.PersistentFlags().BoolVar(&showVersion, "version", showVersion, "Show the version of the application.")
2426
command.PersistentFlags().StringVar(&configFilePath, "config-file", configFilePath, "Path to the config file with the rules.")
2527
command.PersistentFlags().StringVar(&fromHash, "from-hash", fromHash, "The hash to work back to from the starting hash.")
2628
command.PersistentFlags().StringVar(&toHash, "to-hash", toHash, "The most recent hash to start with.")

internal/app/squealer/cmd/root.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package cmd
22

33
import (
44
"fmt"
5+
56
"math"
67
"os"
78

89
"github.com/owenrumney/squealer/pkg/squealer"
10+
"github.com/owenrumney/squealer/pkg/version"
911

1012
log "github.com/sirupsen/logrus"
1113
"github.com/spf13/cobra"
@@ -26,9 +28,16 @@ func Root() *cobra.Command {
2628
Use: "squealer",
2729
Short: "Search for secrets and squeal about them",
2830
Long: `Telling tales on your secret leaking`,
29-
RunE: squeal,
31+
PreRun: func(cmd *cobra.Command, args []string) {
32+
if showVersion {
33+
fmt.Println(version.Version)
34+
os.Exit(0)
35+
}
36+
},
37+
RunE: squeal,
3038
}
3139
configureFlags(rootCommand)
40+
3241
return rootCommand
3342
}
3443

internal/pkg/scan/scanner.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ type Scanner interface {
4040

4141
func NewScanner(sc *ScannerConfig) (Scanner, error) {
4242
if sc.NoGit || notGit(sc.Basepath) {
43-
log.Infof("Using a directory scanner to process %s\n", sc.Basepath)
43+
log.Infof("Using a directory scanner to process %s", sc.Basepath)
4444
return newDirectoryScanner(sc)
4545
}
46-
log.Infof("Using a git scanner to process %s\n", sc.Basepath)
46+
log.Infof("Using a git scanner to process %s", sc.Basepath)
4747
return newGitScanner(sc)
4848
}
4949

pkg/version/version.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package version
2+
3+
var Version = "dev"

scripts/build.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

scripts/publish-image.sh

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)