Skip to content

Commit 14c47ea

Browse files
authored
[linting] Add golangci-lint and GHA that runs it (#36)
## Summary * Moves tests over to own workflow. Release jobs depend on it. * Adds golangci linter and runs it in test workflows. * Adds new pull request template. ## How was it tested? GHA
1 parent be97495 commit 14c47ea

File tree

9 files changed

+115
-25
lines changed

9 files changed

+115
-25
lines changed

.github/pull_request_template.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Summary
2+
3+
## How was it tested?

.github/workflows/release.yml

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: release
22

3+
concurrency: deployment
4+
35
on:
46
# Build/Release on demand
57
workflow_dispatch:
@@ -20,23 +22,12 @@ permissions:
2022
contents: write
2123

2224
jobs:
23-
test:
24-
runs-on: ubuntu-latest
25-
steps:
26-
- name: Checkout source code
27-
uses: actions/checkout@v3
28-
- name: Set up go
29-
uses: actions/setup-go@v3
30-
with:
31-
go-version-file: ./go.mod
32-
cache: true
33-
- name: Build the module
34-
run: go build -v ./...
35-
- name: Run all tests
36-
run: go test -v ./...
25+
tests:
26+
uses: ./.github/workflows/tests.yaml
27+
3728
release-snapshot:
3829
runs-on: ubuntu-latest
39-
needs: test
30+
needs: tests
4031
if: ${{ inputs.is_snapshot_release || github.event.schedule }}
4132
steps:
4233
- name: Checkout source code
@@ -71,7 +62,7 @@ jobs:
7162
dist/*.tar.gz
7263
release:
7364
runs-on: ubuntu-latest
74-
needs: test
65+
needs: tests
7566
# Only release when there's a tag for the release.
7667
if: startsWith(github.ref, 'refs/tags/')
7768
steps:

.github/workflows/tests.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: tests
2+
3+
concurrency:
4+
group: ${{ github.ref }}
5+
cancel-in-progress: true
6+
7+
on:
8+
push:
9+
branches-ignore:
10+
- main
11+
workflow_call:
12+
13+
permissions:
14+
contents: read
15+
pull-requests: read
16+
17+
jobs:
18+
golangci-lint:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v3
22+
- name: Set up go
23+
uses: actions/setup-go@v3
24+
with:
25+
go-version-file: ./go.mod
26+
cache: false # use golangci cache instead
27+
- name: golangci-lint
28+
uses: golangci/[email protected]
29+
with:
30+
args: --timeout=10m
31+
32+
golang-tests:
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@v3
36+
- uses: actions/setup-go@v3
37+
with:
38+
go-version-file: ./go.mod
39+
cache: true
40+
- name: Build the module
41+
run: go build -v ./...
42+
- name: Run all tests
43+
run: go test -v ./...

.golangci.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
run:
2+
go: "1.19"
3+
linters:
4+
disable-all: true
5+
enable:
6+
- dupl
7+
- errorlint
8+
- errcheck
9+
- gofmt
10+
- goimports
11+
- gosimple
12+
- govet
13+
- importas
14+
- ineffassign
15+
- misspell
16+
- nilerr
17+
- reassign
18+
- staticcheck
19+
- stylecheck
20+
- typecheck
21+
- unconvert
22+
- unparam
23+
- unused
24+
- usestdlibvars
25+
- varnamelen
26+
# - wrapcheck If we're going to use github.com/pkg/errors we should probably turn this on?
27+
28+
# We'd like to have the following linter enabled, but it's broken for Go
29+
# 1.19 as of golangci-lint v1.48.0. Re-enable it when this issue is
30+
# fixed: https://github.com/golangci/golangci-lint/issues/2649
31+
# - structcheck
32+
issues:
33+
exclude:
34+
35+
linters-settings:
36+
varnamelen:
37+
max-distance: 10
38+
ignore-decls:
39+
- T any
40+
- c echo.Context
41+
- const C
42+
- e error
43+
- e watch.Event
44+
- f *foo.Bar
45+
- i int
46+
- id string
47+
- m map[string]any
48+
- m map[string]int
49+
- ns string
50+
- r *http.Request
51+
- t testing.T
52+
- w http.ResponseWriter
53+
- w io.Writer

README.md

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

33
### Instant, easy, and predictable shells and containers
44

5-
[![Join Discord](https://img.shields.io/discord/903306922852245526?color=7389D8&label=discord&logo=discord&logoColor=ffffff)](https://discord.gg/agbskCJXk2) ![License: Apache 2.0](https://img.shields.io/github/license/jetpack-io/devbox) [![version](https://img.shields.io/github/v/release/jetpack-io/devbox?color=green&label=version&sort=semver)](https://github.com/jetpack-io/devbox/releases)
5+
[![Join Discord](https://img.shields.io/discord/903306922852245526?color=7389D8&label=discord&logo=discord&logoColor=ffffff)](https://discord.gg/agbskCJXk2) ![License: Apache 2.0](https://img.shields.io/github/license/jetpack-io/devbox) [![version](https://img.shields.io/github/v/release/jetpack-io/devbox?color=green&label=version&sort=semver)](https://github.com/jetpack-io/devbox/releases) [![tests](https://github.com/jetpack-io/devbox/actions/workflows/tests.yaml/badge.svg)](https://github.com/jetpack-io/devbox/actions/workflows/tests.yaml)
66

77
---
88

boxcli/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func RootCmd() *cobra.Command {
2222
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
2323
_, err := exec.LookPath("nix-shell")
2424
if err != nil {
25-
return errors.New("Could not find nix in your PATH\nInstall nix by following the instructions at https://nixos.org/download.html and make sure you've set up your PATH correctly.")
25+
return errors.New("could not find nix in your PATH\nInstall nix by following the instructions at https://nixos.org/download.html and make sure you've set up your PATH correctly")
2626
}
2727
return nil
2828
},

cuecfg/cuecfg.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func Marshal(v any, extension string) ([]byte, error) {
2121

2222
switch extension {
2323
case ".json":
24-
return MarshalJson(v)
24+
return MarshalJSON(v)
2525
case ".yml", ".yaml":
2626
return MarshalYaml(v)
2727
}
@@ -31,7 +31,7 @@ func Marshal(v any, extension string) ([]byte, error) {
3131
func Unmarshal(data []byte, extension string, v any) error {
3232
switch extension {
3333
case ".json":
34-
err := UnmarshalJson(data, v)
34+
err := UnmarshalJSON(data, v)
3535
if err != nil {
3636
return errors.WithStack(err)
3737
}

cuecfg/json.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import "encoding/json"
88
// TODO: consider using cue's JSON marshaller instead of
99
// "encoding/json" ... it might have extra functionality related
1010
// to the cue language.
11-
func MarshalJson(v interface{}) ([]byte, error) {
11+
func MarshalJSON(v interface{}) ([]byte, error) {
1212
return json.MarshalIndent(v, "", " ")
1313
}
1414

15-
func UnmarshalJson(data []byte, v interface{}) error {
15+
func UnmarshalJSON(data []byte, v interface{}) error {
1616
return json.Unmarshal(data, v)
1717
}

generate.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ func generate(rootPath string, plan *planner.BuildPlan) error {
3636

3737
func writeFromTemplate(path string, plan *planner.BuildPlan, tmplName string) error {
3838
embeddedPath := fmt.Sprintf("tmpl/%s.tmpl", tmplName)
39-
t := template.Must(template.New(tmplName+".tmpl").Funcs(templateFuncs).ParseFS(tmplFS, embeddedPath))
4039

4140
// Should we clear the directory so we start "fresh"?
4241
outPath := filepath.Join(path, tmplName)
@@ -54,14 +53,15 @@ func writeFromTemplate(path string, plan *planner.BuildPlan, tmplName string) er
5453
return errors.WithStack(err)
5554
}
5655

56+
t := template.Must(template.New(tmplName+".tmpl").Funcs(templateFuncs).ParseFS(tmplFS, embeddedPath))
5757
return t.Execute(f, plan)
5858
}
5959

60-
func toJson(a any) string {
60+
func toJSON(a any) string {
6161
data, _ := json.Marshal(a)
6262
return string(data)
6363
}
6464

6565
var templateFuncs = template.FuncMap{
66-
"json": toJson,
66+
"json": toJSON,
6767
}

0 commit comments

Comments
 (0)