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

feat: add backend linting on github actions #272

Merged
merged 13 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
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
20 changes: 20 additions & 0 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,23 @@ jobs:
working-directory: frontend
run:
npm run test
backend-lint:
name: Backend Lint
runs-on: ubuntu-latest
strategy:
matrix:
modules:
- backend
- search/pg-indexer
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v5
with:
go-version-file: 'backend/go.mod'
- name: Backend Linting
uses: golangci/golangci-lint-action@v6
with:
version: v1.62
working-directory: ${{ matrix.modules }}
2 changes: 1 addition & 1 deletion backend/internal/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (f ForceRegenerateEntry) MustRegenerateProvider(_ context.Context, addr pro
})
}

func (g GenerateConfig) validate() error {
func (g GenerateConfig) validate() error { //nolint:unused
if g.Name != "" && g.Namespace == "" {
return fmt.Errorf("cannot use name filtering without namespace filtering")
}
Expand Down
1 change: 1 addition & 0 deletions backend/internal/blocklist/blocklist.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (b *blockListType[T]) UnmarshalJSON(data []byte) error {
func (b *blockList) LoadFile(file string) error {
blockListContents, err := os.ReadFile(file)
if err != nil {
return err
}

if err := json.Unmarshal(blockListContents, &b); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion backend/internal/indexstorage/bufferedstorage/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (l *localIndex) Close() error {
}

func (l *localIndex) trySave(ctx context.Context) error {
if time.Now().Sub(l.lastCommitted) < 30*time.Second {
if time.Since(l.lastCommitted) < 30*time.Second {
return nil
}

Expand Down
3 changes: 3 additions & 0 deletions backend/internal/providerindex/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ func (d *documentationGenerator) Generate(ctx context.Context, opts ...Opts) err
func (d *documentationGenerator) GenerateNamespace(ctx context.Context, namespace string, opts ...Opts) error {
d.log.Info(ctx, "Listing all providers in namespace %s...", namespace)
providerList, err := d.metadataAPI.ListProvidersByNamespace(ctx, namespace, true)
if err != nil {
return err
}

d.log.Info(ctx, "Loaded %d providers", len(providerList))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Manages projects.
}
t.Run(tt.name, func(t *testing.T) {
doc := &docItem{}
s.ExtractFrontmatterPermissively(context.Background(), []byte(tt.input), doc)
s.ExtractFrontmatterPermissively(context.Background(), []byte(tt.input), doc) //nolint:all

if doc.Name != tt.expected.Name {
t.Errorf("expected %q, got %q", tt.expected.Name, doc.Name)
Expand Down
8 changes: 3 additions & 5 deletions backend/internal/providerindex/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"github.com/opentofu/registry-ui/internal/search/searchtypes"
)

const indexPrefix = "providers"

type providerSearch struct {
searchAPI search.API
}
Expand Down Expand Up @@ -92,7 +90,7 @@ func (p providerSearch) indexProviderVersion(ctx context.Context, providerAddr p
return nil
}

func (p providerSearch) removeProviderVersionFromSearchIndex(ctx context.Context, addr provider.Addr, version provider.VersionNumber) error {
func (p providerSearch) removeProviderVersionFromSearchIndex(ctx context.Context, addr provider.Addr, version provider.VersionNumber) error { //nolint:unused
for _, t := range []searchtypes.IndexType{
searchtypes.IndexTypeProvider,
searchtypes.IndexTypeProviderResource,
Expand All @@ -105,6 +103,6 @@ func (p providerSearch) removeProviderVersionFromSearchIndex(ctx context.Context
return nil
}

func (p providerSearch) removeModuleFromSearchIndex(ctx context.Context, addr module.Addr) error {
return p.searchAPI.RemoveItem(ctx, searchtypes.IndexID(indexPrefix+"/"+addr.String()))
func (p providerSearch) removeModuleFromSearchIndex(ctx context.Context, addr module.Addr) error { //nolint:unused
return p.searchAPI.RemoveItem(ctx, searchtypes.IndexID("providers/"+addr.String()))
}
2 changes: 1 addition & 1 deletion backend/internal/registrycloner/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (c cloner) cloneGitRepo(ctx context.Context) error {
}

// FetchTags fetches the tags for the repository in the specified directory.
func (c cloner) fetchTags(ctx context.Context) error {
func (c cloner) fetchTags(ctx context.Context) error { //nolint:unused
return c.runGitCommand(ctx, []string{"git", "fetch", "--tags", "--force"}, c.cfg.Directory)
}

Expand Down