ci: add GitHub Actions workflow (format/vet/lint/test) (#27) #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| ci: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.25' | |
| - name: Check formatting | |
| run: | | |
| unformatted=$(gofmt -l .) | |
| if [ -n "$unformatted" ]; then | |
| echo "Unformatted files detected:"; echo "$unformatted"; exit 1 | |
| fi | |
| - name: Run go vet | |
| run: go vet ./... | |
| - name: Install golangci-lint | |
| run: | | |
| mkdir -p ./bin | |
| GOBIN=$(pwd)/bin go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest | |
| - name: Run golangci-lint (verbose) and save log | |
| run: | | |
| set +e | |
| mkdir -p artifacts | |
| ./bin/golangci-lint run ./... --verbose > artifacts/golangci.log 2>&1 || true | |
| rc=$? | |
| cat artifacts/golangci.log | |
| echo $rc > artifacts/golangci_exit | |
| - name: Upload golangci-lint log | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: golangci-log | |
| path: artifacts/golangci.log | |
| - name: Fail if golangci-lint reported issues | |
| run: | | |
| rc=$(cat artifacts/golangci_exit || echo 0) | |
| if [ "$rc" != "0" ]; then | |
| echo "golangci-lint failed with exit code $rc" | |
| exit $rc | |
| fi | |
| - name: Tidy modules | |
| run: go mod tidy | |
| - name: Build | |
| run: go build -v -o codewise main.go | |
| - name: Test | |
| run: go test ./... -v |