From f3d126c17c029e40d47af261d928cbee4b490077 Mon Sep 17 00:00:00 2001 From: Diogenes Fernandes Date: Fri, 3 Jan 2025 09:25:34 -0300 Subject: [PATCH 01/13] backend linting Signed-off-by: Diogenes Fernandes --- .github/workflows/verify.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index abc9816..a2070f0 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -14,6 +14,10 @@ jobs: uses: actions/setup-go@v5 with: go-version-file: 'backend/go.mod' + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.60.0 - name: Cache tofu binary uses: actions/cache@v4 with: From 92c835764eb342663dc9f34a51efaff1d48d939b Mon Sep 17 00:00:00 2001 From: Diogenes Fernandes Date: Fri, 3 Jan 2025 09:34:28 -0300 Subject: [PATCH 02/13] test lint Signed-off-by: Diogenes Fernandes --- .github/workflows/verify.yml | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index a2070f0..a280803 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -2,6 +2,8 @@ name: Verify permissions: {} on: pull_request: + branches: + - feat/backend-lint jobs: generate: @@ -14,10 +16,6 @@ jobs: uses: actions/setup-go@v5 with: go-version-file: 'backend/go.mod' - - name: golangci-lint - uses: golangci/golangci-lint-action@v6 - with: - version: v1.60.0 - name: Cache tofu binary uses: actions/cache@v4 with: @@ -77,3 +75,18 @@ jobs: working-directory: frontend run: npm run test + backend-lint: + name: Backend Lint + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup go + uses: actions/setup-go@v5 + with: + go-version-file: 'backend/go.mod' + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + working-directory: backend + with: + version: v1.60 From 6d11405c9875aca1a305c19b836e25217da93a57 Mon Sep 17 00:00:00 2001 From: Diogenes Fernandes Date: Fri, 3 Jan 2025 09:38:02 -0300 Subject: [PATCH 03/13] on push branches Signed-off-by: Diogenes Fernandes --- .github/workflows/verify.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index a280803..1c3aa25 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -2,7 +2,8 @@ name: Verify permissions: {} on: pull_request: - branches: + push: + branches: - feat/backend-lint jobs: From a782b2e505dddbb7cc5ed9d1e1b2aab8ed5c4a73 Mon Sep 17 00:00:00 2001 From: Diogenes Fernandes Date: Fri, 3 Jan 2025 09:40:03 -0300 Subject: [PATCH 04/13] passing folder Signed-off-by: Diogenes Fernandes --- .github/workflows/verify.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index 1c3aa25..473f55a 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -88,6 +88,6 @@ jobs: go-version-file: 'backend/go.mod' - name: golangci-lint uses: golangci/golangci-lint-action@v6 - working-directory: backend with: version: v1.60 + args: /backend From 93352722773e689ed6f5041980ef1ed8f03bb680 Mon Sep 17 00:00:00 2001 From: Diogenes Fernandes Date: Fri, 3 Jan 2025 09:40:42 -0300 Subject: [PATCH 05/13] on search too Signed-off-by: Diogenes Fernandes --- .github/workflows/verify.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index 473f55a..b91d542 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -90,4 +90,4 @@ jobs: uses: golangci/golangci-lint-action@v6 with: version: v1.60 - args: /backend + args: ./backend ./search From ca6657dfdb9dc10d5602ce28806675a57b4b609f Mon Sep 17 00:00:00 2001 From: Diogenes Fernandes Date: Fri, 3 Jan 2025 09:42:45 -0300 Subject: [PATCH 06/13] identation Signed-off-by: Diogenes Fernandes --- .github/workflows/verify.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index b91d542..c335fe3 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -90,4 +90,4 @@ jobs: uses: golangci/golangci-lint-action@v6 with: version: v1.60 - args: ./backend ./search + args: ./backend ./search From 601561810ed1778c67ab6db635a7a7dcf89f3b8a Mon Sep 17 00:00:00 2001 From: Diogenes Fernandes Date: Fri, 3 Jan 2025 09:44:16 -0300 Subject: [PATCH 07/13] folders Signed-off-by: Diogenes Fernandes --- .github/workflows/verify.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index c335fe3..fce6866 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -90,4 +90,4 @@ jobs: uses: golangci/golangci-lint-action@v6 with: version: v1.60 - args: ./backend ./search + args: ./... ./backend ./search From bef12a05cc78e86e4fc968dbcd51811e9a750cc4 Mon Sep 17 00:00:00 2001 From: Diogenes Fernandes Date: Fri, 3 Jan 2025 09:50:32 -0300 Subject: [PATCH 08/13] backend and search as matrix modules Signed-off-by: Diogenes Fernandes --- .github/workflows/verify.yml | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index fce6866..782016f 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -48,10 +48,10 @@ jobs: - name: Run go generate working-directory: backend run: go generate ./... - - name: Run tests - working-directory: backend - run: | - go test ./... + # - name: Run tests + # working-directory: backend + # run: | + # go test ./... frontend: name: Frontend Lint and Test runs-on: ubuntu-latest @@ -79,6 +79,11 @@ jobs: backend-lint: name: Backend Lint runs-on: ubuntu-latest + strategy: + matrix: + modules: + - backend + - search steps: - name: Checkout uses: actions/checkout@v4 @@ -86,8 +91,8 @@ jobs: uses: actions/setup-go@v5 with: go-version-file: 'backend/go.mod' - - name: golangci-lint + - name: Backend Linting uses: golangci/golangci-lint-action@v6 with: - version: v1.60 - args: ./... ./backend ./search + version: v1.62 + working-directory: ${{ matrix.modules }} From 5c8227c9aeb80ee68d4ba69710c287f419b95438 Mon Sep 17 00:00:00 2001 From: Diogenes Fernandes Date: Fri, 3 Jan 2025 09:52:02 -0300 Subject: [PATCH 09/13] pg-indexer Signed-off-by: Diogenes Fernandes --- .github/workflows/verify.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index 782016f..b417eae 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -83,7 +83,7 @@ jobs: matrix: modules: - backend - - search + - search/pg-indexer steps: - name: Checkout uses: actions/checkout@v4 From 36caca94c089e1574dfc0d6fa37fc84dd6c11a7a Mon Sep 17 00:00:00 2001 From: Diogenes Fernandes Date: Sat, 4 Jan 2025 00:52:10 -0300 Subject: [PATCH 10/13] unused Signed-off-by: Diogenes Fernandes --- backend/internal/blocklist/blocklist.go | 1 + backend/internal/providerindex/generator.go | 3 +++ .../internal/providerindex/providerdocsource/scrape_test.go | 2 +- backend/internal/providerindex/search.go | 2 +- backend/internal/registrycloner/git.go | 2 +- 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/internal/blocklist/blocklist.go b/backend/internal/blocklist/blocklist.go index 362cd4c..2c3f860 100644 --- a/backend/internal/blocklist/blocklist.go +++ b/backend/internal/blocklist/blocklist.go @@ -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 { diff --git a/backend/internal/providerindex/generator.go b/backend/internal/providerindex/generator.go index ab7fb15..802540c 100644 --- a/backend/internal/providerindex/generator.go +++ b/backend/internal/providerindex/generator.go @@ -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)) diff --git a/backend/internal/providerindex/providerdocsource/scrape_test.go b/backend/internal/providerindex/providerdocsource/scrape_test.go index 5a96efa..90305b9 100644 --- a/backend/internal/providerindex/providerdocsource/scrape_test.go +++ b/backend/internal/providerindex/providerdocsource/scrape_test.go @@ -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) diff --git a/backend/internal/providerindex/search.go b/backend/internal/providerindex/search.go index 9f7a1b6..c3d7158 100644 --- a/backend/internal/providerindex/search.go +++ b/backend/internal/providerindex/search.go @@ -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())) } diff --git a/backend/internal/registrycloner/git.go b/backend/internal/registrycloner/git.go index 1f9408a..2567add 100644 --- a/backend/internal/registrycloner/git.go +++ b/backend/internal/registrycloner/git.go @@ -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) } From b2a9e4af70276f505670dc04daf69e6f911245cb Mon Sep 17 00:00:00 2001 From: Diogenes Fernandes Date: Sat, 4 Jan 2025 00:57:30 -0300 Subject: [PATCH 11/13] no lint Signed-off-by: Diogenes Fernandes --- backend/internal/backend.go | 2 +- backend/internal/indexstorage/bufferedstorage/index.go | 2 +- backend/internal/providerindex/search.go | 6 ++---- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/backend/internal/backend.go b/backend/internal/backend.go index c3887ad..ec8464f 100644 --- a/backend/internal/backend.go +++ b/backend/internal/backend.go @@ -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") } diff --git a/backend/internal/indexstorage/bufferedstorage/index.go b/backend/internal/indexstorage/bufferedstorage/index.go index 2c76eb7..d47f570 100644 --- a/backend/internal/indexstorage/bufferedstorage/index.go +++ b/backend/internal/indexstorage/bufferedstorage/index.go @@ -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 } diff --git a/backend/internal/providerindex/search.go b/backend/internal/providerindex/search.go index c3d7158..9edd647 100644 --- a/backend/internal/providerindex/search.go +++ b/backend/internal/providerindex/search.go @@ -11,8 +11,6 @@ import ( "github.com/opentofu/registry-ui/internal/search/searchtypes" ) -const indexPrefix = "providers" - type providerSearch struct { searchAPI search.API } @@ -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, @@ -106,5 +104,5 @@ func (p providerSearch) removeProviderVersionFromSearchIndex(ctx context.Context } func (p providerSearch) removeModuleFromSearchIndex(ctx context.Context, addr module.Addr) error { //nolint:unused - return p.searchAPI.RemoveItem(ctx, searchtypes.IndexID(indexPrefix+"/"+addr.String())) + return p.searchAPI.RemoveItem(ctx, searchtypes.IndexID("providers/"+addr.String())) } From 67a731c25a384d9387b3d3503f9eb1f88065d4bb Mon Sep 17 00:00:00 2001 From: Diogenes Fernandes Date: Sat, 4 Jan 2025 01:00:43 -0300 Subject: [PATCH 12/13] cleanup Signed-off-by: Diogenes Fernandes --- .github/workflows/verify.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index b417eae..cacba2d 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -2,9 +2,6 @@ name: Verify permissions: {} on: pull_request: - push: - branches: - - feat/backend-lint jobs: generate: @@ -48,10 +45,10 @@ jobs: - name: Run go generate working-directory: backend run: go generate ./... - # - name: Run tests - # working-directory: backend - # run: | - # go test ./... + - name: Run tests + working-directory: backend + run: | + go test ./... frontend: name: Frontend Lint and Test runs-on: ubuntu-latest From 135643a54e0513a10cbb0158ce4feaebb4b8b33a Mon Sep 17 00:00:00 2001 From: Diogenes Fernandes Date: Sun, 5 Jan 2025 09:23:01 -0300 Subject: [PATCH 13/13] addressing abstractionFactory comments Signed-off-by: Diogenes Fernandes --- .../providerindex/providerdocsource/scrape_test.go | 4 +++- backend/internal/providerindex/search.go | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/backend/internal/providerindex/providerdocsource/scrape_test.go b/backend/internal/providerindex/providerdocsource/scrape_test.go index 90305b9..df989ec 100644 --- a/backend/internal/providerindex/providerdocsource/scrape_test.go +++ b/backend/internal/providerindex/providerdocsource/scrape_test.go @@ -148,7 +148,9 @@ Manages projects. } t.Run(tt.name, func(t *testing.T) { doc := &docItem{} - s.ExtractFrontmatterPermissively(context.Background(), []byte(tt.input), doc) //nolint:all + 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) diff --git a/backend/internal/providerindex/search.go b/backend/internal/providerindex/search.go index 9edd647..f0b11a3 100644 --- a/backend/internal/providerindex/search.go +++ b/backend/internal/providerindex/search.go @@ -11,6 +11,8 @@ import ( "github.com/opentofu/registry-ui/internal/search/searchtypes" ) +const indexPrefix = "providers" + type providerSearch struct { searchAPI search.API } @@ -23,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), @@ -67,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), @@ -104,5 +106,5 @@ func (p providerSearch) removeProviderVersionFromSearchIndex(ctx context.Context } func (p providerSearch) removeModuleFromSearchIndex(ctx context.Context, addr module.Addr) error { //nolint:unused - return p.searchAPI.RemoveItem(ctx, searchtypes.IndexID("providers/"+addr.String())) + return p.searchAPI.RemoveItem(ctx, searchtypes.IndexID(indexPrefix+"/"+addr.String())) }