From 0a67dd2c31eae6909476e493f854bb50edc554e9 Mon Sep 17 00:00:00 2001 From: Vaughan Whitteron Date: Tue, 27 Feb 2024 20:00:45 +0900 Subject: [PATCH 1/6] ci: disable vet scanning on kaitai struct output file --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1120862..27ffd7f 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ tidy: .PHONY: audit audit: go mod verify - go vet ./... + go vet ./ ./internal/utils # ignore Kaitai Struct files as they trip some rules go run honnef.co/go/tools/cmd/staticcheck@latest -checks=all,-ST1000,-U1000 ./... go run golang.org/x/vuln/cmd/govulncheck@latest ./... go test -race -buildvcs -vet=off ./... From 1050c246e700e407e82a4245f03386c09a7c7476 Mon Sep 17 00:00:00 2001 From: Vaughan Whitteron Date: Tue, 27 Feb 2024 20:13:18 +0900 Subject: [PATCH 2/6] fix: use conventional package names --- telemetry_client.go | 2 +- transformer.go | 2 +- unit_alternates.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/telemetry_client.go b/telemetry_client.go index c31320c..f874da3 100644 --- a/telemetry_client.go +++ b/telemetry_client.go @@ -1,4 +1,4 @@ -package telemetry_client +package telemetry import ( "bytes" diff --git a/transformer.go b/transformer.go index 68b39f2..29dabf8 100644 --- a/transformer.go +++ b/transformer.go @@ -1,4 +1,4 @@ -package telemetry_client +package telemetry import ( "math" diff --git a/unit_alternates.go b/unit_alternates.go index 1a4bc45..6aed5d1 100644 --- a/unit_alternates.go +++ b/unit_alternates.go @@ -1,4 +1,4 @@ -package telemetry_client +package telemetry import ( "fmt" From 14ba0105aef792ccbdbfd3ad405f820cbd6dcb77 Mon Sep 17 00:00:00 2001 From: Vaughan Whitteron Date: Tue, 27 Feb 2024 20:16:34 +0900 Subject: [PATCH 3/6] ci: rename workflow jobs and steps --- .github/workflows/main.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8bd75e1..30b9b67 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,7 +2,8 @@ name: Run Tests on: [push] jobs: - lint: + qualitycheck: + name: Quality Check runs-on: ubuntu-latest steps: - name: Checkout @@ -12,11 +13,11 @@ jobs: with: go-version-file: "go.mod" check-latest: true - - name: Setup golangci-lint + - name: Lint code uses: golangci/golangci-lint-action@v4 with: version: "v1.56.2" args: --verbose - - name: Quality Check + - name: Audit code run: | make audit From 5a2cd6862a8be7416abb52526419f94ec2d48a01 Mon Sep 17 00:00:00 2001 From: Vaughan Whitteron Date: Tue, 27 Feb 2024 20:17:16 +0900 Subject: [PATCH 4/6] ci: update makefile targets --- Makefile | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 27ffd7f..f7ff800 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ MAIN_PACKAGE_PATH := ./examples/simple BINARY_NAME := gt-telemetry + # ==================================================================================== # # HELPERS # ==================================================================================== # @@ -41,6 +42,11 @@ audit: go run golang.org/x/vuln/cmd/govulncheck@latest ./... go test -race -buildvcs -vet=off ./... +## lint: run linters +.PHONY: lint +lint: + golangci-lint run + # ==================================================================================== # # DEVELOPMENT @@ -57,16 +63,35 @@ test/cover: go test -v -race -buildvcs -coverprofile=/tmp/coverage.out ./... go tool cover -html=/tmp/coverage.out -## kaitai: compile the GT telemetry kaitai struct -.PHONY: kaitai -kaitai-struct: +## kaitai: compile the GT telemetry package from the Kaitai Struct +.PHONY: build/kaitai +build/kaitai: +ifeq (, $(shell which kaitai-struct-compilerx)) + $(error "kaitai-struct-compiler command not found, see https://kaitai.io/#download for installation instructions.") +endif @kaitai-struct-compiler --target go --go-package gttelemetry --outdir internal internal/kaitai/gran_turismo_telemetry.ksy ## build: build the application .PHONY: build -build: kaitai +build: @go build -o examples/bin/${BINARY_NAME} ${MAIN_PACKAGE_PATH} +.PHONY: build-darwin +build-darwin: + @GOOS=darwin GOARCH=arm64 go build -o examples/bin/${BINARY_NAME}-darwin-arm64 ${MAIN_PACKAGE_PATH} + +.PHONY: build-linux +build-linux: + @GOOS=linux GOARCH=amd64 go build -o examples/bin/${BINARY_NAME}-linux-amd64 ${MAIN_PACKAGE_PATH} + +.PHONY: build-rpi +build-rpi: + @GOOS=linux GOARCH=arm64 go build -o examples/bin/${BINARY_NAME}-rpi-arm64 ${MAIN_PACKAGE_PATH} + +.PHONY: build-windows +build-windows: + @GOOS=windows GOARCH=amd64 go build -o examples/bin/${BINARY_NAME}-amd64.exe ${MAIN_PACKAGE_PATH} + ## run: run the application .PHONY: run run: build @@ -75,11 +100,7 @@ run: build ## run/live: run the application with reloading on file changes .PHONY: run/live run/live: - @go run ${MAIN_PACKAGE_PATH}/main.go \ - --build.cmd "make build" --build.bin "/tmp/bin/${BINARY_NAME}" --build.delay "100" \ - --build.exclude_dir "" \ - --build.include_ext "go, tpl, tmpl, html, css, scss, js, ts, sql, jpeg, jpg, gif, png, bmp, svg, webp, ico" \ - --misc.clean_on_exit "true" + @go run ${MAIN_PACKAGE_PATH}/main.go ## clean: clean up project and return to a pristine state .PHONY: clean From 2b7faa10d9e7ae8932be370f4336692133c48ecd Mon Sep 17 00:00:00 2001 From: Vaughan Whitteron Date: Tue, 27 Feb 2024 20:28:06 +0900 Subject: [PATCH 5/6] ci: allow manual execution of workflow --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 30b9b67..dba5e89 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,5 +1,5 @@ name: Run Tests -on: [push] +on: [push, workflow_dispatch] jobs: qualitycheck: From 29608700878907f1e2175daea4ef686bbd062195 Mon Sep 17 00:00:00 2001 From: Vaughan Whitteron Date: Tue, 27 Feb 2024 20:41:09 +0900 Subject: [PATCH 6/6] ci: add test workflow --- .github/workflows/main.yml | 22 ++++++++++++++++++++++ .gitignore | 6 ++++++ Makefile | 11 ++++++++--- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dba5e89..d4fb019 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,3 +21,25 @@ jobs: - name: Audit code run: | make audit + + test: + name: Test + needs: qualitycheck + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version-file: "go.mod" + check-latest: true + - name: Run tests + run: make test + - name: Generate coverage report + run: make test/cover + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4.0.1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + slug: vwhitteron/gt-telemetry \ No newline at end of file diff --git a/.gitignore b/.gitignore index bc22b1f..e0d41a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,8 @@ +# MacOS hidden files .DS_Store + +# Build files examples/bin/ + +# Coverage reports +*.out \ No newline at end of file diff --git a/Makefile b/Makefile index f7ff800..b05685c 100644 --- a/Makefile +++ b/Makefile @@ -60,8 +60,12 @@ test: ## test/cover: run all tests and display coverage .PHONY: test/cover test/cover: - go test -v -race -buildvcs -coverprofile=/tmp/coverage.out ./... - go tool cover -html=/tmp/coverage.out + go test -v -race -buildvcs -coverprofile=coverage.out ./... + +## test/cover/show: run all tests and display coverage in a browser +.PHONY: test/cover/show +test/cover/show: test/cover + go tool cover -html=coverage.out ## kaitai: compile the GT telemetry package from the Kaitai Struct .PHONY: build/kaitai @@ -106,4 +110,5 @@ run/live: .PHONY: clean clean: @go clean - @rm -rf examples/bin \ No newline at end of file + @rm -rf examples/bin + @rm -f coverage.out \ No newline at end of file