diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8bd75e1..d4fb019 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,8 +1,9 @@ name: Run Tests -on: [push] +on: [push, workflow_dispatch] jobs: - lint: + qualitycheck: + name: Quality Check runs-on: ubuntu-latest steps: - name: Checkout @@ -12,11 +13,33 @@ 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 + + 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 1120862..b05685c 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ MAIN_PACKAGE_PATH := ./examples/simple BINARY_NAME := gt-telemetry + # ==================================================================================== # # HELPERS # ==================================================================================== # @@ -36,11 +37,16 @@ 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 ./... +## lint: run linters +.PHONY: lint +lint: + golangci-lint run + # ==================================================================================== # # DEVELOPMENT @@ -54,19 +60,42 @@ 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 - -## kaitai: compile the GT telemetry kaitai struct -.PHONY: kaitai -kaitai-struct: + 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 +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,14 +104,11 @@ 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 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 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"