Skip to content

Commit 51e35b6

Browse files
committed
initial version
0 parents  commit 51e35b6

32 files changed

+4980
-0
lines changed

.github/workflows/checks.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: go-test
2+
on: [push, pull_request]
3+
4+
jobs:
5+
checks:
6+
runs-on: ubuntu-latest
7+
8+
services:
9+
postgres:
10+
image: postgres:latest
11+
env:
12+
POSTGRES_DB: gosmig
13+
POSTGRES_USER: gosmig
14+
POSTGRES_PASSWORD: gosmig
15+
ports:
16+
- 5432:5432
17+
options: >-
18+
--health-cmd pg_isready
19+
--health-interval 10s
20+
--health-timeout 5s
21+
--health-retries 5
22+
23+
env:
24+
GOFLAGS: -buildvcs=false
25+
26+
steps:
27+
- uses: actions/checkout@v5
28+
29+
- name: Setup Go
30+
uses: actions/setup-go@v6
31+
with:
32+
go-version: '1.25.x'
33+
34+
- name: Check that Go modules are tidy
35+
uses: katexochen/go-tidy-check@v2
36+
37+
- name: Lint
38+
uses: golangci/golangci-lint-action@v8
39+
with:
40+
version: latest
41+
42+
- name: Check for vulnerabilities
43+
uses: golang/govulncheck-action@v1
44+
45+
- name: Build
46+
run: make build-only
47+
48+
- name: Test with coverage
49+
run: make test-coverage
50+
51+
- name: Check test coverage
52+
uses: vladopajic/go-test-coverage@v2
53+
with:
54+
config: ./.testcoverage.yml
55+

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.vscode
2+
cover.out
3+
cover.html

.testcoverage.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# (mandatory)
2+
# Path to coverage profile file (output of `go test -coverprofile` command).
3+
#
4+
# For cases where there are many coverage profiles, such as when running
5+
# unit tests and integration tests separately, you can combine all those
6+
# profiles into one. In this case, the profile should have a comma-separated list
7+
# of profile files, e.g., 'cover_unit.out,cover_integration.out'.
8+
profile: cover.out
9+
10+
# Holds coverage thresholds percentages, values should be in range [0-100].
11+
threshold:
12+
# (optional; default 0)
13+
# Minimum coverage percentage required for individual files.
14+
file: 90
15+
16+
# (optional; default 0)
17+
# Minimum coverage percentage required for each package.
18+
package: 90
19+
20+
# (optional; default 0)
21+
# Minimum overall project coverage percentage required.
22+
total: 95
23+
24+
# Holds regexp rules which will override thresholds for matched files or packages
25+
# using their paths.
26+
#
27+
# First rule from this list that matches file or package is going to apply
28+
# new threshold to it. If project has multiple rules that match same path,
29+
# override rules should be listed in order from specific to more general rules.
30+
override:
31+
# Increase coverage threshold to 100% for `foo` package
32+
# (default is 80, as configured above in this example).
33+
# - path: ^pkg/lib/foo$
34+
# threshold: 100
35+
36+
# Holds regexp rules which will exclude matched files or packages
37+
# from coverage statistics.
38+
exclude:
39+
# Exclude files or packages matching their paths
40+
paths:
41+
# - \.pb\.go$ # excludes all protobuf generated files
42+
# - ^pkg/bar # exclude package `pkg/bar`
43+
44+
# (optional; default false)
45+
# When true, requires all coverage-ignore annotations to include explanatory comments
46+
force-annotation-comment: false
47+
48+
# If specified, saves the current test coverage breakdown to this file.
49+
#
50+
# Typically, this breakdown is generated only for main (base) branches and
51+
# stored as an artifact. Later, this file can be used in feature branches
52+
# to compare test coverage against the base branch.
53+
breakdown-file-name: ''
54+
55+
diff:
56+
# Path to the test coverage breakdown file from the base branch.
57+
#
58+
# This file is usually generated and stored in the main (base) branch,
59+
# controled via `breakdown-file-name` property.
60+
# When set in a feature branch, it allows the tool to compute and report
61+
# the coverage difference between the current (feature) branch and the base.
62+
base-breakdown-file-name: ''
63+
64+
# Allowed threshold for the test coverage difference (in percentage)
65+
# between the feature branch and the base branch.
66+
#
67+
# By default, this is disabled (set to null). Valid values range from
68+
# -100.0 to +100.0.
69+
#
70+
# Example:
71+
# If set to 0.5, an error will be reported if the feature branch has
72+
# less than 0.5% more coverage than the base.
73+
#
74+
# If set to -0.5, the check allows up to 0.5% less coverage than the base.
75+
threshold: null

