Skip to content

Commit 2fe13b3

Browse files
Merge pull request #1 from thisisdevelopment/feature/generics
Feature/generics
2 parents 30e241e + f346e9b commit 2fe13b3

17 files changed

Lines changed: 1391 additions & 517 deletions

.circleci/config.yml

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,93 @@
1-
version: 2.1 # use CircleCI 2.0
1+
version: 2.1 # use CircleCI 2.1
22
orbs:
3-
codecov: codecov/codecov@1.0.5
3+
codecov: codecov/codecov@4.0.1
44
jobs: # basic units of work in a run
55
build: # runs not using Workflows must have a `build` job as entry point
66
docker: # run the steps with Docker
7-
# CircleCI Go images available at: https://hub.docker.com/r/circleci/golang/
8-
- image: circleci/golang:1.13 #
7+
# Updated Go image with Go 1.21+ support for generics
8+
- image: cimg/go:1.21
99
environment:
1010
GO111MODULE: "on"
1111
# CircleCI PostgreSQL images available at: https://hub.docker.com/r/circleci/postgres/
12-
# directory where steps are run. Path must conform to the Go Workspace requirements
13-
working_directory: /go/src/github.com/thisisdevelopment/flashflood
12+
# directory where steps are run - updated for v2 module
13+
working_directory: ~/project
1414

1515
environment: # environment variables for the build itself
1616
TEST_RESULTS: /tmp/test-results # path to where test results will be saved
1717

1818
steps: # steps that comprise the `build` job
19-
- checkout # check out source code to working directory
19+
- run:
20+
name: Checkout code via HTTPS
21+
command: |
22+
git clone https://github.com/thisisdevelopment/flashflood.git .
23+
git checkout $CIRCLE_SHA1
2024
- run: mkdir -p $TEST_RESULTS # create the test results directory
2125

2226
- restore_cache: # restores saved cache if no changes are detected since last run
2327
# Read about caching dependencies: https://circleci.com/docs/2.0/caching/
2428
keys:
25-
- v1-pkg-cache
29+
- v2-pkg-cache-{{ checksum "go.sum" }}
30+
- v2-pkg-cache-
31+
32+
# Install go-junit-report for test reporting
33+
- run: go install github.com/jstemmer/go-junit-report/v2@latest
2634

27-
# Normally, this step would be in a custom primary image;
28-
# we've added it here for the sake of explanation.
29-
- run: go get github.com/thisisdevelopment/flashflood
30-
- run: go get github.com/jstemmer/go-junit-report
35+
# Download dependencies
36+
- run:
37+
name: Download dependencies
38+
command: go mod download
39+
40+
# Verify dependencies and format
41+
- run:
42+
name: Verify and format code
43+
command: |
44+
go mod verify
45+
go fmt ./...
3146
47+
# Run tests with our test runner
3248
- run:
3349
name: Run unit tests
3450
command: |
35-
trap "go-junit-report <${TEST_RESULTS}/go-test.out > ${TEST_RESULTS}/go-test-report.xml" EXIT
36-
make test | tee ${TEST_RESULTS}/go-test.out
51+
# Use our test-runner.sh if available, otherwise use go test directly
52+
if [ -f "./test-runner.sh" ]; then
53+
chmod +x ./test-runner.sh
54+
./test-runner.sh -v -c
55+
else
56+
go test -v -race ./... | tee ${TEST_RESULTS}/go-test.out
57+
fi
58+
59+
# Generate JUnit report if go test output exists
60+
- run:
61+
name: Generate JUnit report
62+
command: |
63+
if [ -f "${TEST_RESULTS}/go-test.out" ]; then
64+
cat ${TEST_RESULTS}/go-test.out | go-junit-report > ${TEST_RESULTS}/go-test-report.xml
65+
fi
66+
when: always
3767

68+
# Run coverage separately to ensure we get the file
3869
- run:
3970
name: Run code coverage
4071
command: |
41-
go test -race -coverprofile=coverage.txt -covermode=atomic
42-
mv coverage.txt /tmp/test-results/
72+
go test -race -coverprofile=coverage.txt -covermode=atomic ./...
73+
if [ -f "coverage.txt" ]; then
74+
cp coverage.txt ${TEST_RESULTS}/coverage.txt
75+
fi
4376
44-
- run: make # pull and build dependencies for the project
77+
# Build the project to verify everything compiles
78+
- run:
79+
name: Build project
80+
command: |
81+
if [ -f "Makefile" ]; then
82+
make build-native
83+
else
84+
go build ./...
85+
fi
4586
4687
- save_cache: # Store cache in the /go/pkg directory
47-
key: v1-pkg-cache
88+
key: v2-pkg-cache-{{ checksum "go.sum" }}
4889
paths:
49-
- "/go/pkg"
90+
- "/home/circleci/go/pkg"
5091

5192
- store_artifacts: # Upload test summary for display in Artifacts: https://circleci.com/docs/2.0/artifacts/
5293
path: /tmp/test-results

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
# Output of the go coverage tool, specifically when used with LiteIDE
1212
*.out
13+
coverage.html
14+
coverage.txt
1315

1416
# Dependency directories (remove the comment below to include it)
1517
# vendor/

Makefile

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,46 @@
11
GOFILES = $(shell find . -name '*.go' -not -path './vendor/*')
22
GOPACKAGES = $(shell go list ./... | grep -v /vendor/)
33

4-
default: build
4+
default: test
55

66
workdir:
77
mkdir -p workdir
88

9-
build: workdir/flashflood
9+
# For library projects, build means compile-check all packages
10+
build: $(GOFILES)
11+
go build ./...
1012

13+
# Native build also just checks compilation for libraries
1114
build-native: $(GOFILES)
12-
go build -o workdir/native-flashflood .
13-
14-
workdir/flashflood: $(GOFILES)
15-
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o workdir/flashflood .
15+
go build ./...
1616

17+
# Run tests
1718
test: test-all
1819

1920
test-all:
20-
@go test -v $(GOPACKAGES)
21+
@go test -v $(GOPACKAGES)
22+
23+
# Run tests with coverage
24+
test-coverage:
25+
@go test -race -coverprofile=coverage.out -covermode=atomic $(GOPACKAGES)
26+
27+
# Format code
28+
fmt:
29+
@go fmt $(GOPACKAGES)
30+
31+
# Lint code
32+
lint:
33+
@if command -v golangci-lint >/dev/null 2>&1; then \
34+
golangci-lint run; \
35+
else \
36+
echo "golangci-lint not installed, skipping linting"; \
37+
fi
38+
39+
# Run all quality checks
40+
check: fmt lint test-coverage
41+
42+
# Clean build artifacts
43+
clean:
44+
rm -rf workdir coverage.out coverage.html coverage.txt
45+
46+
.PHONY: default build build-native test test-all test-coverage fmt lint check clean

0 commit comments

Comments
 (0)