Skip to content

Commit ad4a1aa

Browse files
committed
chore: fully functional converter with spdx 2
Signed-off-by: Keith Zantow <[email protected]>
1 parent 0cabf70 commit ad4a1aa

11 files changed

+367
-739
lines changed

Makefile

+12-76
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,17 @@
1-
TEMPDIR = ./.tmp
2-
3-
# commands and versions
4-
LINTCMD = $(TEMPDIR)/golangci-lint run --tests=false --timeout=5m --config .golangci.yaml
5-
GOIMPORTS_CMD = $(TEMPDIR)/gosimports -local github.com/anchore
6-
7-
# tool versions
8-
GOLANGCILINT_VERSION = v1.50.1
9-
GOSIMPORTS_VERSION = v0.3.4
10-
BOUNCER_VERSION = v0.4.0
11-
12-
# formatting variables
13-
BOLD := $(shell tput -T linux bold)
14-
PURPLE := $(shell tput -T linux setaf 5)
15-
GREEN := $(shell tput -T linux setaf 2)
16-
CYAN := $(shell tput -T linux setaf 6)
17-
RED := $(shell tput -T linux setaf 1)
18-
RESET := $(shell tput -T linux sgr0)
19-
TITLE := $(BOLD)$(PURPLE)
20-
SUCCESS := $(BOLD)$(GREEN)
21-
22-
# test variables
23-
RESULTSDIR = test/results
24-
COVER_REPORT = $(RESULTSDIR)/unit-coverage-details.txt
25-
COVER_TOTAL = $(RESULTSDIR)/unit-coverage-summary.txt
26-
# the quality gate lower threshold for unit test total % coverage (by function statements)
27-
COVERAGE_THRESHOLD := 80
28-
29-
$(RESULTSDIR):
30-
mkdir -p $(RESULTSDIR)
31-
32-
$(TEMPDIR):
33-
mkdir -p $(TEMPDIR)
34-
35-
.PHONY: bootstrap-tools
36-
bootstrap-tools: $(TEMPDIR)
37-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(TEMPDIR)/ $(GOLANGCILINT_VERSION)
38-
curl -sSfL https://raw.githubusercontent.com/wagoodman/go-bouncer/master/bouncer.sh | sh -s -- -b $(TEMPDIR)/ $(BOUNCER_VERSION)
39-
# the only difference between goimports and gosimports is that gosimports removes extra whitespace between import blocks (see https://github.com/golang/go/issues/20818)
40-
GOBIN="$(realpath $(TEMPDIR))" go install github.com/rinchsan/gosimports/cmd/gosimports@$(GOSIMPORTS_VERSION)
41-
42-
.PHONY: static-analysis
43-
static-analysis: check-licenses lint
44-
45-
.PHONY: lint
46-
lint: ## Run gofmt + golangci lint checks
47-
$(call title,Running linters)
48-
# ensure there are no go fmt differences
49-
@printf "files with gofmt issues: [$(shell gofmt -l -s .)]\n"
50-
@test -z "$(shell gofmt -l -s .)"
51-
52-
# run all golangci-lint rules
53-
$(LINTCMD)
54-
@[ -z "$(shell $(GOIMPORTS_CMD) -d .)" ] || (echo "goimports needs to be fixed" && false)
1+
.PHONY: test
2+
test: unit
553

56-
# go tooling does not play well with certain filename characters, ensure the common cases don't result in future "go get" failures
57-
$(eval MALFORMED_FILENAMES := $(shell find . | grep -e ':'))
58-
@bash -c "[[ '$(MALFORMED_FILENAMES)' == '' ]] || (printf '\nfound unsupported filename characters:\n$(MALFORMED_FILENAMES)\n\n' && false)"
4+
.PHONY: bootstrap
5+
bootstrap:
6+
go install github.com/rinchsan/gosimports/cmd/[email protected]
597

60-
.PHONY: lint-fix
61-
lint-fix: ## Auto-format all source code + run golangci lint fixers
62-
$(call title,Running lint fixers)
63-
gofmt -w -s .
64-
$(GOIMPORTS_CMD) -w .
65-
$(LINTCMD) --fix
8+
.PHONY: format
9+
format:
10+
gofmt -w .
6611
go mod tidy
67-
68-
.PHONY: check-licenses
69-
check-licenses: ## Ensure transitive dependencies are compliant with the current license policy
70-
$(TEMPDIR)/bouncer check ./...
12+
gosimports -w -local github.com/anchore .
7113

7214
.PHONY: unit
73-
unit: $(RESULTSDIR) ## Run unit tests (with coverage)
74-
$(call title,Running unit tests)
75-
go test -coverprofile $(COVER_REPORT) $(shell go list ./... | grep -v anchore/syft/test)
76-
@go tool cover -func $(COVER_REPORT) | grep total | awk '{print substr($$3, 1, length($$3)-1)}' > $(COVER_TOTAL)
77-
@echo "Coverage: $$(cat $(COVER_TOTAL))"
78-
@if [ $$(echo "$$(cat $(COVER_TOTAL)) >= $(COVERAGE_THRESHOLD)" | bc -l) -ne 1 ]; then echo "$(RED)$(BOLD)Failed coverage quality gate (> $(COVERAGE_THRESHOLD)%)$(RESET)" && false; fi
79-
80-
.PHONY: test
81-
test: unit
15+
unit:
16+
go test -v -covermode=count -coverprofile=profile.cov.tmp ./...
17+
cat profile.cov.tmp | grep -v /model.go > profile.cov # ignore generated model file

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type V2 struct {
5454
NewField string // this was a renamed field
5555
}
5656

57-
func (to *V2) ConvertFrom(from interface{}) error {
57+
func (to *V2) ConvertFrom(from any) error {
5858
if from, ok := from.(V1); ok { // forward migration
5959
to.NewField = from.OldField
6060
}
@@ -68,7 +68,7 @@ type V3 struct {
6868
FinalField []string // this field was renamed and the type was changed
6969
}
7070

71-
func (to *V3) ConvertFrom(from interface{}) error {
71+
func (to *V3) ConvertFrom(from any) error {
7272
if from, ok := from.(V2); ok { // forward migration
7373
to.FinalField = []string{from.NewField}
7474
}
@@ -117,7 +117,7 @@ type V1 struct {
117117
OldField string
118118
}
119119

120-
func (to *V1) ConvertFrom(from interface{}) error {
120+
func (to *V1) ConvertFrom(from any) error {
121121
if from, ok := from.(V2); ok { // backward migration
122122
to.OldField = from.NewField
123123
}
@@ -131,7 +131,7 @@ type V2 struct {
131131
NewField string
132132
}
133133

134-
func (to *V2) ConvertFrom(from interface{}) error {
134+
func (to *V2) ConvertFrom(from any) error {
135135
if from, ok := from.(V1); ok { // forward migration
136136
to.NewField = from.OldField
137137
}
@@ -148,7 +148,7 @@ type V3 struct {
148148
FinalField []string
149149
}
150150

151-
func (to *V3) ConvertFrom(from interface{}) error {
151+
func (to *V3) ConvertFrom(from any) error {
152152
if from, ok := from.(V2); ok { // forward migration
153153
to.FinalField = []string{from.NewField}
154154
}

chain.go

-95
This file was deleted.

0 commit comments

Comments
 (0)