Skip to content

Commit

Permalink
ref: Only run the latest version of Terraform on PRs (#542)
Browse files Browse the repository at this point in the history
* ref: Only run the latest version of Terraform on PRs

* fix: lint errors
  • Loading branch information
jianyuan authored Dec 13, 2024
1 parent 51b3d78 commit e00330e
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 68 deletions.
90 changes: 56 additions & 34 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand All @@ -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 }}
Expand All @@ -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
44 changes: 44 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -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)
24 changes: 0 additions & 24 deletions Makefile

This file was deleted.

6 changes: 3 additions & 3 deletions internal/provider/resource_organization_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
4 changes: 3 additions & 1 deletion internal/provider/resource_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions sentry/resource_sentry_organization_code_mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}
Expand All @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions sentry/resource_sentry_organization_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 10 additions & 3 deletions sentry/resource_sentry_organization_repository_github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit e00330e

Please sign in to comment.