Skip to content

Commit 4ed4599

Browse files
authored
refactor: extend nix configuration to support linting and testing (#191)
As part of this rework, an improved golangci-lint configuration has been adopted. All identified linting issues have been resolved. Minimal refactoring was introduced through the (errname) linter nsv: force~minor
1 parent b352cf4 commit 4ed4599

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+635
-403
lines changed

.github/workflows/ci.yml

Lines changed: 70 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,75 @@ permissions:
2020

2121
jobs:
2222
test:
23-
uses: purpleclay/github/.github/workflows/go-test.yml@main
2423
strategy:
2524
matrix:
26-
os: [ubuntu-24.04, macos-14, windows-2022]
27-
with:
28-
go-version: ${{ vars.GO_VERSION }}
29-
secrets:
30-
github-token: ${{ secrets.GITHUB_TOKEN }}
31-
32-
# lint:
33-
# runs-on: ubuntu-24.04
34-
# steps:
35-
# - name: Checkout
36-
# uses: actions/checkout@v4
37-
38-
# - name: golangci-lint
39-
# uses: dagger/dagger-for-github@v7
40-
# with:
41-
# verb: call
42-
# module: github.com/purpleclay/daggerverse/golang
43-
# args: --src . lint
44-
# cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }}
25+
os: [ubuntu-24.04, macos-latest]
26+
runs-on: ${{ matrix.os }}
27+
steps:
28+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
29+
30+
- uses: cachix/install-nix-action@f0fe604f8a612776892427721526b4c7cfb23aba # v31
31+
32+
- uses: cachix/cachix-action@0fc020193b5a1fa3ac4575aa3a7d3aa6a35435ad # v16
33+
with:
34+
name: purpleclay
35+
authToken: "${{ secrets.GH_CACHIX }}"
36+
37+
- run: nix run .#test
38+
39+
- name: Publish Summary
40+
if: always()
41+
run: nix develop -c tparse -format markdown -file reports/unittest.json -all > $GITHUB_STEP_SUMMARY
42+
env:
43+
NO_COLOR: 1
44+
45+
lint:
46+
runs-on: ubuntu-24.04
47+
steps:
48+
- name: Checkout
49+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
50+
51+
- uses: cachix/install-nix-action@f0fe604f8a612776892427721526b4c7cfb23aba # v31
52+
53+
- uses: cachix/cachix-action@0fc020193b5a1fa3ac4575aa3a7d3aa6a35435ad # v16
54+
with:
55+
name: purpleclay
56+
authToken: "${{ secrets.GH_CACHIX }}"
57+
58+
- run: nix run .#lint
59+
60+
alejandra:
61+
runs-on: ubuntu-24.04
62+
steps:
63+
- name: Checkout
64+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
65+
66+
- uses: cachix/install-nix-action@f0fe604f8a612776892427721526b4c7cfb23aba # v31
67+
68+
- uses: cachix/cachix-action@0fc020193b5a1fa3ac4575aa3a7d3aa6a35435ad # v16
69+
with:
70+
name: purpleclay
71+
authToken: "${{ secrets.GH_CACHIX }}"
72+
skipPush: true
73+
useDaemon: false
74+
75+
- name: Run Alejandra
76+
run: nix develop -c alejandra --check .
77+
78+
typos:
79+
runs-on: ubuntu-24.04
80+
steps:
81+
- name: Checkout
82+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
83+
84+
- uses: cachix/install-nix-action@f0fe604f8a612776892427721526b4c7cfb23aba # v31
85+
86+
- uses: cachix/cachix-action@0fc020193b5a1fa3ac4575aa3a7d3aa6a35435ad # v16
87+
with:
88+
name: purpleclay
89+
authToken: "${{ secrets.GH_CACHIX }}"
90+
skipPush: true
91+
useDaemon: false
92+
93+
- name: Run Typos
94+
run: nix develop -c typos

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
!.gitignore
88
!.golangci.yaml
99
!.goreleaser.yaml
10+
!.zed/settings.json
1011
!CODEOWNERS
1112
!CODE_OF_CONDUCT.md
1213
!htmltest.yml
1314
!LICENSE
1415
!mkdocs.yml
1516
!README.md
1617
!taskfile.yaml
18+
!justfile
1719
!docs/**/*
1820

1921
# Allow Nix files

.golangci.yaml

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,62 @@
1+
version: "2"
12
run:
23
timeout: 5m
4+
tests: true
35

46
linters:
5-
disable-all: true
7+
default: none
68
enable:
9+
- bodyclose
10+
- contextcheck
11+
- copyloopvar
712
- dupl
8-
- gofumpt
9-
- goimports
10-
- gosimple
13+
- durationcheck
14+
- errcheck
15+
- errname
16+
- forbidigo
17+
- goconst
18+
- gocritic
19+
- gocyclo
20+
- godot
21+
- gosec
1122
- govet
1223
- ineffassign
1324
- misspell
14-
- nakedret
25+
- nilnil
26+
- reassign
1527
- revive
28+
- spancheck
1629
- staticcheck
30+
- tagliatelle
31+
- testifylint
32+
- thelper
33+
- tparallel
1734
- unused
35+
- wrapcheck
36+
settings:
37+
errcheck:
38+
check-type-assertions: true
39+
goconst:
40+
numbers: true
41+
gocyclo:
42+
min-complexity: 15
43+
tagliatelle:
44+
case:
45+
rules:
46+
json: snake
47+
48+
formatters:
49+
enable:
50+
- gci
51+
- gofumpt
52+
53+
settings:
54+
gci:
55+
sections:
56+
- standard
57+
- default
58+
- localmodule
1859

19-
linters-settings:
20-
dupl:
21-
threshold: 400
60+
issues:
61+
max-issues-per-linter: 50
62+
max-same-issues: 0

.zed/settings.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"languages": {
3+
"Nix": {
4+
"language_servers": ["nil", "!nixd"]
5+
}
6+
},
7+
"lsp": {
8+
"nil": {
9+
"initialization_options": {
10+
"formatting": {
11+
"command": ["alejandra", "--quiet", "--"]
12+
}
13+
},
14+
"settings": {
15+
"diagnostics": {
16+
"ignored": ["unused_binding"]
17+
}
18+
}
19+
}
20+
}
21+
}

