Skip to content

Add GitHub Actions CI: lint, vet, unit tests and golangci-lint #192

Description

@GreedyKomodoDragon

Problem

There is no repository-level CI workflow using GitHub Actions. Adding a GitHub Actions workflow ensures pull requests get automatic linting, vetting, and unit-test verification on supported Go versions.

Suggested change

Add .github/workflows/ci.yml to run the following on push and PRs:

  • checkout
  • setup Go (matrix: 1.23, 1.24)
  • go mod download
  • run golangci-lint run (if configured in repo)
  • go vet ./...
  • go test ./... -race -cover

Apply this file:

*** Begin Patch
*** Add File: .github/workflows/ci.yml
+name: CI
+
+on:
+  push:
+    branches: [ main, master ]
+  pull_request:
+    branches: [ main, master ]
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        go-version: [1.23, 1.24]
+
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v4
+
+      - name: Set up Go
+        uses: actions/setup-go@v4
+        with:
+          go-version: ${{ matrix.go-version }}
+
+      - name: Cache Go modules
+        uses: actions/cache@v4
+        with:
+          path: |
+            ~/.cache/go-build
+            ~/.cache/golangci-lint
+            ${{ env.GOMODCACHE }}
+          key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
+          restore-keys: |
+            ${{ runner.os }}-go-${{ matrix.go-version }}-
+
+      - name: Install golangci-lint
+        run: |
+          curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $GITHUB_WORKSPACE/bin v1.52.2
+          echo "::add-path::$GITHUB_WORKSPACE/bin"
+
+      - name: Go mod download
+        run: go mod download
+
+      - name: Run golangci-lint
+        run: |
+          if [ -f .golangci.yml ] || [ -f .golangci.yaml ]; then
+            $GITHUB_WORKSPACE/bin/golangci-lint run ./...
+          else
+            echo "golangci-lint not configured, skipping"
+          fi
+
+      - name: go vet
+        run: go vet ./...
+
+      - name: go test
+        run: go test ./... -race -cover
+
*** End Patch

Notes

  • The action intentionally checks for .golangci.yml before running golangci-lint so repositories without a config won't fail.
  • Extend workflow later to build container images and push to registry on release tags.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions