Skip to content

Commit

Permalink
build: improve developer experience for VS Code users
Browse files Browse the repository at this point in the history
  • Loading branch information
robertrossmann committed Mar 7, 2024
1 parent cdbbef8 commit bd88363
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 4 deletions.
17 changes: 17 additions & 0 deletions .github/matchers/golangci-lint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"problemMatcher": [
{
"owner": "golangci-lint",
"pattern": [
{
"regexp": "^(.+\\.go):(\\d+):(\\d+): \\w+: (.+) \\((\\w+)\\)$",
"file": 1,
"line": 2,
"column": 3,
"message": 4,
"code": 5
}
]
}
]
}
27 changes: 27 additions & 0 deletions .github/matchers/testify.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"problemMatcher": [
{
"owner": "github.com/stretchr/testify/assert",
"pattern": [
{
"regexp": "^\\s+Error Trace:\\s+(.+):(\\d+)$",
"file": 1,
"line": 2
},
{
"regexp": "^\\s+Error:\\s+(.+)(?=:?)",
"message": 1
}
]
},
{
"owner": "go",
"pattern": [
{
"regexp": "^(panic: .+)$",
"message": 1
}
]
}
]
}
4 changes: 4 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
with:
go-version-file: go.mod
- run: go version
- run: echo "::add-matcher::.github/matchers/golangci-lint.json"

- run: make lint

test:
Expand All @@ -32,6 +34,8 @@ jobs:
with:
go-version-file: go.mod
- run: go version
- run: echo "::add-matcher::.github/matchers/testify.json"

- run: make test
- name: Upload coverage reports to Codecov
if: success()
Expand Down
8 changes: 8 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"recommendations": [
"editorconfig.editorconfig",
"github.vscode-github-actions",
"github.vscode-pull-request-github",
"golang.go"
]
}
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"task.allowAutomaticTasks": "off",
"window.title": "go.strv.io/background${separator}${activeEditorShort}",
"go.lintTool": "golangci-lint",
"go.testTimeout": "5s",
"go.useLanguageServer": true,
"gopls": {
"ui.semanticTokens": true,
},
}
101 changes: 101 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "make: test",
"detail": "Run the test suite",
"type": "process",
"command": "make",
"args": [
"test"
],
"problemMatcher": {
"owner": "github.com/stretchr/testify/assert",
"applyTo": "allDocuments",
"fileLocation": [
"absolute"
],
"pattern": [
{
"regexp": "^\\s+Error Trace:\\s+(.+):(\\d+)$",
"file": 1,
"line": 2
},
// This is extremely rudimentary because VS Code does not support matching the message across multiple lines
// so this only shows the error but does not show the expected and actual values in the UI 🤦‍♂️
{
"regexp": "^\\s+Error:\\s+(.+)(?=:?)",
"message": 1
}
]
},
"isTestCommand": true,
"group": {
"kind": "test",
"isDefault": true
},
"presentation": {
"clear": true
},
"icon": {
"id": "beaker",
"color": "terminal.ansiGreen"
}
},
{
"label": "make: lint",
"detail": "Run the linter using Docker (golangci-lint)",
"type": "process",
"command": "make",
"args": [
"lint"
],
"problemMatcher": {
"owner": "golangci-lint",
"applyTo": "allDocuments",
"fileLocation": [
"relative",
"${workspaceFolder}"
],
"pattern": {
"regexp": "^(.+\\.go):(\\d+):(\\d+): \\w+: (.+) \\((\\w+)\\)$",
"file": 1,
"line": 2,
"column": 3,
"message": 4,
"code": 5
},
},
"group": {
"kind": "test",
"isDefault": false
},
"presentation": {
"clear": true,
},
"icon": {
"id": "eye",
"color": "terminal.ansiYellow"
}
},
{
"label": "make: clean",
"detail": "Remove compiled and generated files or caches",
"type": "process",
"command": "make",
"args": [
"clean"
],
"problemMatcher": [],
"presentation": {
"showReuseMessage": false,
"clear": true,
"close": true
},
"icon": {
"id": "trash",
"color": "terminal.ansiRed"
}
}
],
}
1 change: 0 additions & 1 deletion background.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ func (m *Manager) Close() {
m.Wait()
wg.Done()
}()
wg.Add(1)
go func() {
m.Cancel()
wg.Done()
Expand Down
2 changes: 1 addition & 1 deletion background_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
func Test_NewManager(t *testing.T) {
m := background.NewManager()
assert.NotNil(t, m)
assert.IsType(t, &background.Manager{}, m)
assert.IsType(t, background.Manager{}, m)

Check failure on line 18 in background_test.go

View workflow job for this annotation

GitHub Actions / test

Object expected to be of type background.Manager, but was *background.Manager
assert.EqualValues(t, 0, m.CountOf(background.TaskTypeOneOff))
assert.EqualValues(t, 0, m.CountOf(background.TaskTypeLoop))
}
Expand Down
3 changes: 2 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
all: lint test

lint: force
./tools/golangci-lint run -v
./tools/golangci-lint run --verbose

test: force
go test -v -timeout 5s -covermode=atomic -coverprofile=coverage.txt ./...

clean:
rm -rf .cache
rm coverage.txt

.PHONY: force
2 changes: 1 addition & 1 deletion tools/golangci-lint
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ exec docker run -t \
--volume "$(pwd):/app" \
--volume "$(pwd)/.cache/golangci-lint:/root/.cache" \
--workdir /app \
"$image" golangci-lint "$@"
"$image" golangci-lint --color never "$@" # Force no colour output to allow GH Actions problem matchers to work

0 comments on commit bd88363

Please sign in to comment.