From 4ade3314e8a76d84c0335657d0c7863e5b8fe679 Mon Sep 17 00:00:00 2001 From: Viacheslav Poturaev Date: Thu, 2 May 2024 14:51:52 +0200 Subject: [PATCH] Update CI and Makefile (#619) --- .github/workflows/gorelease.yml | 3 +-- .github/workflows/release-assets.yml | 2 +- .github/workflows/test.yml | 8 ++++---- Makefile | 25 ++++++++++++++++++------- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/.github/workflows/gorelease.yml b/.github/workflows/gorelease.yml index 2d8060f2..ef0c6dae 100644 --- a/.github/workflows/gorelease.yml +++ b/.github/workflows/gorelease.yml @@ -9,13 +9,12 @@ concurrency: cancel-in-progress: true env: - GO_VERSION: 1.19.x + GO_VERSION: stable jobs: gorelease: runs-on: ubuntu-latest steps: - name: Install Go stable - if: env.GO_VERSION != 'tip' uses: actions/setup-go@v5 with: go-version: ${{ env.GO_VERSION }} diff --git a/.github/workflows/release-assets.yml b/.github/workflows/release-assets.yml index ce08040f..5acc845a 100644 --- a/.github/workflows/release-assets.yml +++ b/.github/workflows/release-assets.yml @@ -15,7 +15,7 @@ jobs: - name: Install Go uses: actions/setup-go@v5 with: - go-version: 1.20.x + go-version: stable - name: Checkout code uses: actions/checkout@v4 - name: Build artifacts diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6bcf83f1..5a3662fb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ jobs: test: strategy: matrix: - go-version: [ 1.16.x, 1.17.x, 1.19.x, 1.20.x, 1.21.x ] # Lowest supported and current stable versions. + go-version: [ 1.16.x, 1.17.x, oldstable, stable ] # Lowest supported and current stable versions. runs-on: ubuntu-latest steps: - name: Install Go @@ -29,10 +29,10 @@ jobs: - name: Run gofmt run: gofmt -d -e . 2>&1 | tee outfile && test -z "$(cat outfile)" && rm outfile - name: Run staticcheck - if: matrix.go-version == '1.20.x' + if: matrix.go-version == 'stable' uses: dominikh/staticcheck-action@v1.3.1 with: - version: "2023.1.3" + version: "latest" install-go: false cache-key: ${{ matrix.go }} @@ -49,7 +49,7 @@ jobs: go install ./cmd/godog godog -f progress --strict - name: Report on code coverage - if: matrix.go-version == '1.17.x' + if: matrix.go-version == 'stable' uses: codecov/codecov-action@v4 with: file: ./coverage.txt diff --git a/Makefile b/Makefile index 01bbc5c4..aefccb13 100644 --- a/Makefile +++ b/Makefile @@ -2,21 +2,32 @@ VERS ?= $(shell git symbolic-ref -q --short HEAD || git describe --tags --exact-match) -FOUND_GO_VERSION := $(shell go version) -EXPECTED_GO_VERSION = 1.17 +GO_MAJOR_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1) +GO_MINOR_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2) +MINIMUM_SUPPORTED_GO_MAJOR_VERSION = 1 +MINIMUM_SUPPORTED_GO_MINOR_VERSION = 16 +GO_VERSION_VALIDATION_ERR_MSG = Go version $(GO_MAJOR_VERSION).$(GO_MINOR_VERSION) is not supported, please update to at least $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION).$(MINIMUM_SUPPORTED_GO_MINOR_VERSION) + .PHONY: check-go-version check-go-version: - @$(if $(findstring ${EXPECTED_GO_VERSION}, ${FOUND_GO_VERSION}),(exit 0),(echo Wrong go version! Please install ${EXPECTED_GO_VERSION}; exit 1)) + @if [ $(GO_MAJOR_VERSION) -gt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \ + exit 0 ;\ + elif [ $(GO_MAJOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \ + echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\ + exit 1; \ + elif [ $(GO_MINOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MINOR_VERSION) ] ; then \ + echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\ + exit 1; \ + fi test: check-go-version @echo "running all tests" - @go install ./... @go fmt ./... - @go run honnef.co/go/tools/cmd/staticcheck@v0.2.2 github.com/cucumber/godog - @go run honnef.co/go/tools/cmd/staticcheck@v0.2.2 github.com/cucumber/godog/cmd/godog + @go run honnef.co/go/tools/cmd/staticcheck@v0.4.7 github.com/cucumber/godog + @go run honnef.co/go/tools/cmd/staticcheck@v0.4.7 github.com/cucumber/godog/cmd/godog go vet ./... go test -race ./... - godog -f progress -c 4 + go run ./cmd/godog -f progress -c 4 gherkin: @if [ -z "$(VERS)" ]; then echo "Provide gherkin version like: 'VERS=commit-hash'"; exit 1; fi