Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for dynamic golangci-lint matrix #1087

Merged
merged 26 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 40 additions & 3 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Golangci Lint Check
name: Golangci-Lint Check

on:
push:
Expand All @@ -20,12 +20,49 @@ on:
- ".github/dependabot.yml"

jobs:
golangci-lint:
generate-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Fetch Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- id: set-matrix
run: |
# Determine the base and head commits for diff based on the event type
BASE_SHA="${{ github.event.pull_request.base.sha || github.event.before }}"
HEAD_SHA="${{ github.event.pull_request.head.sha || github.event.after }}"

# Extract directories from changed files, only include those with go.mod files
GO_MOD_DIRECTORIES=()
FILES=$(git diff --name-only $BASE_SHA $HEAD_SHA | grep -vE '/\.')
DIRECTORIES=$(echo "$FILES" | xargs -L1 dirname | sort -u)

for dir in $DIRECTORIES; do
if [[ -f "$dir/go.mod" ]]; then
GO_MOD_DIRECTORIES+=("$dir")
fi
done

# Export the JSON array
JSON_ARRAY=$(printf '%s\n' "${GO_MOD_DIRECTORIES[@]}" | jq -R -s -c 'split("\n")[:-1]')
echo "matrix=${JSON_ARRAY}" >> $GITHUB_OUTPUT

lint:
needs: generate-matrix
runs-on: ubuntu-latest
strategy:
matrix:
modules: ${{fromJson(needs.generate-matrix.outputs.matrix)}}
steps:
- name: Fetch Repository
uses: actions/checkout@v4
- name: Run golangci-lint
uses: reviewdog/action-golangci-lint@v2
with:
golangci_lint_flags: "--tests=false"
golangci_lint_flags: "--tests=false --timeout=5m"
workdir: ${{ matrix.modules }}
fail_on_error: true
filter_mode: nofilter
3 changes: 1 addition & 2 deletions azureblob/azureblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package azureblob

import (
"context"
"errors"
"fmt"
"io"
"time"
Expand Down Expand Up @@ -108,7 +107,7 @@ func (s *Storage) Reset() error {
}
}
if errCounter > 0 {
return errors.New(fmt.Sprintf("%d errors occured while resetting", errCounter))
return fmt.Errorf("%d errors occured while resetting", errCounter)
}
return nil
}
Expand Down
16 changes: 6 additions & 10 deletions mongodb/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,14 @@ func New(config ...Config) *Storage {
}

// Set mongo options
opt := options.Client()
opt.ApplyURI(dsn)
opt := options.Client().ApplyURI(dsn)

// Create mongo client
client, err := mongo.NewClient(opt)
if err != nil {
panic(err)
}

ctx, cancel := context.WithTimeout(context.TODO(), 20*time.Second)
// Create and connect the mongo client in one step
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
if err = client.Connect(ctx); err != nil {

client, err := mongo.Connect(ctx, opt)
if err != nil {
panic(err)
}

Expand Down
3 changes: 0 additions & 3 deletions mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ func New(config ...Config) *Storage {
return store
}

var noRows = "sql: no rows in result set"

// Get value by key
func (s *Storage) Get(key string) ([]byte, error) {
if len(key) <= 0 {
Expand Down Expand Up @@ -136,7 +134,6 @@ func (s *Storage) Get(key string) ([]byte, error) {
return data, nil
}

// Set key with value
// Set key with value
func (s *Storage) Set(key string, val []byte, exp time.Duration) error {
// Ain't Nobody Got Time For That
Expand Down
9 changes: 2 additions & 7 deletions pebble/pebble.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,6 @@ func isValid(fp string) bool {
return false
}

err = os.Remove(fp) // And delete it

if err != nil {
return false
}

return true
err = os.Remove(fp)
return err == nil
}
2 changes: 0 additions & 2 deletions sqlite3/sqlite3.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ type Storage struct {
}

var (
checkSchemaMsg = "The `v` row has an incorrect data type. " +
"It should be BLOB but is instead %s. This will cause encoding-related panics if the DB is not migrated (see https://github.com/gofiber/storage/blob/main/MIGRATE.md)."
dropQuery = `DROP TABLE IF EXISTS %s;`
initQuery = []string{
`CREATE TABLE IF NOT EXISTS %s (
Expand Down
Loading