Skip to content

Commit

Permalink
feat(dagger): Move dagger inside the .github folder, needs fix for .g…
Browse files Browse the repository at this point in the history
…olangci.yaml.
  • Loading branch information
jochumdev committed Sep 5, 2024
1 parent 66296af commit fd8f68a
Show file tree
Hide file tree
Showing 9 changed files with 268 additions and 9 deletions.
File renamed without changes.
File renamed without changes.
258 changes: 258 additions & 0 deletions .github/.golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
# This file contains all available configuration options
# with their default values.

# options for analysis running
run:
# go: '1.18'
# default concurrency is a available CPU number
# concurrency: 4

# timeout for analysis, e.g. 30s, 5m, default is 1m
deadline: 10m

# exit code when at least one issue was found, default is 1
issues-exit-code: 1

# include test files or not, default is true
tests: true

# which files to skip: they will be analyzed, but issues from them
# won't be reported. Default value is empty list, but there is
# no need to include all autogenerated files, we confidently recognize
# autogenerated files. If it's not please let us know.
skip-files:
[]
# - .*\\.pb\\.go$

allow-parallel-runners: true

# list of build tags, all linters use it. Default is empty list.
build-tags: []

# output configuration options
output:
# Format: colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions
#
# Multiple can be specified by separating them by comma, output can be provided
# for each of them by separating format name and path by colon symbol.
# Output path can be either `stdout`, `stderr` or path to the file to write to.
# Example: "checkstyle:report.json,colored-line-number"
#
# Default: colored-line-number
formats:
- format: colored-line-number
# Print lines of code with issue.
# Default: true
print-issued-lines: true
# Print linter name in the end of issue text.
# Default: true
print-linter-name: true
# Make issues output unique by line.
# Default: true
uniq-by-line: true
# Add a prefix to the output file references.
# Default is no prefix.
path-prefix: ""
# Sort results by: filepath, line and column.
sort-results: true

# all available settings of specific linters
linters-settings:
wsl:
allow-cuddle-with-calls: [Lock, RLock, defer]
funlen:
lines: 80
statements: 60
varnamelen:
# The longest distance, in source lines, that is being considered a "small scope".
# Variables used in at most this many lines will be ignored.
# Default: 5
max-distance: 26
ignore-names:
- err
- id
- ch
- wg
- mu
ignore-decls:
- c echo.Context
- t testing.T
- f *foo.Bar
- e error
- i int
- const C
- T any
- m map[string]int
errcheck:
# report about not checking of errors in type assetions: `a := b.(MyStruct)`;
# default is false: such cases aren't reported by default.
check-type-assertions: true

# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
# default is false: such cases aren't reported by default.
check-blank: true
govet:
# report about shadowed variables
check-shadowing: false
gofmt:
# simplify code: gofmt with `-s` option, true by default
simplify: true
gocyclo:
# minimal code complexity to report, 30 by default (but we recommend 10-20)
min-complexity: 15
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true
dupl:
# tokens count to trigger issue, 150 by default
threshold: 100
goconst:
# minimal length of string constant, 3 by default
min-len: 3
# minimal occurrences count to trigger, 3 by default
min-occurrences: 3
depguard:
list-type: blacklist
# Packages listed here will reported as error if imported
packages:
- github.com/golang/protobuf/proto
misspell:
# Correct spellings using locale preferences for US or UK.
# Default is to use a neutral variety of English.
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
locale: US
lll:
# max line length, lines longer will be reported. Default is 120.
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
line-length: 140
# tab width in spaces. Default to 1.
tab-width: 1
unused:
# treat code as a program (not a library) and report unused exported identifiers; default is false.
# XXX: if you enable this setting, unused will report a lot of false-positives in text editors:
# if it's called for subdir of a project it can't find funcs usages. All text editor integrations
# with golangci-lint call it on a directory with the changed file.
check-exported: false
unparam:
# call graph construction algorithm (cha, rta). In general, use cha for libraries,
# and rta for programs with main packages. Default is cha.
algo: cha

# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
# with golangci-lint call it on a directory with the changed file.
check-exported: false
nakedret:
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30
max-func-lines: 60
nolintlint:
allow-unused: false
allow-leading-space: false
allow-no-explanation: []
require-explanation: false
require-specific: true
prealloc:
# XXX: we don't recommend using this linter before doing performance profiling.
# For most programs usage of prealloc will be a premature optimization.

# Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them.
# True by default.
simple: true
range-loops: true # Report preallocation suggestions on range loops, true by default
for-loops: false # Report preallocation suggestions on for loops, false by default
cyclop:
# the maximal code complexity to report
max-complexity: 20
gomoddirectives:
replace-local: true
retract-allow-no-explanation: false
exclude-forbidden: true

linters:
enable-all: true
disable-all: false
fast: false
disable:
- testpackage
- promlinter
- nonamedreturns
- makezero
- gofumpt
- nlreturn
- gci

# Can be considered to be enabled
- gochecknoinits
# - gochecknoglobals # RIP
- dogsled
- wrapcheck
- paralleltest
- ireturn
- gomnd
- err113
- exhaustruct
- containedctx
- godox
- forcetypeassert

- rowserrcheck # generics
- sqlclosecheck # generics
- wastedassign # generics

# Not configured yet
- depguard

- execinquery
- copyloopvar # go 1.22
- intrange # go 1.22

# Magic number
- mnd

# Deprecated
- exportloopref

issues:
# List of regexps of issue texts to exclude, empty list by default.
# But independently from this option we use default exclude patterns,
# it can be disabled by `exclude-use-default: false`. To list all
# excluded by default patterns execute `golangci-lint run --help`
# exclude:
# - package comment should be of the form "Package services ..." # revive
# - ^ST1000 # ST1000: at least one file in a package should have a package comment (stylecheck)

# exclude-rules:
# - path: internal/app/machined/pkg/system/services
# linters:
# - dupl
exclude-rules:
- path: _test\.go
linters:
- gocyclo
- dupl
- gosec
- funlen
- varnamelen
- wsl
- gochecknoglobals

# Independently from option `exclude` we use default exclude patterns,
# it can be disabled by this option. To list all
# excluded by default patterns execute `golangci-lint run --help`.
# Default value for this option is true.
exclude-use-default: false

# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-issues-per-linter: 0

# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0

# Show only new issues: if there are unstaged changes or untracked files,
# only those changes are analyzed, else only changes in HEAD~ are analyzed.
# It's a super-useful option for integration of golangci-lint into existing
# large codebase. It's not practical to fix all existing issues at the moment
# of integration: much better don't allow issues in new code.
# Default is false.
new: false
File renamed without changes.
File renamed without changes.
8 changes: 6 additions & 2 deletions dagger/main.go → .github/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ func (m *GoOrb) Modules(ctx context.Context, root *dagger.Directory) ([]string,
}

for i, mod := range mods {
if strings.HasPrefix(mod, "dagger") {
// Ignore dagger
if strings.HasPrefix(mod, ".github") {
mods[i] = ""
continue
}
Expand All @@ -120,6 +121,8 @@ func (m *GoOrb) Lint(ctx context.Context, root *dagger.Directory) (*AllResult, e
default:
}

config := dag.CurrentModule().Source().File(".golangci.yaml")

out, err := dag.Container().From("golangci/golangci-lint").
WithMountedCache("/go/pkg/mod",
dag.CacheVolume("go-mod"),
Expand All @@ -138,7 +141,8 @@ func (m *GoOrb) Lint(ctx context.Context, root *dagger.Directory) (*AllResult, e
WithMountedCache("/root/.cache/golangci-lint", dag.CacheVolume("golangci-lint")).
WithDirectory("/work/src", root.Directory(dir)).
WithWorkdir("/work/src").
WithExec([]string{"golangci-lint", "run"}).
WithMountedFile("/work/config", config).
WithExec([]string{"golangci-lint", "run", "--config", "/work/config"}).
Stdout(ctx)

res <- &WorkerResult{Module: dir, Logs: out, Err: err}
Expand Down
2 changes: 1 addition & 1 deletion client/tests/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ type TestSuite struct {
}

// NewSuite creates a new test suite.
func NewSuite(pluginsRoot string, transports []string, requests ...TestRequest) *TestSuite {
func NewSuite(_ string, transports []string, requests ...TestRequest) *TestSuite {
s := new(TestSuite)

s.Transports = transports
Expand Down
4 changes: 2 additions & 2 deletions dagger.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "go-orb",
"sdk": "go",
"source": "dagger",
"engineVersion": "v0.12.6"
"source": ".github",
"engineVersion": "v0.12.7"
}
5 changes: 1 addition & 4 deletions server/http/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,4 @@ require (
golang.org/x/text v0.17.0 // indirect
golang.org/x/tools v0.24.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
)

// Fixing ambiguous import: found package google.golang.org/genproto/googleapis/api/annotations in multiple modules.
exclude google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1
)

0 comments on commit fd8f68a

Please sign in to comment.