LICENSE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This is free and unencumbered software released into the public domain.
2+
3+
Anyone is free to copy, modify, publish, use, compile, sell, or
4+
distribute this software, either in source code form or as a compiled
5+
binary, for any purpose, commercial or non-commercial, and by any
6+
means.
7+
8+
In jurisdictions that recognize copyright laws, the author or authors
9+
of this software dedicate any and all copyright interest in the
10+
software to the public domain. We make this dedication for the benefit
11+
of the public at large and to the detriment of our heirs and
12+
successors. We intend this dedication to be an overt act of
13+
relinquishment in perpetuity of all present and future rights to this
14+
software under copyright law.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
23+
24+
For more information, please refer to <https://unlicense.org>

Makefile

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
cover_file = cover.out
2+
3+
lint:
4+
@echo "\n[lint] Linting ..."
5+
golangci-lint run
6+
7+
vulncheck:
8+
@echo "\n[vuln] Checking for vulnerabilities ..."
9+
govulncheck ./...
10+
11+
build: vulncheck lint
12+
@echo "\n[build] Building ..."
13+
go build -v ./...
14+
15+
build-only:
16+
@echo "\n[build] Building only ..."
17+
go build -v ./...
18+
19+
test:
20+
@echo "\n[test] Testing ..."
21+
go test -count=1 -shuffle=on -failfast -race -v ./...
22+
23+
test-docker:
24+
@bash -c '\
25+
set -e; \
26+
cleanup() { \
27+
echo "[docker] Stopping PostgreSQL container for tests ..."; \
28+
docker compose -f docker-compose.test.yml down -v; \
29+
}; \
30+
trap cleanup EXIT; \
31+
echo "[docker] Starting PostgreSQL container for tests ..."; \
32+
docker compose -f docker-compose.test.yml up -d; \
33+
echo "[docker] Waiting for PostgreSQL to be ready ..."; \
34+
sleep 2; \
35+
docker compose -f docker-compose.test.yml exec -T gosmig_test_postgres sh -c "while ! pg_isready -U gosmig -d gosmig; do echo \"[docker] Waiting for PostgreSQL...\"; sleep 2; done"; \
36+
echo "[docker] Running tests with Docker PostgreSQL ..."; \
37+
go test -count=1 -shuffle=on -failfast -race -v ./...; \
38+
'
39+
40+
test-docker-down:
41+
@echo "\n[docker] Stopping PostgreSQL container for tests ..."
42+
docker compose -f docker-compose.test.yml down -v
43+
44+
test-coverage:
45+
@echo "\n[coverage] Testing with coverage ..."
46+
go test -count=1 -shuffle=on -failfast -race -v -coverprofile=${cover_file} -covermode=atomic -coverpkg=./... ./...
47+
48+
test-coverage-html: test-coverage
49+
@echo "\n[coverage] Generating HTML coverage report ..."
50+
go tool cover -html=${cover_file}
51+
# Uncomment the following line to output the HTML report to a file:
52+
# go tool cover -html=${cover_file} -o=cover.html
53+
54+
install-go-test-coverage:
55+
@echo "\n[tools] Installing go-test-coverage tool ..."
56+
go install github.com/vladopajic/go-test-coverage/v2@latest
57+
58+
check-coverage: test-coverage
59+
@echo "\n[coverage] Checking coverage thresholds ..."
60+
go-test-coverage --config=./.testcoverage.yml
61+
62+
check-coverage-only: test-coverage
63+
@echo "\n[coverage] Checking coverage thresholds ..."
64+
go-test-coverage --config=./.testcoverage.yml
65+
66+
test-github-workflow:
67+
@echo "\n[ci] Running GitHub Actions checks locally ..."
68+
# Requires github.com/nektos/act
69+
act --job checks

0 commit comments

Comments
 (0)