Skip to content

Commit

Permalink
Upload unit test coverage for bridged providers by default (#1224)
Browse files Browse the repository at this point in the history
Turn on codecov reporting for provider unit tests.
  • Loading branch information
blampe authored Dec 13, 2024
1 parent 3e4be1c commit 87d055d
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 49 deletions.
47 changes: 3 additions & 44 deletions provider-ci/internal/pkg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ type actionVersions struct {
UpgradeProviderAction string `yaml:"upgradeProviderAction"`
FreeDiskSpace string `yaml:"freeDiskSpace"`
ProviderVersionAction string `yaml:"providerVersionAction"`
Codecov string `yaml:"codeCov"`
}

type toolVersions struct {
Expand Down Expand Up @@ -345,8 +346,6 @@ type publish struct {
func loadDefaultConfig() (Config, error) {
var config Config

var wf workflow

// Parse our actions file while preserving comments.
var doc yaml.Node
err := yaml.Unmarshal(defaultActionVersions, &doc)
Expand Down Expand Up @@ -394,42 +393,15 @@ func loadDefaultConfig() (Config, error) {
config.ActionVersions.FreeDiskSpace = uses
case "pulumi/provider-version-action":
config.ActionVersions.ProviderVersionAction = uses
case "codecov/codecov-action":
config.ActionVersions.Codecov = uses
}
}
}
}
}
}

for _, j := range wf.Jobs {
for _, s := range j.Steps {
switch s.Name {
case "aws-actions/configure-aws-credentials":
config.ActionVersions.ConfigureAwsCredentials = s.Uses
case "google-github-actions/setup-gcloud":
config.ActionVersions.SetupGcloud = s.Uses
case "google-github-actions/auth":
config.ActionVersions.GoogleAuth = s.Uses
case "actions/checkout":
config.ActionVersions.Checkout = s.Uses
case "actions/download-artifact":
config.ActionVersions.DownloadArtifact = s.Uses
case "dorny/paths-filter":
config.ActionVersions.PathsFilter = s.Uses
case "thollander/actions-comment-pull-request":
config.ActionVersions.PrComment = s.Uses
case "actions/upload-artifact":
config.ActionVersions.UploadArtifact = s.Uses
case "pulumi/pulumi-upgrade-provider-action":
config.ActionVersions.UpgradeProviderAction = s.Uses
case "jlumbroso/free-disk-space":
config.ActionVersions.FreeDiskSpace = s.Uses
case "pulumi/provider-version-action":
config.ActionVersions.ProviderVersionAction = s.Uses
}
}
}

configBytes, err := templateFS.ReadFile(filepath.Join("templates", "defaults.config.yaml"))
if err != nil {
return Config{}, fmt.Errorf("error reading embedded defaults config file: %w", err)
Expand Down Expand Up @@ -479,16 +451,3 @@ func (x *intOrDuration) UnmarshalYAML(unmarshal func(interface{}) error) error {
*x = intOrDuration(i * int64(time.Minute))
return nil
}

type workflow struct {
Jobs map[string]job
}

type job struct {
Steps []step
}

type step struct {
Name string
Uses string
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ jobs:
run: make provider
- name: Unit-test provider code
run: make test_provider
- name: Upload coverage reports to Codecov
uses: #{{ .Config.ActionVersions.Codecov }}#
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- if: inputs.is_pr
name: Check Schema is Valid
run: |
Expand Down
6 changes: 5 additions & 1 deletion provider-ci/internal/pkg/templates/bridged-provider/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,11 @@ test:
.PHONY: test

test_provider:
cd provider && go test -v -short ./... -parallel $(TESTPARALLELISM)
cd provider && go test -v -short \
-coverprofile="coverage.txt" \
-coverpkg="./...,github.com/hashicorp/terraform-provider-..." \
-parallel $(TESTPARALLELISM) \
./...
.PHONY: test_provider

tfgen: schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ jobs:
run: make provider
- name: Unit-test provider code
run: make test_provider
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@c2fcb216de2b0348de0100baa3ea2cad9f100a01 # v5.1.0
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- if: inputs.is_pr
name: Check Schema is Valid
run: |
Expand Down
6 changes: 5 additions & 1 deletion provider-ci/test-providers/acme/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,11 @@ test:
.PHONY: test

test_provider:
cd provider && go test -v -short ./... -parallel $(TESTPARALLELISM)
cd provider && go test -v -short \
-coverprofile="coverage.txt" \
-coverpkg="./...,github.com/hashicorp/terraform-provider-..." \
-parallel $(TESTPARALLELISM) \
./...
.PHONY: test_provider

tfgen: schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ jobs:
run: make provider
- name: Unit-test provider code
run: make test_provider
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@c2fcb216de2b0348de0100baa3ea2cad9f100a01 # v5.1.0
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- if: inputs.is_pr
name: Check Schema is Valid
run: |
Expand Down
6 changes: 5 additions & 1 deletion provider-ci/test-providers/aws/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,11 @@ test:
.PHONY: test

test_provider:
cd provider && go test -v -short ./... -parallel $(TESTPARALLELISM)
cd provider && go test -v -short \
-coverprofile="coverage.txt" \
-coverpkg="./...,github.com/hashicorp/terraform-provider-..." \
-parallel $(TESTPARALLELISM) \
./...
.PHONY: test_provider

tfgen: schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ jobs:
run: make provider
- name: Unit-test provider code
run: make test_provider
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@c2fcb216de2b0348de0100baa3ea2cad9f100a01 # v5.1.0
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- if: inputs.is_pr
name: Check Schema is Valid
run: |
Expand Down
6 changes: 5 additions & 1 deletion provider-ci/test-providers/cloudflare/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,11 @@ test:
.PHONY: test

test_provider:
cd provider && go test -v -short ./... -parallel $(TESTPARALLELISM)
cd provider && go test -v -short \
-coverprofile="coverage.txt" \
-coverpkg="./...,github.com/hashicorp/terraform-provider-..." \
-parallel $(TESTPARALLELISM) \
./...
.PHONY: test_provider

tfgen: schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ jobs:
run: make provider
- name: Unit-test provider code
run: make test_provider
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@c2fcb216de2b0348de0100baa3ea2cad9f100a01 # v5.1.0
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- if: inputs.is_pr
name: Check Schema is Valid
run: |
Expand Down
6 changes: 5 additions & 1 deletion provider-ci/test-providers/docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ test:
.PHONY: test

test_provider:
cd provider && go test -v -short ./... -parallel $(TESTPARALLELISM)
cd provider && go test -v -short \
-coverprofile="coverage.txt" \
-coverpkg="./...,github.com/hashicorp/terraform-provider-..." \
-parallel $(TESTPARALLELISM) \
./...
.PHONY: test_provider

tfgen: schema
Expand Down

0 comments on commit 87d055d

Please sign in to comment.