Skip to content

Commit

Permalink
Merge pull request #272 from diofeher/feat/backend-linting
Browse files Browse the repository at this point in the history
feat: add backend linting on github actions
  • Loading branch information
Yantrio authored Jan 7, 2025
2 parents 9be4529 + 135643a commit 76b3477
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 8 deletions.
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,9 @@ Manages projects.
}
t.Run(tt.name, func(t *testing.T) {
doc := &docItem{}
s.ExtractFrontmatterPermissively(context.Background(), []byte(tt.input), doc)
if err := s.ExtractFrontmatterPermissively(context.Background(), []byte(tt.input), doc); err != nil {
t.Errorf("Failed to extract frontmatter: (%v)", err)
}

if doc.Name != tt.expected.Name {
t.Errorf("expected %q, got %q", tt.expected.Name, doc.Name)
Expand Down
8 changes: 4 additions & 4 deletions backend/internal/providerindex/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (p providerSearch) indexProviderVersion(ctx context.Context, providerAddr p
popularity = providerDetails.UpstreamPopularity
}
providerItem := searchtypes.IndexItem{
ID: searchtypes.IndexID("providers/" + providerAddr.String()),
ID: searchtypes.IndexID(indexPrefix + "/" + providerAddr.String()),
Type: searchtypes.IndexTypeProvider,
Addr: providerAddr.String(),
Version: string(version),
Expand Down Expand Up @@ -69,7 +69,7 @@ func (p providerSearch) indexProviderVersion(ctx context.Context, providerAddr p
for _, docItem := range item.items {
title := docItem.Title
if err := p.searchAPI.AddItem(ctx, searchtypes.IndexItem{
ID: searchtypes.IndexID("providers/" + providerAddr.String() + "/" + item.typeName + "s/" + string(docItem.Name)),
ID: searchtypes.IndexID(indexPrefix + "/" + providerAddr.String() + "/" + item.typeName + "s/" + string(docItem.Name)),
Type: item.indexType,
Addr: providerAddr.String(),
Version: string(version),
Expand All @@ -92,7 +92,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 +105,6 @@ func (p providerSearch) removeProviderVersionFromSearchIndex(ctx context.Context
return nil
}

func (p providerSearch) removeModuleFromSearchIndex(ctx context.Context, addr module.Addr) error {
func (p providerSearch) removeModuleFromSearchIndex(ctx context.Context, addr module.Addr) error { //nolint:unused
return p.searchAPI.RemoveItem(ctx, searchtypes.IndexID(indexPrefix+"/"+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

0 comments on commit 76b3477

Please sign in to comment.