diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..155bddf --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,27 @@ +name: CI + +on: ["push", "release"] + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + lint: + name: "Lint the repository" + uses: ./.github/workflows/job-lint.yml + test: + name: "Run tests and lint artifacts" + needs: + - lint + secrets: inherit + strategy: + fail-fast: false # Run the whole matrix for maximum information. No matter if we fail with one job early. + matrix: + os: + - "macOS-latest" + - "ubuntu-latest" + - "windows-latest" + uses: ./.github/workflows/job-test.yml + with: + os: ${{ matrix.os }} diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml deleted file mode 100644 index 0291266..0000000 --- a/.github/workflows/go.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Go - -on: - push: - branches: ["master"] - pull_request: - branches: ["master"] - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: "1.21" - - - name: Build - run: make install - - - name: Test - run: make test-verbose diff --git a/.github/workflows/job-lint.yml b/.github/workflows/job-lint.yml new file mode 100644 index 0000000..71b44bb --- /dev/null +++ b/.github/workflows/job-lint.yml @@ -0,0 +1,18 @@ +on: + workflow_call: + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: "go.mod" + + - name: Lint + run: make lint + shell: bash # Explicitly use Bash because otherwise failing Windows jobs are not erroring. diff --git a/.github/workflows/job-test.yml b/.github/workflows/job-test.yml new file mode 100644 index 0000000..ecf5705 --- /dev/null +++ b/.github/workflows/job-test.yml @@ -0,0 +1,34 @@ +on: + workflow_call: + inputs: + os: + required: true + type: string + +jobs: + test: + runs-on: ${{ inputs.os }} + steps: + - uses: actions/checkout@v4 + + - uses: jlumbroso/free-disk-space@main + if: contains(inputs.os, 'ubuntu') + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: "go.mod" + + - name: Set up Git + run: | + git config --global user.name "GitHub Actions Bot" + git config --global user.email "<>" + shell: bash # Explicitly use Bash because otherwise failing Windows jobs are not erroring. + + - name: Build + run: make install + shell: bash # Explicitly use Bash because otherwise failing Windows jobs are not erroring. + + - name: Test + run: make test + shell: bash # Explicitly use Bash because otherwise failing Windows jobs are not erroring. diff --git a/.gitignore b/.gitignore index 9407b0b..e8d5a24 100644 --- a/.gitignore +++ b/.gitignore @@ -1,23 +1,21 @@ -# If you prefer the allow list template instead of the deny list, see community template: -# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore -# -# Binaries for programs and plugins +# Binaries for programs and plugins. +/bin *.exe *.exe~ *.dll *.so *.dylib -# Test binary, built with `go test -c` +# Test binary, built with `go test -c`. *.test -# Output of the go coverage tool, specifically when used with LiteIDE +# Output of the go coverage tool, specifically when used with LiteIDE. *.out -# Dependency directories (remove the comment below to include it) -# vendor/ +# Test artifacts +/limittest/memory -# Go workspace file +# Go workspace file. go.work # Ignore local configurations. diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..70931e5 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,8 @@ +{ + "recommendations": [ + "augustocdias.tasks-shell-input", + "golang.go", + "spadin.memento-inputs", + "Symflower.symflower" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..60e13dd --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,12 @@ +{ + "gopls": { + // Disable analyzers that we are currently not interested in because they do not obey our conventions. + "analyses": { + "simplifycompositelit": false, + }, + // Add parameter placeholders when completing a function. + "usePlaceholders": true, + }, + "symflower.lint.onOpen": true, + "symflower.lint.onSave": true, +} diff --git a/Makefile b/Makefile index a56f1d3..d58c551 100644 --- a/Makefile +++ b/Makefile @@ -9,55 +9,46 @@ export ARGS ifdef ARGS HAS_ARGS := "1" + PACKAGE := $(ARGS) else HAS_ARGS := PACKAGE := $(PACKAGE_BASE)/... endif -all: install-dependencies install-tools install lint test-verbose -.PHONY: all +ifdef NO_UNIT_TEST_CACHE + export NO_UNIT_TEST_CACHE=-count=1 +else + export NO_UNIT_TEST_CACHE= +endif -clean: +.DEFAULT_GOAL := help + +clean: # Clean up artifacts of the development environment to allow for untainted builds, installations and updates. go clean -i $(PACKAGE) go clean -i -race $(PACKAGE) .PHONY: clean -clean-coverage: - find $(ROOT_DIR) | grep .coverprofile | xargs rm -.PHONY: clean-coverage +editor: # Open our default IDE with the project's configuration. + @# WORKAROUND VS.code does not call Delve with absolute paths to files which it needs to set breakpoints. Until either Delve or VS.code have a fix we need to disable "-trimpath" which converts absolute to relative paths of Go builds which is a requirement for reproducible builds. + GOFLAGS="$(GOFLAGS) -trimpath=false" $(ROOT_DIR)/scripts/editor.sh +.PHONY: editor + +help: # Show this help message. + @grep -E '^[a-zA-Z-][a-zA-Z0-9.-]*?:.*?# (.+)' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?# "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' +.PHONY: help install: go install -v $(PACKAGE) .PHONY: install -install-dependencies: - go get -t -v $(PACKAGE) - go test -i -v $(PACKAGE) -.PHONY: install-dependencies - -install-tools: - # Install linting tools - go get -u -v github.com/kisielk/errcheck/... - go get -u -v honnef.co/go/tools/cmd/megacheck - - # Install code coverage tools - go get -u -v github.com/onsi/ginkgo/ginkgo/... - go get -u -v github.com/modocache/gover/... - go get -u -v github.com/mattn/goveralls/... -.PHONY: install-tools +install-all: install install-tools-linting install-tools-testing +.PHONY: install-all lint: - $(ROOT_DIR)/scripts/lint.sh + go tool github.com/kisielk/errcheck ./... + go vet ./... .PHONY: lint -test: - go test -race -test.timeout $(UNIT_TEST_TIMEOUT)s $(PACKAGE) +test: # [&1 | grep --invert-match -E "(Checking file|\%p of wrong type|can't check non-constant format|could not import C)") -if [ -n "$OUT" ]; then echo "$OUT"; PROBLEM=1; fi - -echo "megacheck:" -OUT=$(megacheck $PKG/...) -if [ -n "$OUT" ]; then echo "$OUT"; PROBLEM=1; fi - -if [ -n "$PROBLEM" ]; then exit 1; fi