Skip to content

Commit eabee20

Browse files
nblair2GHOST-6
andauthored
build: CI Actions (lint/test, release), hooks (#1)
* linting using golangci-lint now applied at pre-commit hook and via GitHub Actions for any push (i.e. PR). Most of the changes in this should just be formatting and making the linter happy. In the future we will want to go back and start adding back some of the checks and improving the quality of code to make them happy, but for now this is better than it was. * pre-commit hook is provided so that contributors can ensure that both linting and testing pass before a commit is generated. This needs to be configured for each developer, just run 'make hooks'. Installing golangci-lint is left to the user. * makefile is provided to lint, fix, test * CI actions for auto lint/test and release on PR approval. This is my first time configuring the auto-release so we might have to come back and make some changes Co-authored-by: GHOST6 <github@nisb.net>
1 parent 77eecde commit eabee20

18 files changed

Lines changed: 906 additions & 318 deletions

.githooks/pre-commit

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
if (git diff --cached --name-only | grep --silent '\.go$'); then
4+
5+
make lint
6+
if [ $? -ne 0 ]; then
7+
echo "golangci-lint failed. You can try 'make fix' to automatically fix some issues. Commit aborted."
8+
exit 1
9+
fi
10+
11+
make test
12+
if [ $? -ne 0 ]; then
13+
echo "Tests failed. Commit aborted."
14+
exit 1
15+
fi
16+
fi

.github/workflows/ci.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
branches: [ "**" ]
6+
7+
jobs:
8+
golangci-lint:
9+
name: lint
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v5
13+
- uses: actions/setup-go@v6
14+
with:
15+
go-version: 1.24.4
16+
- uses: golangci/golangci-lint-action@v8
17+
with:
18+
version: v2.5.0
19+
20+
test:
21+
name: test
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v5
25+
- uses: actions/setup-go@v6
26+
with:
27+
go-version: 1.24.4
28+
- name: Install libpcap-dev
29+
run: sudo apt-get update && sudo apt-get install -y libpcap-dev
30+
- name: Download Go modules
31+
run: go mod download
32+
- name: Run Go tests
33+
run: make test

.github/workflows/release.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: release
2+
3+
on:
4+
workflow_run:
5+
workflows: [ "CI" ]
6+
types: [ completed ]
7+
branches: [ "main" ]
8+
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
issues: write
13+
14+
jobs:
15+
release:
16+
name: Run release-please
17+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v5
21+
- name: Run release-please
22+
id: release
23+
uses: googleapis/release-please-action@v4
24+
with:
25+
token: ${{ secrets.GITHUB_TOKEN }}
26+
release-type: go
27+
- name: Show release info
28+
run: |
29+
echo "Release created? ${{ steps.release.outputs.release_created }}"
30+
echo "Tag name: ${{ steps.release.outputs.tag_name }}"
31+
echo "Release notes body: ${{ steps.release.outputs.body}}"

.golangci.yml

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
version: "2"
2+
linters:
3+
enable:
4+
- arangolint
5+
- asasalint
6+
- asciicheck
7+
- bidichk
8+
- bodyclose
9+
- canonicalheader
10+
- containedctx
11+
- contextcheck
12+
- copyloopvar
13+
- cyclop
14+
- decorder
15+
- dogsled
16+
- dupl
17+
- dupword
18+
- durationcheck
19+
- embeddedstructfieldcheck
20+
- errcheck
21+
- errchkjson
22+
- errname
23+
- errorlint
24+
- exhaustive
25+
- exhaustruct
26+
- exptostd
27+
- fatcontext
28+
- forbidigo
29+
- forcetypeassert
30+
- funcorder
31+
- funlen
32+
- ginkgolinter
33+
- gocheckcompilerdirectives
34+
- gochecknoinits
35+
- gochecksumtype
36+
- gocognit
37+
- goconst
38+
- gocritic
39+
- gocyclo
40+
- godoclint
41+
- godot
42+
- godox
43+
- goheader
44+
- gomoddirectives
45+
- gomodguard
46+
- goprintffuncname
47+
- gosec
48+
- gosmopolitan
49+
- govet
50+
- grouper
51+
- iface
52+
- importas
53+
- inamedparam
54+
- ineffassign
55+
- intrange
56+
- iotamixing
57+
- ireturn
58+
- lll
59+
- loggercheck
60+
- maintidx
61+
- makezero
62+
- mirror
63+
- misspell
64+
- nakedret
65+
- nestif
66+
- nilerr
67+
- nilnesserr
68+
- nilnil
69+
- nlreturn
70+
- noctx
71+
- noinlineerr
72+
- nolintlint
73+
- nonamedreturns
74+
- nosprintfhostport
75+
- paralleltest
76+
- perfsprint
77+
- prealloc
78+
- predeclared
79+
- promlinter
80+
- protogetter
81+
- reassign
82+
- recvcheck
83+
- revive
84+
- rowserrcheck
85+
- sloglint
86+
- spancheck
87+
- sqlclosecheck
88+
- staticcheck
89+
- tagalign
90+
- tagliatelle
91+
- testableexamples
92+
- testifylint
93+
- testpackage
94+
- thelper
95+
- tparallel
96+
- unconvert
97+
- unparam
98+
- unqueryvet
99+
- unused
100+
- usestdlibvars
101+
- usetesting
102+
- wastedassign
103+
- whitespace
104+
- wrapcheck
105+
- wsl_v5
106+
- zerologlint
107+
exclusions:
108+
warn-unused: true
109+
rules:
110+
# Never
111+
- linters:
112+
- forbidigo
113+
path: dnp3/dnp3.go
114+
- linters:
115+
- godox
116+
text: "Line contains TODO/BUG/FIXME"
117+
- linters:
118+
- gosec
119+
text: "G115: integer overflow conversion"
120+
# Soonish
121+
- linters:
122+
- revive
123+
text: "should have comment or be unexported"
124+
- linters:
125+
- revive
126+
text: "exported: "
127+
# Soonest
128+
- linters:
129+
- funlen
130+
- maintidx
131+
text: "getPointsConstructor"
132+
- linters:
133+
- funlen
134+
- maintidx
135+
text: "getGroupVariationDescription"
136+
- linters:
137+
- funlen
138+
text: "Function 'newRangeFieldFromSpec' has too many statements"
139+
path: dnp3/appDataHeader.go
140+
141+
disable:
142+
- cyclop # re-add soonest (with gocyclo)
143+
- depguard
144+
- err113
145+
- exhaustruct
146+
- interfacebloat
147+
- ireturn # re-add soonest
148+
- gochecknoglobals
149+
- gocyclo # re-add soonest (with cyclop)
150+
- godoclint # re-add eventually (revive comment/unexported too)
151+
- mnd
152+
- musttag
153+
- varnamelen # re-add eventually
154+
155+
formatters:
156+
enable:
157+
- gci
158+
- gofmt
159+
- gofumpt
160+
- goimports
161+
- golines

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.PHONY: hooks lint fix test
2+
3+
hooks:
4+
git config core.hooksPath .githooks
5+
6+
lint:
7+
golangci-lint run ./...
8+
9+
fix:
10+
golangci-lint run ./... --fix
11+
12+
test:
13+
go test ./dnp3 -v -args -pcaps=opendnp3_test1.pcap

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# go-dnp3
22

3-
[![GoDoc](https://godoc.org/github.com/nblair2/go-dnp3?status.svg)](https://godoc.org/github.com/nblair2/go-dnp3)
3+
[![GoDoc](https://godoc.org/github.com/nblair2/go-dnp3?status.svg)](https://godoc.org/github.com/nblair2/go-dnp3/dnp3)
44
![Go Version](https://img.shields.io/github/go-mod/go-version/nblair2/go-dnp3?filename=go.mod&style=flat-square)
55
![License](https://img.shields.io/github/license/nblair2/go-dnp3?style=flat-square)
66

@@ -13,17 +13,18 @@ DNP3 parsing in go.
1313

1414
## Improvements
1515

16+
* [ ] accept interfaces, return structs
1617
* [ ] consistency on plural / singular of bits / bit and bytes / byte. Functions and attributes should be named based on what they actually are, and be as small as possible
1718
* [ ] errors always available / checked in `FromBytes` and `ToBytes` methods. Should buble these up but not fail if possible.
1819
* [ ] re-write a generic `Point` called `PointBytes` with flags and all possible fields (`Prefix`, `Flags`, `AbsTime`, `RelTime`) rather than the many different types we have now
1920
* [ ] clean up the the `String` method so we aren't always appending newlines, these should be the responsibility of the caller
2021
* [ ] consolidate the 3 different massive switch statements for Group / Variation into one
21-
* [ ] Always more point improvements (Events / Quality, Prefix parsing)
22+
* [ ] Events / Quality, Prefix parsing
2223
* [ ] `DIR` field / `PRM`
2324

2425
## Test
2526

26-
Run `go test -v` to check a few different DNP3 messages. You can also use the `-args -pcaps=examples/opendnp3_test1.pcap` argument to pass in a full PCAP. Data taken from [opendnp3 conformance reports](https://dnp3.github.io/conformance/report.html).
27+
Run `go test ./dnp3 -v` to check a few different DNP3 messages. You can also use the `-args -pcaps=opendnp3_test1.pcap` argument to pass in a full PCAP. Data taken from [opendnp3 conformance reports](https://dnp3.github.io/conformance/report.html).
2728

2829
## Spec
2930

0 commit comments

Comments
 (0)