From fde5497d8da933bcb3578a7e003d9c79319de7d7 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sat, 5 Oct 2024 18:35:52 -0500 Subject: [PATCH] ci: add basic workflows --- .github/workflows/lint.yml | 45 ++++++++++++++++++++++++++++++++++++++ .github/workflows/unit.yml | 33 ++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/unit.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..a0df2d3 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,45 @@ +on: [push, pull_request] + +jobs: + check: + runs-on: ubuntu-latest + name: Lint + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: "1.23.x" + - name: Check for //go:build ignore in .go files + run: | + IGNORED_FILES=$(grep -rl '//go:build ignore' . --include='*.go') || true + if [ -n "$IGNORED_FILES" ]; then + echo "::error::Found ignored Go files: $IGNORED_FILES" + exit 1 + fi + - name: Check that go.mod is tidied + if: success() || failure() # run this step even if the previous one failed + run: | + cp go.mod go.mod.orig + cp go.sum go.sum.orig + go mod tidy + diff go.mod go.mod.orig + diff go.sum go.sum.orig + - name: gofmt + if: success() || failure() # run this step even if the previous one failed + run: | + out=$(gofmt -s -l .) + if [[ -n "$out" ]]; then + echo $out | awk '{print "::error file=" $0 ",line=0,col=0::File is not gofmt-ed."}' + exit 1 + fi + - name: go vet + if: success() || failure() # run this step even if the previous one failed + run: go vet ./... + - name: Install staticcheck + if: success() || failure() # run this step even if the previous one failed + run: go install honnef.co/go/tools/cmd/staticcheck@v0.5.0 + - name: staticcheck + if: success() || failure() # run this step even if the previous one failed + run: | + set -o pipefail + staticcheck ./... | sed -e 's@\(.*\)\.go@./\1.go@g' diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml new file mode 100644 index 0000000..d0aafe4 --- /dev/null +++ b/.github/workflows/unit.yml @@ -0,0 +1,33 @@ +on: [push, pull_request] + +jobs: + unit: + strategy: + fail-fast: false + matrix: + os: [ "ubuntu", "windows", "macos" ] + go: [ "1.22.x", "1.23.x" ] + runs-on: ${{ fromJSON(vars[format('UNIT_RUNNER_{0}', matrix.os)] || format('"{0}-latest"', matrix.os)) }} + name: Unit tests (${{ matrix.os}}, Go ${{ matrix.go }}) + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go }} + - run: go version + - name: Run tests + env: + TIMESCALE_FACTOR: 10 + run: go test -v -cover -coverprofile coverage.txt ./... + - name: Run tests (32 bit) + if: ${{ matrix.os != 'macos' }} # can't run 32 bit tests on OSX. + env: + TIMESCALE_FACTOR: 10 + GOARCH: 386 + run: go test -v -cover + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 + with: + files: coverage.txt,coverage-root.txt + env_vars: OS=${{ matrix.os }}, GO=${{ matrix.go }} + token: ${{ secrets.CODECOV_TOKEN }}