Skip to content

Commit

Permalink
Merge branch 'master' into module-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
frankcarey authored Jun 22, 2022
2 parents e106e62 + 861f002 commit e7a2409
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 35 deletions.
2 changes: 0 additions & 2 deletions .ahoy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ commands:
test:
usage: Run automated tests.
cmd: |
ahoy build
FAIL=false
TESTS=(
'go vet'
'go test -v -race '
'golint -set_exit_status'
'bats tests'
)
for i in "${TESTS[@]}"; do
Expand Down
53 changes: 44 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,48 @@
version: 2
version: 2.1
orbs:
go: circleci/[email protected]
workflows:
main:
jobs:
- build

jobs:
build:
working_directory: /go/src/github.com/ahoy-cli/ahoy
docker:
- image: circleci/golang
executor:
name: go/default
tag: '1.18'
working_directory: /home/circleci/go/src/github.com/ahoy-cli/ahoy
steps:
- checkout
- run: git clone https://github.com/bats-core/bats-core.git && cd bats-core && sudo ./install.sh /usr/local && bats --version && cd -
- run: sudo apt install php
- run: go get -u golang.org/x/lint/golint
- run: bash build.sh -v
- run: ./ahoy test
- run:
name: Install BATS.
command: git clone https://github.com/bats-core/bats-core.git && cd bats-core && sudo ./install.sh /usr/local && bats --version && cd -
- run:
name: Install Go linter.
command: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.46.2
- run:
name: Install PHP for testing.
command: sudo apt update && sudo apt install php7.4
- go/load-cache
- go/mod-download
- run:
name: Get Go modules.
command: |
go mod tidy
go mod vendor
go mod verify
- go/save-cache
- run:
name: Build project.
command: |
make
make version
- run:
name: Lint code.
command: /home/circleci/go/bin/golangci-lint run || true
- run:
name: Run unit tests.
command: make test
- run:
name: Run functional tests.
command: ./ahoy test
38 changes: 17 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,38 +1,34 @@
VERSION ?= $(shell cat VERSION)
GITCOMMIT := $(shell git rev-parse --short HEAD 2>/dev/null)
VERSION := $(shell git describe --tag $(GITCOMMIT) 2>/dev/null)

GITCOMMIT := $(shell git rev-parse HEAD 2>/dev/null)
GITBRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
BUILDTIME := $(shell TZ=GMT date "+%Y-%m-%d_%H:%M_GMT")
LDFLAGS := "-X main.Version=$(VERSION) -X main.GitCommit=$(GITCOMMIT) -X main.GitBranch=$(GITBRANCH) -X main.BuildTime=$(BUILDTIME)"
LDFLAGS := "-X main.version=$(VERSION) -X main.GitCommit=$(GITCOMMIT) -X main.GitBranch=$(GITBRANCH) -X main.BuildTime=$(BUILDTIME)"

SRCS = $(shell find . -name '*.go' | grep -v '^./vendor/')
PKGS := $(foreach pkg, $(sort $(dir $(SRCS))), $(pkg))

TESTARGS ?=

default:
go build -v
go build -ldflags $(LDFLAGS) -v -o ./ahoy

install:
cp ahoy /usr/local/bin/ahoy
chmod +x /usr/local/bin/ahoy

cross: build_dir
GOOS=linux GOARCH=amd64 \
LDFLAGS=$(LDFLAGS) \
go build -v -o ./builds/linux_amd64/ahoy

go build -ldflags $(LDFLAGS) -v -o ./builds/linux_amd64/ahoy

GOOS=linux GOARCH=arm64 \
LDFLAGS=$(LDFLAGS) \
go build -v -o ./builds/linux_arm64/ahoy

go build -ldflags $(LDFLAGS) -v -o ./builds/linux_arm64/ahoy

GOOS=darwin GOARCH=amd64 \
LDFLAGS=$(LDFLAGS) \
go build -v -o ./builds/darwin_amd64/ahoy

go build -ldflags $(LDFLAGS) -v -o ./builds/darwin_amd64/ahoy

GOOS=darwin GOARCH=arm64 \
LDFLAGS=$(LDFLAGS) \
go build -v -o ./builds/darwin_arm64/ahoy
go build -ldflags $(LDFLAGS) -v -o ./builds/darwin_arm64/ahoy

cross_tars: cross
COPYFILE_DISABLE=1 tar -zcvf ./builds/ahoy_linux_amd64.tar.gz -C builds/linux_amd64 ahoy
Expand All @@ -53,21 +49,21 @@ clean:
fmtcheck:
$(foreach file,$(SRCS),gofmt $(file) | diff -u $(file) - || exit;)

lint:
@ go get golang.org/x/lint/golint
$(foreach file,$(SRCS),golint $(file) || exit;)
staticcheck:
@ go install honnef.co/go/tools/cmd/staticcheck@latest
staticcheck ./...

vet:
$(foreach pkg,$(PKGS),go vet $(pkg) || exit;)

gocyclo:
@ go get github.com/fzipp/gocyclo/cmd/gocyclo
@ go install github.com/fzipp/gocyclo/cmd/gocyclo@latest
gocyclo -over 25 -avg -ignore "vendor" .

test: fmtcheck lint vet
test: fmtcheck staticcheck vet
go test *.go $(TESTARGS)

version:
@echo $(VERSION)

.PHONY: clean test fmtcheck lint vet gocyclo version testdeps cross cross_tars build_dir default install
.PHONY: clean test fmtcheck staticcheck vet gocyclo version testdeps cross cross_tars build_dir default install
5 changes: 2 additions & 3 deletions ahoy.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ type Command struct {

var app *cli.App
var sourcefile string
var args []string
var verbose bool
var bashCompletion bool

Expand Down Expand Up @@ -127,7 +126,7 @@ func getConfig(file string) (Config, error) {

func getSubCommands(includes []string) []cli.Command {
subCommands := []cli.Command{}
if 0 == len(includes) {
if len(includes) == 0 {
return subCommands
}
commands := map[string]cli.Command{}
Expand Down Expand Up @@ -241,7 +240,7 @@ func getCommands(config Config) []cli.Command {

if cmd.Imports != nil {
subCommands := getSubCommands(cmd.Imports)
if subCommands == nil || len(subCommands) == 0 {
if len(subCommands) == 0 {
logger("fatal", "Command ["+name+"] has 'imports' set, but no commands were found. Check your yaml file.")
}
newCmd.Subcommands = subCommands
Expand Down

0 comments on commit e7a2409

Please sign in to comment.