Skip to content

Commit 72ad95f

Browse files
committed
feat: use Nix flake for lint and test flows
1 parent fb6883f commit 72ad95f

File tree

7 files changed

+78
-15
lines changed

7 files changed

+78
-15
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
name: Setup Go
3+
description: |
4+
Sets up the Go toolchain cache for faster execution.
5+
runs:
6+
using: composite
7+
steps:
8+
- name: Setup cache
9+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4
10+
with:
11+
path: |
12+
~/.cache/go-build
13+
~/go/pkg/mod
14+
key: ${{ runner.os }}-${{ github.workflow }}-golang-${{ hashFiles('**/go.sum') }}
15+
restore-keys: |
16+
${{ runner.os }}-${{ github.workflow }}-golang-
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Setup golangci-lint
3+
description: |
4+
Sets up golangci-lint cache and smooth buttery experience to make it go brrrr!
5+
runs:
6+
using: composite
7+
steps:
8+
- name: Setup Go
9+
uses: ./.github/actions/go-setup
10+
- name: Set cache directory in env
11+
shell: bash
12+
run: |
13+
echo "GOLANGCI_LINT_CACHE=$HOME/.cache/golangci-lint" >> $GITHUB_ENV
14+
- name: Setup cache
15+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4
16+
with:
17+
path: ${{ env.GOLANGCI_LINT_CACHE }}
18+
key: ${{ runner.os }}-golangci-lint-cache-${{ hashFiles('**/go.sum') }}
19+
restore-keys: |
20+
${{ runner.os }}-golangci-lint-cache-
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
name: Setup Nix and direnv
3+
description: |
4+
Sets up the Nix package manager and direnv to use the same packages
5+
vendored through Nix for local development.
6+
inputs:
7+
github_token:
8+
description: 'Github Access Token'
9+
required: true
10+
runs:
11+
using: composite
12+
steps:
13+
- name: Install Nix package manager
14+
uses: DeterminateSystems/nix-installer-action@e50d5f73bfe71c2dd0aa4218de8f4afa59f8f81d # v16
15+
with:
16+
extra-conf: |
17+
experimental-features = nix-command flakes
18+
- name: Set up Nix cache
19+
uses: DeterminateSystems/magic-nix-cache-action@6221693898146dc97e38ad0e013488a16477a4c4 # v9

.github/workflows/lint.yml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,20 @@ jobs:
2424
pull-requests: write
2525
steps:
2626
- name: Checkout source code
27-
uses: actions/checkout@v4
28-
- name: Set up Go
29-
uses: actions/setup-go@v5
27+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
3028
with:
31-
go-version: '1.21'
32-
- name: Run golangci-lint
33-
uses: golangci/golangci-lint-action@v6
29+
fetch-depth: 0
30+
- name: Set up Nix system
31+
uses: ./.github/actions/nix-setup
3432
with:
35-
args: --timeout=5m
33+
github_token: ${{ secrets.GITHUB_TOKEN }}
34+
- name: Setup Go
35+
uses: ./.github/actions/go-setup # NOTE: used for caching only.
36+
- name: Set up golangci-lint
37+
uses: ./.github/actions/golangci-lint-setup
38+
- name: Run golangci-lint
39+
run: make go.lint
40+
shell: nix develop --quiet -c bash -e {0}
3641

3742
super-linter:
3843
name: Super Linter

.github/workflows/test.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ jobs:
2121
runs-on: ubuntu-latest
2222
steps:
2323
- name: Checkout source code
24-
uses: actions/checkout@v4
25-
- name: Set up Go
26-
uses: actions/setup-go@v5
24+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
25+
- name: Set up Nix system
26+
uses: ./.github/actions/nix-setup
2727
with:
28-
go-version: '1.21'
29-
- name: Run go test
28+
github_token: ${{ secrets.GITHUB_TOKEN }}
29+
- name: Setup Go
30+
uses: ./.github/actions/go-setup # NOTE: used for caching only.
31+
- name: Run 'make go.test'
3032
run: make go.test
33+
shell: nix develop --quiet -c bash -e {0}
3134
- name: Upload coverage report
3235
uses: codecov/codecov-action@v4
3336
with:

.golangci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
version: "2"
33

44
run:
5-
go: "1.23"
5+
timeout: 5m
66

77
linters:
88
default: none

internal/user/user_by_email.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ func (handler *GetByEmailHandler) Process(_ context.Context, evt event.Persisted
7878
handler.mx.Lock()
7979
defer handler.mx.Unlock()
8080

81-
userEvent, ok := evt.Envelope.Message.(*Event)
81+
userEvent, ok := evt.Message.(*Event)
8282
if !ok {
83-
return fmt.Errorf("user.GetByEmailHandler: unexpected event type, %T", evt.Envelope.Message)
83+
return fmt.Errorf("user.GetByEmailHandler: unexpected event type, %T", evt.Message)
8484
}
8585

8686
switch kind := userEvent.Kind.(type) {

0 commit comments

Comments
 (0)