Skip to content

Commit

Permalink
Add preflight checks for clearer failures and reference go.mod where …
Browse files Browse the repository at this point in the history
…possible (#384)

Closes: #383

It seems like go has a general issue with forward versioning as seen
here: golang/go#55092 and the `gvm`
project does not look to be healthy.

Until some of that dust settles, it makes sense to add a preflight check
to ensure that this repo fails before buildtime if the build environment
is wrong.

1. Add a preflight check such that go is detected in the PATH
1. Adds a preflight check such that go version mismatches are more
explicit
1. Updates CI to reference go.mod to prevent heartburn and headaches
  • Loading branch information
unlikelyzero authored Sep 3, 2024
1 parent ef60ed2 commit 80a13f3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:
fetch-depth: 0
# Go env
- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: "1.23"
go-version-file: 'go.mod'
# make test
- name: Test
run: go test -v ./...
Expand All @@ -32,9 +32,12 @@ jobs:
fetch-depth: 0
# Go env
- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: "1.23"
go-version-file: 'go.mod'
# Preflight checks
- name: Preflight checks
run: make check-go-version
# make build
- name: Build
run: go build -v cmd/grafana-app-sdk/*.go
19 changes: 11 additions & 8 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ jobs:
uses: actions/checkout@v4

- name: Set go version
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version-file: go.mod
go-version-file: 'go.mod'

- name: Update workspace
run: make update-workspace
Expand All @@ -43,9 +43,9 @@ jobs:
fetch-depth: 0
# go env
- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: "1.23"
go-version-file: 'go.mod'
# make lint
- name: Lint
uses: golangci/golangci-lint-action@v3
Expand All @@ -63,9 +63,9 @@ jobs:
fetch-depth: 0
# go env
- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: "1.23"
go-version-file: 'go.mod'
# make test
- name: Test
# find all go.mod files and run go test against directories containing go.mod files
Expand All @@ -80,9 +80,12 @@ jobs:
fetch-depth: 0
# go env
- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: "1.23"
go-version-file: 'go.mod'
# Preflight checks
- name: Preflight checks
run: make check-go-version
# make build
- name: Build
run: go build -v cmd/grafana-app-sdk/*.go
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.23"
go-version-file: 'go.mod'
# make test
- name: Test
run: go test -v ./...
Expand All @@ -38,7 +38,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.23"
go-version-file: 'go.mod'
# Install the CLI
- name: Install the CLI
run: cd cmd/grafana-app-sdk && go install && cd -
Expand Down Expand Up @@ -141,7 +141,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
go-version-file: 'go.mod'
# Release
- name: Create Release
uses: goreleaser/goreleaser-action@v4
Expand Down
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,23 @@ GOWORK := go.work
GOWORKSUM := go.work.sum
VENDOR := vendor
COVOUT := coverage.out
GOVERSION := $(shell awk '/^go / {print $$2}' go.mod)
GOBINARY := $(shell which go)

BIN_DIR := target

all: deps lint test build
.PHONY: check-go-version
check-go-version:
@if [ -z "$(GOBINARY)" ]; then \
echo "Error: No Go binary found. It's a no-go!"; \
exit 1; \
fi; \
if [ "$$($(GOBINARY) version | awk '{print $$3}' | sed 's/go//')" != "$(GOVERSION)" ]; then \
echo "Error: Go version $(GOVERSION) is required, but version $$($(GOBINARY) version | awk '{print $$3}' | sed 's/go//') is installed."; \
exit 1; \
fi

all: check-go-version deps lint test build

deps: $(GOSUM) $(GOWORKSUM)
$(GOSUM): $(SOURCES) $(GOMOD)
Expand Down

0 comments on commit 80a13f3

Please sign in to comment.