From 8c28cf58fe7813b2a92f6b579e0b9cec9b187e83 Mon Sep 17 00:00:00 2001 From: Alex Goodman Date: Tue, 5 Sep 2023 12:30:40 -0400 Subject: [PATCH] add gh to benny and improve task bootstrapping --- .binny.yaml | 7 +++++++ .bouncer.yaml | 3 +++ Makefile | 42 +++++++++++++++++++++++++++++----------- Taskfile.yaml | 53 ++++++++++++++++++++++++++++++++++++++++++++++----- go.mod | 2 +- 5 files changed, 90 insertions(+), 17 deletions(-) diff --git a/.binny.yaml b/.binny.yaml index e14a66e..3c33f40 100644 --- a/.binny.yaml +++ b/.binny.yaml @@ -10,6 +10,13 @@ tools: # module: github.com/anchore/binny # path: cmd/binny + - name: gh + version: + want: v2.33.0 + method: github-release + with: + repo: cli/cli + - name: quill version: want: v0.4.1 diff --git a/.bouncer.yaml b/.bouncer.yaml index 73b6b01..115111c 100644 --- a/.bouncer.yaml +++ b/.bouncer.yaml @@ -12,3 +12,6 @@ ignore-packages: # All these files have been put into the public domain. # You can do whatever you want with these files. - github.com/xi2/xz + + # crypto/internal/boring is released under the openSSL license as a part of the Golang Standard Libary + - crypto/internal/boring \ No newline at end of file diff --git a/Makefile b/Makefile index 584dec0..8a798bd 100644 --- a/Makefile +++ b/Makefile @@ -1,29 +1,49 @@ OWNER = anchore PROJECT = binny -BINNY_VERSION = v0.1.0 - TOOL_DIR = .tool BINNY = $(TOOL_DIR)/binny TASK = $(TOOL_DIR)/task -.DEFAULT_GOAL := default +.DEFAULT_GOAL := make-default -.PHONY: default -default: $(TASK) - $(TASK) $@ +## Bootstrapping targets ################################# $(BINNY): @mkdir -p $(TOOL_DIR) - curl -sSfL https://raw.githubusercontent.com/$(OWNER)/$(PROJECT)/main/install.sh | sh -s -- -b $(TOOL_DIR) $(BINNY_VERSION) + @# we don't have a release of binny yet, so build off of the current branch + @#curl -sSfL https://raw.githubusercontent.com/$(OWNER)/$(PROJECT)/main/install.sh | sh -s -- -b $(TOOL_DIR) + go build -o $(TOOL_DIR)/$(PROJECT) ./cmd/$(PROJECT) $(TASK): $(BINNY) $(BINNY) install task -# for those of us that can't seem to kick the habit of typing `make ...` -# assume that any other target is a task in the taskfile. +.PHONY: ci-bootstrap-go +ci-bootstrap-go: + go mod download + +.PHONY: ci-bootstrap-tools +ci-bootstrap-tools: $(BINNY) + $(BINNY) install -v + +## Shim targets ################################# + +.PHONY: make-default +make-default: $(TASK) + @# run the default task in the taskfile + @$(TASK) + +# for those of us that can't seem to kick the habit of typing `make ...` lets wrap the superior `task` tool +TASKS := $(shell bash -c "$(TASK) -l | grep '^\* ' | cut -d' ' -f2 | tr -d ':' | tr '\n' ' '" ) $(shell bash -c "$(TASK) -l | grep 'aliases:' | cut -d ':' -f 3 | tr '\n' ' ' | tr -d ','") + +.PHONY: $(TASKS) +$(TASKS): $(TASK) + @$(TASK) $@ + %: $(TASK) - $(TASK) $@ + # it looks like you tried to run make without task being installed... try running the same command again + echo $(TASKS) + exit 1 help: $(TASK) - $(TASK) -l + @$(TASK) -l diff --git a/Taskfile.yaml b/Taskfile.yaml index 4ea9e49..7416be0 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -5,9 +5,6 @@ vars: OWNER: anchore PROJECT: binny - # unit test coverage threshold (in % coverage) - COVERAGE_THRESHOLD: 50 - TMP_DIR: .tmp SNAPSHOT_DIR: snapshot CHANGELOG: CHANGELOG.md @@ -19,6 +16,9 @@ tasks: default: desc: Run all validation tasks + aliases: + - pr-validations + - validations cmds: - task: static-analysis - task: test @@ -36,10 +36,44 @@ tasks: cmds: - task: unit + ## Bootstrap tasks ################################# + + binny: + internal: true + desc: Get the binny tool + generates: + - "{{ .TOOL_DIR }}/binny" + status: + - "test -f {{ .TOOL_DIR }}/binny" + # we just need a release of benny, doesn't matter which one (binny will update itself, this is just a bootstrap step) + # note: on the first release of binny, switch to the curl approach + # cmd: "curl -sSfL https://raw.githubusercontent.com/{{ .OWNER }}/{{ .PROJECT }}/main/install.sh | sh -s -- -b {{ .TOOL_DIR }}" + cmd: "go build -o {{ .TOOL_DIR }}/binny ./cmd/binny" + silent: true + + tools: + desc: Install all tools needed for CI and local development + deps: [binny] + generates: + - "{{ .TOOL_DIR }}/binny" + - "{{ .TOOL_DIR }}/goreleaser" + - "{{ .TOOL_DIR }}/chronicle" + - "{{ .TOOL_DIR }}/glow" + - "{{ .TOOL_DIR }}/golangci-lint" + - "{{ .TOOL_DIR }}/gosimports" + - "{{ .TOOL_DIR }}/bouncer" + - "{{ .TOOL_DIR }}/task" + status: + - "{{ .TOOL_DIR }}/binny check -v" + cmd: "{{ .TOOL_DIR }}/binny install -v" + silent: true + + ## Static analysis tasks ################################# format: desc: Auto-format all source code + deps: [tools] cmds: - gofmt -w -s . - "{{ .TOOL_DIR }}/gosimports -local github.com/anchore -w ." @@ -47,6 +81,7 @@ tasks: lint-fix: desc: Auto-format all source code + run golangci lint fixers + deps: [tools] cmds: - task: format - "{{ .TOOL_DIR }}/golangci-lint run --tests=false" @@ -58,6 +93,7 @@ tasks: sh: gofmt -l -s . BAD_FILE_NAMES: sh: "find . | grep -e ':' || true" + deps: [tools] cmds: # ensure there are no go fmt differences - cmd: 'test -z "{{ .BAD_FMT_FILES }}" || (echo "files with gofmt issues: [{{ .BAD_FMT_FILES }}]"; exit 1)' @@ -71,8 +107,8 @@ tasks: check-licenses: desc: Ensure transitive dependencies are compliant with the current license policy - cmds: - - "{{ .TOOL_DIR }}/bouncer check ./..." + deps: [tools] + cmd: "{{ .TOOL_DIR }}/bouncer check ./..." check-go-mod-tidy: desc: Ensure go.mod and go.sum are up to date @@ -86,6 +122,9 @@ tasks: vars: TEST_PKGS: sh: "go list ./... | grep -v {{ .OWNER }}/{{ .PROJECT }}/test | tr '\n' ' '" + + # unit test coverage threshold (in % coverage) + COVERAGE_THRESHOLD: 60 cmds: - cmd: "mkdir -p {{ .TMP_DIR }}" silent: true @@ -97,6 +136,7 @@ tasks: changelog: desc: Generate a changelog + deps: [tools] generates: - "{{ .CHANGELOG }}" - "{{ .NEXT_VERSION }}" @@ -108,6 +148,7 @@ tasks: desc: Create a snapshot release aliases: - build + deps: [tools] cmds: - silent: true cmd: | @@ -122,6 +163,7 @@ tasks: release: desc: Create a release interactive: true + deps: [tools] cmds: - cmd: .github/scripts/trigger-release.sh silent: true @@ -143,6 +185,7 @@ tasks: ci-release: desc: Create a release + deps: [tools] cmds: - task: ci-check - "{{ .TOOL_DIR }}/goreleaser release --clean" diff --git a/go.mod b/go.mod index 0dc98c1..db8a6c3 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/gabriel-vasile/mimetype v1.4.2 github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 github.com/google/yamlfmt v0.9.1-0.20230607021126-908b19015fc4 + github.com/hashicorp/go-multierror v1.1.1 github.com/mholt/archiver/v3 v3.5.1 github.com/mitchellh/hashstructure/v2 v2.0.2 github.com/mitchellh/mapstructure v1.5.0 @@ -41,7 +42,6 @@ require ( github.com/google/uuid v1.3.0 // indirect github.com/gookit/color v1.5.4 // indirect github.com/hashicorp/errwrap v1.0.0 // indirect - github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/iancoleman/strcase v0.3.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect