Skip to content

Commit

Permalink
add gh to benny and improve task bootstrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
wagoodman committed Sep 5, 2023
1 parent 1ebad9f commit 8c28cf5
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 17 deletions.
7 changes: 7 additions & 0 deletions .binny.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions .bouncer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
42 changes: 31 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
53 changes: 48 additions & 5 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,6 +16,9 @@ tasks:

default:
desc: Run all validation tasks
aliases:
- pr-validations
- validations
cmds:
- task: static-analysis
- task: test
Expand All @@ -36,17 +36,52 @@ 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 ."
- go mod tidy

lint-fix:
desc: Auto-format all source code + run golangci lint fixers
deps: [tools]
cmds:
- task: format
- "{{ .TOOL_DIR }}/golangci-lint run --tests=false"
Expand All @@ -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)'
Expand All @@ -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
Expand All @@ -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
Expand All @@ -97,6 +136,7 @@ tasks:

changelog:
desc: Generate a changelog
deps: [tools]
generates:
- "{{ .CHANGELOG }}"
- "{{ .NEXT_VERSION }}"
Expand All @@ -108,6 +148,7 @@ tasks:
desc: Create a snapshot release
aliases:
- build
deps: [tools]
cmds:
- silent: true
cmd: |
Expand All @@ -122,6 +163,7 @@ tasks:
release:
desc: Create a release
interactive: true
deps: [tools]
cmds:
- cmd: .github/scripts/trigger-release.sh
silent: true
Expand All @@ -143,6 +185,7 @@ tasks:

ci-release:
desc: Create a release
deps: [tools]
cmds:
- task: ci-check
- "{{ .TOOL_DIR }}/goreleaser release --clean"
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8c28cf5

Please sign in to comment.