Skip to content

Commit

Permalink
build: ci, lint issues
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <[email protected]>
  • Loading branch information
caarlos0 committed May 5, 2023
1 parent 2b12158 commit 5bb4381
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 11 deletions.
38 changes: 38 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: 2
updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"
labels:
- "dependencies"
commit-message:
prefix: "feat"
include: "scope"
- package-ecosystem: "gomod"
directory: "/examples"
schedule:
interval: "daily"
labels:
- "dependencies"
commit-message:
prefix: "chore"
include: "scope"
- package-ecosystem: "gomod"
directory: "/tutorials"
schedule:
interval: "daily"
labels:
- "dependencies"
commit-message:
prefix: "chore"
include: "scope"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
labels:
- "dependencies"
commit-message:
prefix: "chore"
include: "scope"
33 changes: 33 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: build
on: [push, pull_request]

jobs:
build:
strategy:
matrix:
go-version: [~1.17, ^1]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
env:
GO111MODULE: "on"
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
cache: true

- name: Download Go modules
run: go mod download
working-directory: ./exp/teatest

- name: Build
run: go build -v ./...
working-directory: ./exp/teatest

- name: Test
run: go test -v ./...
working-directory: ./exp/teatest
27 changes: 27 additions & 0 deletions .github/workflows/lint-soft.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: lint-soft
on:
push:
pull_request:

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
pull-requests: read

jobs:
golangci:
name: lint-soft
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: stable
cache: true
- uses: golangci/golangci-lint-action@v3
with:
# Optional: golangci-lint command line arguments.
args: --config .golangci-soft.yml --issues-exit-code=0
# Optional: show only new issues if it's a pull request. The default value is `false`.
only-new-issues: true
working-directory: ./exp/teatest
27 changes: 27 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: lint
on:
push:
pull_request:

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
pull-requests: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: stable
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: golangci-lint command line arguments.
#args:
# Optional: show only new issues if it's a pull request. The default value is `false`.
only-new-issues: true
working-directory: ./exp/teatest
12 changes: 12 additions & 0 deletions .github/workflows/soft-serve.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: soft-serve

on:
push:
branches:
- master

jobs:
soft-serve:
uses: charmbracelet/meta/.github/workflows/soft-serve.yml@main
secrets:
ssh-key: "${{ secrets.CHARM_SOFT_SERVE_KEY }}"
47 changes: 47 additions & 0 deletions .golangci-soft.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
run:
tests: false

issues:
include:
- EXC0001
- EXC0005
- EXC0011
- EXC0012
- EXC0013

max-issues-per-linter: 0
max-same-issues: 0

linters:
enable:
# - dupl
- exhaustive
# - exhaustivestruct
- goconst
- godot
- godox
- gomnd
- gomoddirectives
- goprintffuncname
# - ifshort
# - lll
- misspell
- nakedret
- nestif
- noctx
- nolintlint
- prealloc
- wrapcheck

# disable default linters, they are already enabled in .golangci.yml
disable:
- deadcode
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- structcheck
- typecheck
- unused
- varcheck
29 changes: 29 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
run:
tests: false

issues:
include:
- EXC0001
- EXC0005
- EXC0011
- EXC0012
- EXC0013

max-issues-per-linter: 0
max-same-issues: 0

linters:
enable:
- bodyclose
- exportloopref
- goimports
- gosec
- nilerr
- predeclared
- revive
- rowserrcheck
- sqlclosecheck
- tparallel
- unconvert
- unparam
- whitespace
24 changes: 13 additions & 11 deletions exp/teatest/teatest.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func WaitFor(
func doWaitFor(r io.Reader, condition func(bts []byte) bool, options ...WaitForOption) error {
wf := WaitingForContext{
Duration: time.Second,
CheckInterval: 50 * time.Millisecond,
CheckInterval: 50 * time.Millisecond, //nolint: gomnd
}

for _, opt := range options {
Expand Down Expand Up @@ -227,19 +227,19 @@ func RequireEqualOutput(tb testing.TB, out []byte) {

golden := filepath.Join("testdata", tb.Name()+".golden")
if *update {
if err := os.MkdirAll(filepath.Dir(golden), 0o755); err != nil { // nolint: gomnd
if err := os.MkdirAll(filepath.Dir(golden), 0o755); err != nil { //nolint: gomnd
tb.Fatal(err)
}
if err := os.WriteFile(golden, out, 0o600); err != nil { // nolint: gomnd
if err := os.WriteFile(golden, out, 0o600); err != nil { //nolint: gomnd
tb.Fatal(err)
}
}

path := filepath.Join(tb.TempDir(), tb.Name()+".out")
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { // nolint: gomnd
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { //nolint: gomnd
tb.Fatal(err)
}
if err := os.WriteFile(path, out, 0o600); err != nil { // nolint: gomnd
if err := os.WriteFile(path, out, 0o600); err != nil { //nolint: gomnd
tb.Fatal(err)
}

Expand All @@ -257,20 +257,22 @@ func safe(rw io.ReadWriter) io.ReadWriter {
return &safeReadWriter{rw: rw}
}

// safeReadWriter implements io.ReadWriter, but locks reads and writes.
type safeReadWriter struct {
rw io.ReadWriter
m sync.Mutex
m sync.RWMutex
}

// Read implements io.ReadWriter
// Read implements io.ReadWriter.
func (s *safeReadWriter) Read(p []byte) (n int, err error) {
s.m.Lock()
defer s.m.Unlock()
return s.rw.Read(p)
s.m.RLock()
defer s.m.RUnlock()
return s.rw.Read(p) //nolint: wrapcheck
}

// Write implements io.ReadWriter.
func (s *safeReadWriter) Write(p []byte) (int, error) {
s.m.Lock()
defer s.m.Unlock()
return s.rw.Write(p)
return s.rw.Write(p) //nolint: wrapcheck
}

0 comments on commit 5bb4381

Please sign in to comment.