Skip to content

Commit 9d2be89

Browse files
authored
Initial commit
0 parents  commit 9d2be89

File tree

7 files changed

+163
-0
lines changed

7 files changed

+163
-0
lines changed

.github/workflows/lint.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: lint
2+
3+
on:
4+
push:
5+
branches: [main] # on pushes TO main
6+
pull_request:
7+
branches: [main] # on pull requests AGAINST main
8+
9+
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-go@v5
15+
with:
16+
go-version: 'stable'
17+
- uses: golangci/golangci-lint-action@v6
18+
with:
19+
version: latest

.github/workflows/test.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: test
2+
3+
on:
4+
push:
5+
branches: [main] # on pushes TO main
6+
pull_request:
7+
branches: [main] # on pull requests AGAINST main
8+
9+
# cancel CI runs when a new commit is pushed to any branch except main
10+
concurrency:
11+
group: "test-${{ github.ref }}"
12+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
13+
14+
jobs:
15+
test:
16+
name: test
17+
runs-on: ubuntu-latest
18+
19+
strategy:
20+
matrix:
21+
# build against the two latest releases, to match golang's release
22+
# policy: https://go.dev/doc/devel/release#policy
23+
go-version:
24+
- 'stable'
25+
- 'oldstable'
26+
27+
steps:
28+
- name: setup
29+
uses: actions/setup-go@v5
30+
with:
31+
go-version: ${{matrix.go-version}}
32+
33+
- name: checkout
34+
uses: actions/checkout@v4
35+
36+
- name: test
37+
run: make testci
38+
39+
- name: report code coverage
40+
uses: codecov/codecov-action@v5
41+
with:
42+
files: ./coverage.out
43+
if: ${{ matrix.go-version == 'stable' }}

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, build with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Will McCutchen
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Default flags used by the test, testci, testcover targets
2+
COVERAGE_PATH ?= coverage.out
3+
COVERAGE_ARGS ?= -covermode=atomic -coverprofile=$(COVERAGE_PATH)
4+
TEST_ARGS ?= -race $(COVERAGE_ARGS)
5+
6+
# 3rd party tools
7+
LINT := go run github.com/mgechev/revive@v1.5.1
8+
STATICCHECK := go run honnef.co/go/tools/cmd/staticcheck@2024.1.1
9+
10+
test:
11+
go test $(TEST_ARGS) ./...
12+
.PHONY: test
13+
14+
# Test command to run for continuous integration, which includes code coverage
15+
# based on codecov.io's documentation:
16+
# https://github.com/codecov/example-go/blob/b85638743b972bd0bd2af63421fe513c6f968930/README.md
17+
testci:
18+
go test $(TEST_ARGS) $(COVERAGE_ARGS) ./...
19+
.PHONY: testci
20+
21+
testcover: testci
22+
go tool cover -html=$(COVERAGE_PATH)
23+
.PHONY: testcover
24+
25+
lint:
26+
test -z "$$(gofmt -d -s -e .)" || (echo "Error: gofmt failed"; gofmt -d -s -e . ; exit 1)
27+
go vet ./...
28+
$(LINT) -set_exit_status ./...
29+
$(STATICCHECK) ./...
30+
.PHONY: lint
31+
32+
clean:
33+
rm -rf $(COVERAGE_PATH)
34+
.PHONY: clean

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# go-pkg-template
2+
3+
[![Documentation](https://pkg.go.dev/badge/github.com/mccutchen/go-pkg-template)](https://pkg.go.dev/github.com/mccutchen/go-pkg-template)
4+
[![Build status](https://github.com/mccutchen/go-pkg-template/actions/workflows/test.yaml/badge.svg)](https://github.com/mccutchen/go-pkg-template/actions/workflows/test.yaml)
5+
[![Code coverage](https://codecov.io/gh/mccutchen/go-pkg-template/branch/main/graph/badge.svg)](https://codecov.io/gh/mccutchen/go-pkg-template)
6+
[![Go report card](http://goreportcard.com/badge/github.com/mccutchen/go-pkg-template)](https://goreportcard.com/report/github.com/mccutchen/go-pkg-template)
7+
8+
Template repo for Go packages/libraries
9+
10+
TODO:
11+
- Replace go-pkg-template with new repo name
12+
- Add high level description
13+
- Add usage examples
14+
- Set up branch protection rules
15+
- Require linear history
16+
- Require pull requests
17+
- Require lint/test CI checks to pass
18+
- Set up security scanning
19+
- Maybe:
20+
- Update go version in go.mod
21+
- Update action versions in .github/workflows/*.yaml
22+
23+
## Usage
24+
25+
TK
26+
27+
## Testing
28+
29+
```bash
30+
make test
31+
```

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/mccutchen/go-pkg-template
2+
3+
go 1.23.0

0 commit comments

Comments
 (0)