Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: port to clio #89

Merged
merged 10 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
405 changes: 0 additions & 405 deletions .github/scripts/goreleaser-install.sh

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- "v*"

env:
GO_VERSION: "1.17.x"
GO_VERSION: "1.18.x"

jobs:
quality-gate:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- main

env:
GO_VERSION: "1.17.x"
GO_VERSION: "1.18.x"

jobs:

Expand Down
10 changes: 5 additions & 5 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ linters:
disable-all: true
enable:
- asciicheck
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
Expand All @@ -38,18 +36,16 @@ linters:
- nakedret
- nolintlint
- revive
- rowserrcheck
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace

# do not enable...
# - bodyclose # 1.18 compat
# - gochecknoglobals
# - gochecknoinits # this is too aggressive
# - godot
Expand All @@ -62,6 +58,10 @@ linters:
# - maligned # this is an excellent linter, but tricky to optimize and we are not sensitive to memory layout optimizations
# - nestif
# - prealloc # following this rule isn't consistently a good idea, as it sometimes forces unnecessary allocations that result in less idiomatic code
# - rowserrcheck # 1.18 compat
# - scopelint # deprecated
# - testpackage
# - wsl # this doens't have an auto-fixer yet and is pretty noisy (https://github.com/bombsimon/wsl/issues/90)
# - varcheck # deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter. Replaced by unused.
# - deadcode # deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter. Replaced by unused.
# - structcheck # deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter. Replaced by unused.
13 changes: 7 additions & 6 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ release:
draft: true

builds:
- binary: chronicle
id: chronicle
- id: chronicle
binary: chronicle
dir: ./cmd/chronicle
env:
- CGO_ENABLED=0
goos:
Expand All @@ -24,10 +25,10 @@ builds:
-w
-s
-extldflags '-static'
-X github.com/anchore/chronicle/internal/version.version={{.Version}}
-X github.com/anchore/chronicle/internal/version.gitCommit={{.Commit}}
-X github.com/anchore/chronicle/internal/version.buildDate={{.Date}}
-X github.com/anchore/chronicle/internal/version.gitTreeState={{.Env.BUILD_GIT_TREE_STATE}}
-X main.version={{.Version}}
-X main.gitCommit={{.Commit}}
-X main.buildDate={{.Date}}
-X main.gitDescription={{.Summary}}

nfpms:
-
Expand Down
121 changes: 67 additions & 54 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
BIN = chronicle
TEMP_DIR = ./.tmp
RESULTS_DIR = test/results
COVER_REPORT = $(RESULTS_DIR)/unit-coverage-details.txt
COVER_TOTAL = $(RESULTS_DIR)/unit-coverage-summary.txt

# Command templates #################################
LINT_CMD = $(TEMP_DIR)/golangci-lint run --tests=false --timeout=2m --config .golangci.yaml
GOIMPORTS_CMD = $(TEMP_DIR)/gosimports -local github.com/anchore
RELEASE_CMD = $(TEMP_DIR)/goreleaser release --rm-dist
SNAPSHOT_CMD = $(RELEASE_CMD) --skip-publish --snapshot --skip-sign
CHRONICLE_CMD = $(TEMP_DIR)/chronicle

# Tool versions #################################
GOLANG_CI_VERSION = v1.52.2
GOBOUNCER_VERSION = v0.4.0
GORELEASER_VERSION = v1.17.0
GOSIMPORTS_VERSION = v0.3.8
CHRONICLE_VERSION = latest

# Formatting variables #################################
BOLD := $(shell tput -T linux bold)
PURPLE := $(shell tput -T linux setaf 5)
GREEN := $(shell tput -T linux setaf 2)
Expand All @@ -7,28 +28,22 @@ RESET := $(shell tput -T linux sgr0)
TITLE := $(BOLD)$(PURPLE)
SUCCESS := $(BOLD)$(GREEN)

BIN = chronicle
TEMPDIR = ./.tmp
RESULTSDIR = test/results
COVER_REPORT = $(RESULTSDIR)/unit-coverage-details.txt
COVER_TOTAL = $(RESULTSDIR)/unit-coverage-summary.txt
LINT_CMD = $(TEMPDIR)/golangci-lint run --tests=false --timeout=2m --config .golangci.yaml
GOIMPORTS_CMD = $(TEMPDIR)/gosimports -local github.com/anchore
# Test variables #################################
# the quality gate lower threshold for unit test total % coverage (by function statements)
COVERAGE_THRESHOLD := 50
# CI cache busting values; change these if you want CI to not use previous stored cache
FIXTURE_CACHE_BUSTER = "88738d2f"