checkout.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
// CheckoutOption provides a way for setting specific options while attempting
88
// to checkout a branch. Each supported option can customize how a branch is checked
9-
// out from the remote and integrated into the current repository (working directory)
9+
// out from the remote and integrated into the current repository (working directory).
1010
type CheckoutOption func(*checkoutOptions)
1111

1212
type checkoutOptions struct {
@@ -18,7 +18,7 @@ type checkoutOptions struct {
1818
// any config defined within existing git config files. Config must be
1919
// provided as key value pairs, mismatched config will result in an
2020
// [ErrMissingConfigValue] error. Any invalid paths will result in an
21-
// [ErrInvalidConfigPath] error
21+
// [ErrInvalidConfigPath] error.
2222
func WithCheckoutConfig(kv ...string) CheckoutOption {
2323
return func(opts *checkoutOptions) {
2424
opts.Config = trim(kv...)
@@ -28,7 +28,7 @@ func WithCheckoutConfig(kv ...string) CheckoutOption {
2828
// Checkout will attempt to checkout a branch with the given name. If the branch
2929
// does not exist, it is created at the current working tree reference (or commit),
3030
// and then switched to. If the branch does exist, then switching to it restores
31-
// all working tree files
31+
// all working tree files.
3232
func (c *Client) Checkout(branch string, opts ...CheckoutOption) (string, error) {
3333
options := &checkoutOptions{}
3434
for _, opt := range opts {

checkout_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package git_test
33
import (
44
"testing"
55

6-
git "github.com/purpleclay/gitz"
7-
"github.com/purpleclay/gitz/gittest"
86
"github.com/stretchr/testify/assert"
97
"github.com/stretchr/testify/require"
8+
9+
git "github.com/purpleclay/gitz"
10+
"github.com/purpleclay/gitz/gittest"
1011
)
1112

1213
func TestCheckout(t *testing.T) {
@@ -21,7 +22,7 @@ write tests for branch checkout
2122

2223
// Inspect the raw git output
2324
assert.Contains(t, out, "Switched to branch 'main'")
24-
assert.Equal(t, gittest.LastCommit(t).Message, "docs: update existing project README")
25+
assert.Equal(t, "docs: update existing project README", gittest.LastCommit(t).Message)
2526
}
2627

2728
func TestCheckoutCreatesLocalBranch(t *testing.T) {

0 commit comments

Comments
 (0)