From e00330e7cf149293e75ea5a2db3c9c33bc41d985 Mon Sep 17 00:00:00 2001 From: Jian Yuan Lee Date: Fri, 13 Dec 2024 12:20:53 +0000 Subject: [PATCH] ref: Only run the latest version of Terraform on PRs (#542) * ref: Only run the latest version of Terraform on PRs * fix: lint errors --- .github/workflows/test.yml | 90 ++++++++++++------- GNUmakefile | 44 +++++++++ Makefile | 24 ----- .../resource_organization_repository_test.go | 6 +- internal/provider/resource_project.go | 4 +- ...ource_sentry_organization_code_mappings.go | 12 ++- sentry/resource_sentry_organization_member.go | 3 + ...e_sentry_organization_repository_github.go | 13 ++- 8 files changed, 128 insertions(+), 68 deletions(-) create mode 100644 GNUmakefile delete mode 100644 Makefile diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2155b081e..54d1fd4b4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,7 +1,8 @@ -# This GitHub action runs your tests for each commit push and/or PR. Optionally -# you can turn it on using a cron schedule for regular testing. -# +# Terraform Provider testing workflow. name: Tests + +# This GitHub action runs your tests for each pull request and push. +# Optionally, you can turn it on using a schedule for regular testing. on: pull_request: branches: @@ -17,48 +18,58 @@ on: # to an API change, even if the code did not change. schedule: - cron: "0 0 * * *" + +# Testing only needs permissions to read the repository contents. +permissions: + contents: read + concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true + jobs: - # ensure the code builds... + # Ensure project builds before running testing matrix build: name: Build runs-on: ubuntu-latest timeout-minutes: 5 steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0 with: go-version-file: "go.mod" cache: true - - name: Get dependencies - run: | - go mod download - - name: Build - run: | - go build -v . + - run: go mod download + - run: go build -v . + - name: Run linters + uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6.1.1 + with: + version: latest generate: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0 with: go-version-file: "go.mod" cache: true - - run: go generate ./... + # We need the latest version of Terraform for our documentation generation to use + - uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2 + with: + terraform_wrapper: false + - run: make generate - name: git diff run: | - git diff --exit-code || \ - (echo; echo "Unexpected difference in directories after code generation. Run 'go generate ./...' command and commit."; exit 1) + git diff --compact-summary --exit-code || \ + (echo; echo "Unexpected difference in directories after code generation. Run 'make generate' command and commit."; exit 1) - # run acceptance tests in a matrix with Terraform core versions + # Run acceptance tests in a matrix with Terraform CLI versions test: - name: Matrix Test + name: Terraform Provider Acceptance Tests needs: build runs-on: ubuntu-latest - timeout-minutes: 30 + timeout-minutes: 15 strategy: fail-fast: false max-parallel: 1 @@ -69,25 +80,36 @@ jobs: - "1.6.*" - "1.7.*" - "1.8.*" + - "1.9.*" + - "1.10.*" + is-pr: + - ${{ github.event_name == 'pull_request' }} + # Only run the latest version of Terraform on pull requests + exclude: + - terraform: "1.4.*" + is-pr: true + - terraform: "1.5.*" + is-pr: true + - terraform: "1.6.*" + is-pr: true + - terraform: "1.7.*" + is-pr: true + - terraform: "1.8.*" + is-pr: true + - terraform: "1.9.*" + is-pr: true steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0 with: go-version-file: "go.mod" cache: true - - - uses: hashicorp/setup-terraform@v3 + - uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2 with: terraform_version: ${{ matrix.terraform }} terraform_wrapper: false - - - name: Get dependencies - run: | - go mod download - - - name: TF acceptance tests - timeout-minutes: 30 - env: + - run: go mod download + - env: TF_ACC: "1" SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} SENTRY_TEST_GITHUB_INSTALLATION_ID: ${{ secrets.SENTRY_TEST_GITHUB_INSTALLATION_ID }} @@ -100,5 +122,5 @@ jobs: SENTRY_TEST_PAGERDUTY_ORGANIZATION: ${{ secrets.SENTRY_TEST_PAGERDUTY_ORGANIZATION }} SENTRY_TEST_VSTS_INSTALLATION_ID: ${{ secrets.SENTRY_TEST_VSTS_INSTALLATION_ID }} SENTRY_TEST_VSTS_REPOSITORY_IDENTIFIER: ${{ secrets.SENTRY_TEST_VSTS_REPOSITORY_IDENTIFIER }} - run: | - go test -v -cover -timeout 30m ./... + run: go test -v -cover ./internal/provider/ + timeout-minutes: 10 diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 000000000..c0142a129 --- /dev/null +++ b/GNUmakefile @@ -0,0 +1,44 @@ +SWEEP ?= cloud +SWEEP_TIMEOUT ?= 360m + +default: fmt lint install generate + +.PHONY: build +build: + go build -v ./... + +.PHONY: install +install: build + go install -v ./... + +.PHONY: lint +lint: + golangci-lint run + +.PHONY: generate +generate: + go generate ./... + +.PHONY: fmt +fmt: + gofmt -s -w -e . + +.PHONY: test +test: + go test -v -cover -timeout=120s -parallel=10 ./... + +.PHONY: testacc +testacc: + TF_ACC=1 go test -v -cover -timeout 120m ./... + +.PHONY: sweep +sweep: + # make sweep SWEEPARGS=-sweep-run=sentry_team + # set SWEEPARGS=-sweep-allow-failures to continue after first failure + @echo "WARNING: This will destroy infrastructure. Use only in development accounts." + go test ./... -v -sweep=$(SWEEP) $(SWEEPARGS) -timeout $(SWEEP_TIMEOUT) + +.PHONY: sweeper +sweeper: + @echo "WARNING: This will destroy infrastructure. Use only in development accounts." + go test ./... -v -tags=sweep -sweep=$(SWEEP) -sweep-allow-failures -timeout $(SWEEP_TIMEOUT) diff --git a/Makefile b/Makefile deleted file mode 100644 index b8d1874c0..000000000 --- a/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -GO_VER ?= go -SWEEP ?= cloud -SWEEP_TIMEOUT ?= 360m - -default: testacc - -.PHONY: deps -deps: - $(GO_VER) mod download - -# Run acceptance tests -.PHONY: testacc -testacc: - TF_ACC=1 $(GO_VER) test ./... -v $(TESTARGS) -timeout 120m - -sweep: ## Run sweepers - # make sweep SWEEPARGS=-sweep-run=sentry_team - # set SWEEPARGS=-sweep-allow-failures to continue after first failure - @echo "WARNING: This will destroy infrastructure. Use only in development accounts." - $(GO_VER) test ./... -v -sweep=$(SWEEP) $(SWEEPARGS) -timeout $(SWEEP_TIMEOUT) - -sweeper: ## Run sweepers with failures allowed - @echo "WARNING: This will destroy infrastructure. Use only in development accounts." - $(GO_VER) test ./... -v -tags=sweep -sweep=$(SWEEP) -sweep-allow-failures -timeout $(SWEEP_TIMEOUT) \ No newline at end of file diff --git a/internal/provider/resource_organization_repository_test.go b/internal/provider/resource_organization_repository_test.go index 12d198194..11b8a746e 100644 --- a/internal/provider/resource_organization_repository_test.go +++ b/internal/provider/resource_organization_repository_test.go @@ -98,7 +98,7 @@ func TestAccOrganizationRepositoryResource_GitHub(t *testing.T) { t.Skip("Skipping test due to missing SENTRY_TEST_GITHUB_REPOSITORY_IDENTIFIER environment variable") } - testAccOrganizationRepositoryResourcePreCheck() + must.Do(testAccOrganizationRepositoryResourcePreCheck()) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ @@ -150,7 +150,7 @@ func TestAccOrganizationRepositoryResource_GitLab(t *testing.T) { t.Skip("Skipping test due to missing SENTRY_TEST_GITLAB_REPOSITORY_IDENTIFIER environment variable") } - testAccOrganizationRepositoryResourcePreCheck() + must.Do(testAccOrganizationRepositoryResourcePreCheck()) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ @@ -202,7 +202,7 @@ func TestAccOrganizationRepositoryResource_VSTS(t *testing.T) { t.Skip("Skipping test due to missing SENTRY_TEST_VSTS_REPOSITORY_IDENTIFIER environment variable") } - testAccOrganizationRepositoryResourcePreCheck() + must.Do(testAccOrganizationRepositoryResourcePreCheck()) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ diff --git a/internal/provider/resource_project.go b/internal/provider/resource_project.go index 80fd89b18..6414bc6dd 100644 --- a/internal/provider/resource_project.go +++ b/internal/provider/resource_project.go @@ -124,7 +124,9 @@ func (m *ProjectResourceModel) Fill(project apiclient.Project) error { m.ResolveAge = types.Int64Value(project.ResolveAge) if m.Filters != nil { - m.Filters.Fill(project) + if err := m.Filters.Fill(project); err != nil { + return err + } } m.FingerprintingRules = sentrytypes.TrimmedStringValue(project.FingerprintingRules) diff --git a/sentry/resource_sentry_organization_code_mappings.go b/sentry/resource_sentry_organization_code_mappings.go index 59a09f8fa..ce974b6be 100644 --- a/sentry/resource_sentry_organization_code_mappings.go +++ b/sentry/resource_sentry_organization_code_mappings.go @@ -93,7 +93,9 @@ func resourceSentryOrganizationCodeMappingCreate(ctx context.Context, d *schema. } d.SetId(orgCodeMapping.ID) - d.Set("internal_id", orgCodeMapping.ID) + if err := d.Set("internal_id", orgCodeMapping.ID); err != nil { + return diag.FromErr(err) + } return resourceSentryOrganizationCodeMappingRead(ctx, d, meta) } @@ -178,7 +180,9 @@ func resourceSentryOrganizationCodeMappingUpdate(ctx context.Context, d *schema. } d.SetId(orgCodeMapping.ID) - d.Set("internal_id", orgCodeMapping.ID) + if err := d.Set("internal_id", orgCodeMapping.ID); err != nil { + return diag.FromErr(err) + } return resourceSentryOrganizationCodeMappingRead(ctx, d, meta) } @@ -204,7 +208,9 @@ func importSentryOrganizationCodeMapping(ctx context.Context, d *schema.Resource } d.SetId(id) - d.Set("organization", org) + if err := d.Set("organization", org); err != nil { + return nil, err + } resourceSentryOrganizationCodeMappingRead(ctx, d, meta) diff --git a/sentry/resource_sentry_organization_member.go b/sentry/resource_sentry_organization_member.go index bd3d8a423..0e3fca889 100644 --- a/sentry/resource_sentry_organization_member.go +++ b/sentry/resource_sentry_organization_member.go @@ -96,6 +96,9 @@ func resourceSentryOrganizationMemberRead(ctx context.Context, d *schema.Resourc client := meta.(*providerdata.ProviderData).Client org, memberID, err := splitSentryOrganizationMemberID(d.Id()) + if err != nil { + return diag.FromErr(err) + } tflog.Debug(ctx, "Reading organization member", map[string]interface{}{ "org": org, diff --git a/sentry/resource_sentry_organization_repository_github.go b/sentry/resource_sentry_organization_repository_github.go index df113f9e6..6905253a5 100644 --- a/sentry/resource_sentry_organization_repository_github.go +++ b/sentry/resource_sentry_organization_repository_github.go @@ -86,7 +86,9 @@ func resourceSentryOrganizationRepositoryGithubCreate(ctx context.Context, d *sc // You can connect multiple GitHub organizations to one Sentry organization, but you cannot connect a single GitHub organization to multiple Sentry organizations. // https://docs.sentry.io/product/integrations/source-code-mgmt/github/ d.SetId(identifier) - d.Set("internal_id", orgRepo.ID) + if err := d.Set("internal_id", orgRepo.ID); err != nil { + return diag.FromErr(err) + } return resourceSentryOrganizationRepositoryGithubRead(ctx, d, meta) } @@ -172,8 +174,13 @@ func importSentryOrganizationRepositoryGithub(ctx context.Context, d *schema.Res } d.SetId(id) - d.Set("identifier", id) - d.Set("organization", org) + if err := d.Set("identifier", id); err != nil { + return nil, err + } + + if err := d.Set("organization", org); err != nil { + return nil, err + } resourceSentryOrganizationRepositoryGithubRead(ctx, d, meta)