diff --git a/.github/workflows/add-copyright-headers.yml b/.github/workflows/add-copyright-headers.yml deleted file mode 100644 index 536ecb6f2..000000000 --- a/.github/workflows/add-copyright-headers.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: "Add Copyright Headers" - -on: - pull_request_target: - types: - - opened - - reopened - - synchronize - - ready_for_review - workflow_dispatch: {} - -jobs: - add-copyright-headers: - runs-on: ubuntu-latest - env: - HEAD_REF: ${{ github.event.pull_request.head.ref }} - permissions: - contents: write - steps: - - name: Checkout - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - with: - ref: ${{ github.event.pull_request.head.ref }} - repository: ${{ github.event.pull_request.head.repo.full_name }} - - name: Set git identity - run: |- - git config user.name "hashicorp-copywrite[bot]" - git config user.email "110428419+hashicorp-copywrite[bot]@users.noreply.github.com" - - name: Setup Copywrite tool - uses: hashicorp/setup-copywrite@32638da2d4e81d56a0764aa1547882fc4d209636 # v1.1.3 - - name: Add headers using Copywrite tool - run: copywrite headers - - name: Check if there are any changes - id: get_changes - run: echo "changed=$(git status --porcelain | wc -l)" >> $GITHUB_OUTPUT - - name: Push changes - if: steps.get_changes.outputs.changed != 0 - run: |- - git add . - git commit -s -m "[COMPLIANCE] Add required copyright headers" - git push origin HEAD:$HEAD_REF diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index 4ee7c4513..227e99e19 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -25,6 +25,7 @@ jobs: build: runs-on: ubuntu-latest + needs: [generate-provider-schemas] strategy: matrix: include: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cff58d91e..085590f3e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,6 +28,7 @@ jobs: build: runs-on: ubuntu-latest + needs: [generate-provider-schemas] strategy: matrix: include: diff --git a/.github/workflows/check-changelog.yml b/.github/workflows/check-changelog.yml deleted file mode 100644 index a108af916..000000000 --- a/.github/workflows/check-changelog.yml +++ /dev/null @@ -1,36 +0,0 @@ -# Checks if a file has been committed under the .changes/unreleased directory -# -# Skip PRs labeled with 'dependencies' - -on: - pull_request: - branches: - - main - - pre-release - -name: Check if changelog entry exists - -jobs: - changelog_existence: - name: Check if changelog entry exists - if: "!contains(github.event.pull_request.labels.*.name, 'dependencies')" - runs-on: ubuntu-latest - - steps: - - name: Check if changelog file was added - # https://github.com/marketplace/actions/paths-changes-filter - # For each filter, it sets output variable named by the filter to the text: - # 'true' - if any of changed files matches any of filter rules - # 'false' - if none of changed files matches any of filter rules - uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 - id: changelog_check - with: - filters: | - exists: - - '.changes/unreleased/**.yaml' - - - name: Fail job if changelog entry is missing and required - if: steps.changelog_check.outputs.exists == 'false' - uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 - with: - script: core.setFailed('Changelog entry required to merge.') diff --git a/internal/features/modules/hooks/hooks.go b/internal/features/modules/hooks/hooks.go index 6584d2449..42a6e2cf2 100644 --- a/internal/features/modules/hooks/hooks.go +++ b/internal/features/modules/hooks/hooks.go @@ -9,7 +9,6 @@ package hooks import ( "log" - "github.com/algolia/algoliasearch-client-go/v3/algolia/search" "github.com/hashicorp/terraform-ls/internal/features/modules/state" "github.com/hashicorp/terraform-ls/internal/registry" ) @@ -17,6 +16,5 @@ import ( type Hooks struct { ModStore *state.ModuleStore RegistryClient registry.Client - AlgoliaClient *search.Client Logger *log.Logger } diff --git a/internal/features/modules/hooks/module_source_registry.go b/internal/features/modules/hooks/module_source_registry.go index bd39b9aee..c1fb049d1 100644 --- a/internal/features/modules/hooks/module_source_registry.go +++ b/internal/features/modules/hooks/module_source_registry.go @@ -5,12 +5,9 @@ package hooks import ( "context" - "strings" - - "github.com/algolia/algoliasearch-client-go/v3/algolia/opt" "github.com/hashicorp/hcl-lang/decoder" - "github.com/hashicorp/hcl-lang/lang" "github.com/zclconf/go-cty/cty" + "strings" ) type RegistryModule struct { @@ -18,32 +15,6 @@ type RegistryModule struct { Description string `json:"description"` } -const algoliaModuleIndex = "tf-registry:prod:modules" - -func (h *Hooks) fetchModulesFromAlgolia(ctx context.Context, term string) ([]RegistryModule, error) { - modules := make([]RegistryModule, 0) - - index := h.AlgoliaClient.InitIndex(algoliaModuleIndex) - params := []interface{}{ - ctx, // transport.Request will magically extract the context from here - opt.AttributesToRetrieve("full-name", "description"), - opt.HitsPerPage(10), - } - - res, err := index.Search(term, params...) - if err != nil { - return modules, err - } - - err = res.UnmarshalHits(&modules) - if err != nil { - return modules, err - - } - - return modules, nil -} - func (h *Hooks) RegistryModuleSources(ctx context.Context, value cty.Value) ([]decoder.Candidate, error) { candidates := make([]decoder.Candidate, 0) prefix := value.AsString() @@ -54,24 +25,7 @@ func (h *Hooks) RegistryModuleSources(ctx context.Context, value cty.Value) ([]d return candidates, nil } - if h.AlgoliaClient == nil { - return candidates, nil - } - - modules, err := h.fetchModulesFromAlgolia(ctx, prefix) - if err != nil { - h.Logger.Printf("Error fetching modules from Algolia: %#v", err) - return candidates, err - } - - for _, mod := range modules { - c := decoder.ExpressionCompletionCandidate(decoder.ExpressionCandidate{ - Value: cty.StringVal(mod.FullName), - Detail: "registry", - Description: lang.PlainText(mod.Description), - }) - candidates = append(candidates, c) - } + //TODO: figure out how we can do module autocompletion return candidates, nil } diff --git a/internal/features/modules/hooks/module_source_registry_test.go b/internal/features/modules/hooks/module_source_registry_test.go index d5e5bf4db..be9cac685 100644 --- a/internal/features/modules/hooks/module_source_registry_test.go +++ b/internal/features/modules/hooks/module_source_registry_test.go @@ -91,28 +91,9 @@ func TestHooks_RegistryModuleSources(t *testing.T) { t.Fatal(err) } - searchClient := buildSearchClientMock(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.RequestURI == "/1/indexes/tf-registry%3Aprod%3Amodules/query" { - b, _ := io.ReadAll(r.Body) - - if strings.Contains(string(b), "query=aws") { - w.Write([]byte(responseAWS)) - return - } else if strings.Contains(string(b), "query=err") { - http.Error(w, responseErr, http.StatusForbidden) - return - } - - w.Write([]byte(responseEmpty)) - return - } - http.Error(w, fmt.Sprintf("unexpected request: %q", r.RequestURI), 400) - })) - h := &Hooks{ - ModStore: store, - AlgoliaClient: searchClient, - Logger: log.New(io.Discard, "", 0), + ModStore: store, + Logger: log.New(io.Discard, "", 0), } tests := []struct { @@ -186,15 +167,9 @@ func TestHooks_RegistryModuleSourcesCtxCancel(t *testing.T) { t.Fatal(err) } - searchClient := buildSearchClientMock(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - time.Sleep(500 * time.Millisecond) - http.Error(w, fmt.Sprintf("unexpected request: %q", r.RequestURI), 400) - })) - h := &Hooks{ - ModStore: store, - AlgoliaClient: searchClient, - Logger: log.New(io.Discard, "", 0), + ModStore: store, + Logger: log.New(io.Discard, "", 0), } _, err = h.RegistryModuleSources(ctx, cty.StringVal("aws")) @@ -220,14 +195,9 @@ func TestHooks_RegistryModuleSourcesIgnore(t *testing.T) { t.Fatal(err) } - searchClient := buildSearchClientMock(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - http.Error(w, fmt.Sprintf("unexpected request: %q", r.RequestURI), 400) - })) - h := &Hooks{ - ModStore: store, - AlgoliaClient: searchClient, - Logger: log.New(io.Discard, "", 0), + ModStore: store, + Logger: log.New(io.Discard, "", 0), } tests := []struct { diff --git a/internal/features/modules/modules_feature.go b/internal/features/modules/modules_feature.go index 72e7ec5c2..16aec4803 100644 --- a/internal/features/modules/modules_feature.go +++ b/internal/features/modules/modules_feature.go @@ -9,11 +9,9 @@ import ( "io" "log" - "github.com/algolia/algoliasearch-client-go/v3/algolia/search" "github.com/hashicorp/go-version" "github.com/hashicorp/hcl-lang/decoder" "github.com/hashicorp/hcl-lang/lang" - "github.com/hashicorp/terraform-ls/internal/algolia" "github.com/hashicorp/terraform-ls/internal/document" "github.com/hashicorp/terraform-ls/internal/eventbus" fdecoder "github.com/hashicorp/terraform-ls/internal/features/modules/decoder" @@ -23,7 +21,6 @@ import ( "github.com/hashicorp/terraform-ls/internal/langserver/diagnostics" "github.com/hashicorp/terraform-ls/internal/registry" globalState "github.com/hashicorp/terraform-ls/internal/state" - "github.com/hashicorp/terraform-ls/internal/telemetry" "github.com/hashicorp/terraform-schema/backend" tfmod "github.com/hashicorp/terraform-schema/module" ) @@ -170,11 +167,6 @@ func (f *ModulesFeature) AppendCompletionHooks(srvCtx context.Context, decoderCo Logger: f.logger, } - credentials, ok := algolia.CredentialsFromContext(srvCtx) - if ok { - h.AlgoliaClient = search.NewClient(credentials.AppID, credentials.APIKey) - } - decoderContext.CompletionHooks["CompleteLocalModuleSources"] = h.LocalModuleSources decoderContext.CompletionHooks["CompleteRegistryModuleSources"] = h.RegistryModuleSources decoderContext.CompletionHooks["CompleteRegistryModuleVersions"] = h.RegistryModuleVersions @@ -247,11 +239,6 @@ func (f *ModulesFeature) Telemetry(path string) map[string]interface{} { if len(mod.Meta.ProviderRequirements) > 0 { reqs := make(map[string]string, 0) for pAddr, cons := range mod.Meta.ProviderRequirements { - if telemetry.IsPublicProvider(pAddr) { - reqs[pAddr.String()] = cons.String() - continue - } - // anonymize any unknown providers or the ones not publicly listed id, err := f.stateStore.ProviderSchemas.GetProviderID(pAddr) if err != nil { diff --git a/internal/features/rootmodules/root_modules_feature.go b/internal/features/rootmodules/root_modules_feature.go index c51bcc0a1..ae02ca452 100644 --- a/internal/features/rootmodules/root_modules_feature.go +++ b/internal/features/rootmodules/root_modules_feature.go @@ -5,7 +5,6 @@ package rootmodules import ( "context" - "fmt" "io" "log" @@ -14,7 +13,6 @@ import ( "github.com/hashicorp/terraform-ls/internal/features/rootmodules/jobs" "github.com/hashicorp/terraform-ls/internal/features/rootmodules/state" globalState "github.com/hashicorp/terraform-ls/internal/state" - "github.com/hashicorp/terraform-ls/internal/telemetry" "github.com/hashicorp/terraform-ls/internal/terraform/exec" tfaddr "github.com/hashicorp/terraform-registry-address" tfmod "github.com/hashicorp/terraform-schema/module" @@ -152,43 +150,6 @@ func (f *RootModulesFeature) CallersOfModule(modPath string) ([]string, error) { return f.Store.CallersOfModule(modPath) } -func (f *RootModulesFeature) Telemetry(path string) map[string]interface{} { - properties := make(map[string]interface{}) - - record, err := f.Store.RootRecordByPath(path) - if err != nil { - return properties - } - - if record.TerraformVersion != nil { - properties["tfVersion"] = record.TerraformVersion.String() - } - if len(record.InstalledProviders) > 0 { - installedProviders := make(map[string]string, 0) - for pAddr, pv := range record.InstalledProviders { - if telemetry.IsPublicProvider(pAddr) { - versionString := "" - if pv != nil { - versionString = pv.String() - } - installedProviders[pAddr.String()] = versionString - continue - } - - // anonymize any unknown providers or the ones not publicly listed - id, err := f.stateStore.ProviderSchemas.GetProviderID(pAddr) - if err != nil { - continue - } - addr := fmt.Sprintf("unlisted/%s", id) - installedProviders[addr] = "" - } - properties["installedProviders"] = installedProviders - } - - return properties -} - // InstalledModulePath checks the installed modules in the given root module // for the given normalized source address. // diff --git a/internal/langserver/handlers/completion_hooks.go b/internal/langserver/handlers/completion_hooks.go deleted file mode 100644 index 26f7b9e55..000000000 --- a/internal/langserver/handlers/completion_hooks.go +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package handlers - -import ( - "github.com/hashicorp/hcl-lang/decoder" - "github.com/hashicorp/terraform-ls/internal/hooks" -) - -func (s *service) AppendCompletionHooks(decoderContext decoder.DecoderContext) { - h := hooks.Hooks{ - ModStore: s.modStore, - RegistryClient: s.registryClient, - Logger: s.logger, - } - - decoderContext.CompletionHooks["CompleteLocalModuleSources"] = h.LocalModuleSources - decoderContext.CompletionHooks["CompleteRegistryModuleSources"] = h.RegistryModuleSources - decoderContext.CompletionHooks["CompleteRegistryModuleVersions"] = h.RegistryModuleVersions -} diff --git a/internal/langserver/handlers/hooks_module.go b/internal/langserver/handlers/hooks_module.go index e4dc55bb2..00958f8a0 100644 --- a/internal/langserver/handlers/hooks_module.go +++ b/internal/langserver/handlers/hooks_module.go @@ -12,7 +12,6 @@ import ( "github.com/hashicorp/terraform-ls/internal/state" ) - func callRefreshClientCommand(clientRequester session.ClientCaller, commandId string) notifier.Hook { return func(ctx context.Context, changes state.Changes) error { // TODO: avoid triggering if module calls/providers did not change