From 4f4cd62a87310330a863f7fc90ad80b16482f43b Mon Sep 17 00:00:00 2001 From: bvanvugt <1531419+bvanvugt@users.noreply.github.com> Date: Mon, 20 Feb 2023 00:25:17 +0000 Subject: [PATCH] Move test commands into Makefile. --- .github/workflows/release.yml | 13 +++++++++---- .github/workflows/test.yml | 27 +++++++++++++-------------- Makefile | 23 +++++++++++++++++++++++ 3 files changed, 45 insertions(+), 18 deletions(-) create mode 100644 Makefile diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 28659f2..eecf51e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,14 +1,19 @@ -name: Release (goreleaser) +name: Release on: - push: - tags: - - '*' + release: + types: [published] + branches: [main] env: GO_VERSION: '1.20' jobs: + + test: + name: Test + uses: ./.github/workflows/test.yml + goreleaser: runs-on: ubuntu-latest steps: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3a2971e..a7f7cfb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,11 @@ name: Test -on: [push, pull_request] +on: + push: # Branch pushes only, not tags + branches: + - '**' + pull_request: + workflow_call: # Allow other workflows to call this one env: GO_VERSION: '1.20' @@ -16,8 +21,7 @@ jobs: with: go-version: '${{ env.GO_VERSION }}' check-latest: true - - name: Run gofmt - run: test -z $(gofmt -l .) || (gofmt -d . && exit 1) + - run: make test-format lint: name: Lint (golangci-lint) @@ -29,13 +33,10 @@ jobs: with: go-version: '${{ env.GO_VERSION }}' check-latest: true - - name: Run golangci-lint - run: | - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.51.1 - golangci-lint run -v ./... + - run: make test-lint test: - name: Test (go test) + name: Tests (go test) runs-on: ubuntu-latest needs: [lint] steps: @@ -44,8 +45,7 @@ jobs: with: go-version: '${{ env.GO_VERSION }}' check-latest: true - - name: Run go test - run: go test -race ./... + - run: make test-unit build-cli: name: Build CLI (go build) @@ -57,7 +57,6 @@ jobs: with: go-version: '${{ env.GO_VERSION }}' check-latest: true - - name: Run go build - run: | - go build ./cli/battlesnake - ./battlesnake --help + - run: | + make build-cli + battlesnake --help diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..177e53e --- /dev/null +++ b/Makefile @@ -0,0 +1,23 @@ +GOLANGCI_LINT_VERSION ?= 1.51.1 + +/go/bin/golangci-lint: + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ${GOPATH}/bin v${GOLANGCI_LINT_VERSION} + +build-cli: + go install ./cli/battlesnake +.PHONY: cli + +test: test-format test-lint test-unit +.PHONY: test + +test-format: + test -z $(gofmt -l .) || (gofmt -l . && exit 1) +.PHONY: test-format + +test-lint: /go/bin/golangci-lint + /go/bin/golangci-lint run -v ./... +.PHONY: test-lint + +test-unit: + go test -race ./... +.PHONY: test-unit