## Build variables
DISTDIR=./dist
SNAPSHOTDIR=./snapshot
GITTREESTATE=$(if $(shell git status --porcelain),dirty,clean)
OS := $(shell uname)
DIST_DIR=./dist
SNAPSHOT_DIR=./snapshot
OS=$(shell uname | tr '[:upper:]' '[:lower:]')
CHANGELOG := CHANGELOG.md

ifeq ($(OS),Darwin)
SNAPSHOT_CMD=$(shell realpath $(shell pwd)/$(SNAPSHOTDIR)/$(BIN)-macos_darwin_amd64/$(BIN))
SNAPSHOT_CMD=$(realpath $(shell pwd)/$(SNAPSHOT_DIR)/$(BIN)-macos_darwin_amd64/$(BIN))
else
SNAPSHOT_CMD=$(shell realpath $(shell pwd)/$(SNAPSHOTDIR)/$(BIN)_linux_amd64/$(BIN))
SNAPSHOT_CMD=$(realpath $(shell pwd)/$(SNAPSHOT_DIR)/$(BIN)_linux_amd64/$(BIN))
endif

ifeq "$(strip $(VERSION))" ""
Expand All @@ -37,20 +52,20 @@ endif

## Variable assertions

ifndef TEMPDIR
$(error TEMPDIR is not set)
ifndef TEMP_DIR
$(error TEMP_DIR is not set)
endif

ifndef RESULTSDIR
$(error RESULTSDIR is not set)
ifndef RESULTS_DIR
$(error RESULTS_DIR is not set)
endif

ifndef DISTDIR
$(error DISTDIR is not set)
ifndef DIST_DIR
$(error DIST_DIR is not set)
endif

ifndef SNAPSHOTDIR
$(error SNAPSHOTDIR is not set)
ifndef SNAPSHOT_DIR
$(error SNAPSHOT_DIR is not set)
endif

ifndef REF_NAME
Expand All @@ -74,29 +89,29 @@ test: unit ## Run all tests
ci-bootstrap:
DEBIAN_FRONTEND=noninteractive sudo apt update && sudo -E apt install -y bc jq libxml2-utils

$(RESULTSDIR):
mkdir -p $(RESULTSDIR)
$(RESULTS_DIR):
mkdir -p $(RESULTS_DIR)

$(TEMPDIR):
mkdir -p $(TEMPDIR)
$(TEMP_DIR):
mkdir -p $(TEMP_DIR)

.PHONY: bootstrap-tools
bootstrap-tools: $(TEMPDIR)
GO111MODULE=off GOBIN=$(shell realpath $(TEMPDIR)) go get -u golang.org/x/perf/cmd/benchstat
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(TEMPDIR)/ v1.47.2
curl -sSfL https://raw.githubusercontent.com/wagoodman/go-bouncer/master/bouncer.sh | sh -s -- -b $(TEMPDIR)/ v0.4.0
bootstrap-tools: $(TEMP_DIR)
GO111MODULE=off GOBIN=$(realpath $(TEMP_DIR)) go get -u golang.org/x/perf/cmd/benchstat
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(TEMP_DIR)/ $(GOLANG_CI_VERSION)
curl -sSfL https://raw.githubusercontent.com/wagoodman/go-bouncer/master/bouncer.sh | sh -s -- -b $(TEMP_DIR)/ $(GOBOUNCER_VERSION)
# we purposefully use the latest version of chronicle released
curl -sSfL https://raw.githubusercontent.com/anchore/chronicle/main/install.sh | sh -s -- -b $(TEMPDIR)/ v0.6.0
.github/scripts/goreleaser-install.sh -b $(TEMPDIR)/ v0.182.1
curl -sSfL https://raw.githubusercontent.com/anchore/chronicle/main/install.sh | sh -s -- -b $(TEMP_DIR)/ $(CHRONICLE_VERSION)
GOBIN="$(realpath $(TEMP_DIR))" go install github.com/goreleaser/goreleaser@$(GORELEASER_VERSION)
# the only difference between goimports and gosimports is that gosimports removes extra whitespace between import blocks (see https://github.com/golang/go/issues/20818)
GOBIN="$(shell realpath $(TEMPDIR))" go install github.com/rinchsan/gosimports/cmd/gosimports@v0.1.5
GOBIN="$(realpath $(TEMP_DIR))" go install github.com/rinchsan/gosimports/cmd/gosimports@$(GOSIMPORTS_VERSION)

.PHONY: bootstrap-go
bootstrap-go:
go mod download

.PHONY: bootstrap
bootstrap: $(RESULTSDIR) bootstrap-go bootstrap-tools ## Download and install all go dependencies (+ prep tooling in the ./tmp dir)
bootstrap: $(RESULTS_DIR) bootstrap-go bootstrap-tools ## Download and install all go dependencies (+ prep tooling in the ./tmp dir)
$(call title,Bootstrapping dependencies)

.PHONY: static-analysis
Expand Down Expand Up @@ -131,13 +146,13 @@ lint-fix: format ## Auto-format all source code + run golangci lint fixers

.PHONY: check-licenses
check-licenses:
$(TEMPDIR)/bouncer check
$(TEMP_DIR)/bouncer check ./...

check-go-mod-tidy:
@ .github/scripts/go-mod-tidy-check.sh && echo "go.mod and go.sum are tidy!"

.PHONY: unit
unit: $(RESULTSDIR) fixtures ## Run unit tests (with coverage)
unit: $(RESULTS_DIR) fixtures ## Run unit tests (with coverage)
$(call title,Running unit tests)
go test -coverprofile $(COVER_REPORT) $(shell go list ./... | grep -v anchore/chronicle/test)
@go tool cover -func $(COVER_REPORT) | grep total | awk '{print substr($$3, 1, length($$3)-1)}' > $(COVER_TOTAL)
Expand All @@ -154,17 +169,17 @@ fixtures-fingerprint:
find internal/git/test-fixtures/*.sh -type f -exec md5sum {} + | awk '{print $1}' | sort | md5sum | tee internal/git/test-fixtures/cache.fingerprint && echo "$(FIXTURE_CACHE_BUSTER)" >> internal/git/test-fixtures/cache.fingerprint

.PHONY: build
build: $(SNAPSHOTDIR) ## Build release snapshot binaries and packages
build: $(SNAPSHOT_DIR) ## Build release snapshot binaries and packages

$(SNAPSHOTDIR): ## Build snapshot release binaries and packages
$(SNAPSHOT_DIR): ## Build snapshot release binaries and packages
$(call title,Building snapshot artifacts)
# create a config with the dist dir overridden
echo "dist: $(SNAPSHOTDIR)" > $(TEMPDIR)/goreleaser.yaml
cat .goreleaser.yaml >> $(TEMPDIR)/goreleaser.yaml
echo "dist: $(SNAPSHOT_DIR)" > $(TEMP_DIR)/goreleaser.yaml
cat .goreleaser.yaml >> $(TEMP_DIR)/goreleaser.yaml

# build release snapshots
BUILD_GIT_TREE_STATE=$(GITTREESTATE) \
$(TEMPDIR)/goreleaser build --snapshot --skip-validate --rm-dist --config $(TEMPDIR)/goreleaser.yaml
$(TEMP_DIR)/goreleaser build --snapshot --skip-validate --rm-dist --config $(TEMP_DIR)/goreleaser.yaml

.PHONY: changelog
changelog: clean-changelog CHANGELOG.md
Expand All @@ -174,42 +189,40 @@ changelog: clean-changelog CHANGELOG.md
-t 748.5989 \
/CHANGELOG.md

CHANGELOG.md:
$(TEMPDIR)/chronicle > CHANGELOG.md
$(CHANGELOG):
$(TEMP_DIR)/chronicle > $(CHANGELOG)

.PHONY: release
release: clean-dist CHANGELOG.md ## Build and publish final binaries and packages.
release: clean-dist $(CHANGELOG) ## Build and publish final binaries and packages.
$(call title,Publishing release artifacts)

# create a config with the dist dir overridden
echo "dist: $(DISTDIR)" > $(TEMPDIR)/goreleaser.yaml
cat .goreleaser.yaml >> $(TEMPDIR)/goreleaser.yaml
echo "dist: $(DIST_DIR)" > $(TEMP_DIR)/goreleaser.yaml
cat .goreleaser.yaml >> $(TEMP_DIR)/goreleaser.yaml

# TODO: in the future add chronicle to generate changelogs
# release (note the version transformation from v0.7.0 --> 0.7.0)
bash -c "\
BUILD_GIT_TREE_STATE=$(GITTREESTATE) \
VERSION=$(VERSION:v%=%) \
$(TEMPDIR)/goreleaser \
$(TEMP_DIR)/goreleaser \
--rm-dist \
--config $(TEMPDIR)/goreleaser.yaml \
--release-notes <(cat CHANGELOG.md)"
--config $(TEMP_DIR)/goreleaser.yaml \
--release-notes <(cat $(CHANGELOG))"

.PHONY: clean
clean: clean-dist clean-snapshot ## Remove previous builds, result reports, and test cache
rm -rf $(RESULTSDIR)/*
rm -rf $(RESULTS_DIR)/*

.PHONY: clean-snapshot
clean-snapshot:
rm -rf $(SNAPSHOTDIR) $(TEMPDIR)/goreleaser.yaml
rm -rf $(SNAPSHOT_DIR) $(TEMP_DIR)/goreleaser.yaml

.PHONY: clean-dist
clean-dist: clean-changelog
rm -rf $(DISTDIR) $(TEMPDIR)/goreleaser.yaml
rm -rf $(DIST_DIR) $(TEMP_DIR)/goreleaser.yaml

.PHONY: clean-changelog
clean-changelog:
rm -f CHANGELOG.md
rm -f $(CHANGELOG)

.PHONY: help
help:
Expand Down
2 changes: 1 addition & 1 deletion chronicle/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

// SetLogger sets the logger object used for all logging calls.
func SetLogger(logger logger.Logger) {
log.Log = logger
log.Set(logger)
}

// SetBus sets the event bus for all published events onto (in-library subscriptions are not allowed).
Expand Down
6 changes: 3 additions & 3 deletions chronicle/release/releasers/github/gh_issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ issueLoop:
return results
}

// nolint:deadcode,unused
//nolint:deadcode,unused
func issuesAtOrAfter(since time.Time) issueFilter {
return func(issue ghIssue) bool {
keep := issue.ClosedAt.After(since) || issue.ClosedAt.Equal(since)
Expand Down Expand Up @@ -77,7 +77,7 @@ func issuesAfter(since time.Time) issueFilter {
}
}

// nolint:deadcode,unused
//nolint:deadcode,unused
func issuesBefore(since time.Time) issueFilter {
return func(issue ghIssue) bool {
keep := issue.ClosedAt.Before(since)
Expand Down Expand Up @@ -154,7 +154,7 @@ func issuesWithoutLabels() issueFilter {
}
}

// nolint:funlen
//nolint:funlen
func fetchClosedIssues(user, repo string) ([]ghIssue, error) {
src := oauth2.StaticTokenSource(
// TODO: DI this
Expand Down
6 changes: 3 additions & 3 deletions chronicle/release/releasers/github/gh_pull_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ prLoop:
return results, removed
}

// nolint:deadcode,unused
//nolint:deadcode,unused
func prsAtOrAfter(since time.Time) prFilter {
return func(pr ghPullRequest) bool {
keep := pr.MergedAt.After(since) || pr.MergedAt.Equal(since)
Expand Down Expand Up @@ -98,7 +98,7 @@ func prsAfter(since time.Time) prFilter {
}
}

// nolint:deadcode,unused
//nolint:deadcode,unused
func prsBefore(since time.Time) prFilter {
return func(pr ghPullRequest) bool {
keep := pr.MergedAt.Before(since)
Expand Down Expand Up @@ -237,7 +237,7 @@ func keepPRsWithCommits(prs []ghPullRequest, commits []string, filters ...prFilt
return results
}

// nolint:funlen
//nolint:funlen
func fetchMergedPRs(user, repo string) ([]ghPullRequest, error) {
src := oauth2.StaticTokenSource(
// TODO: DI this
Expand Down
2 changes: 1 addition & 1 deletion chronicle/release/releasers/github/gh_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func latestNonDraftRelease(releases []ghRelease) *ghRelease {
return nil
}

// nolint:funlen
//nolint:funlen
func fetchAllReleases(user, repo string) ([]ghRelease, error) {
src := oauth2.StaticTokenSource(
// TODO: DI this
Expand Down
2 changes: 1 addition & 1 deletion chronicle/release/releasers/github/summarizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (s *Summarizer) LastRelease() (*release.Release, error) {
return nil, fmt.Errorf("unable to find latest release")
}

// nolint:funlen
//nolint:funlen
func (s *Summarizer) Changes(sinceRef, untilRef string) ([]change.Change, error) {
var changes []change.Change
var err error
Expand Down
Loading