Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI to check that the provider compiles #105

Merged
merged 2 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: lint

on:
workflow_call:
inputs: {}
pull_request:
branches:
- main
- v*
- feature*
paths-ignore:
- CHANGELOG.md

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
lint:
name: lint
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Install go
uses: actions/setup-go@v4
with:
# The versions of golangci-lint and setup-go here cross-depend and need to update together.
go-version: 1.21
# Either this action or golangci-lint needs to disable the cache
cache: false
- name: disarm go:embed directives to enable lint
continue-on-error: true # this fails if there are no go:embed directives
run: |
git grep -l 'go:embed' -- provider | xargs sed -i 's/go:embed/ goembed/g'
- name: prepare upstream
continue-on-error: true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why continue on error here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the Makefile might not define an upstream target. If it does, then it is assumed to be necessary to compile the provider. If make upstream exists and fails, it is assumed the next step will fail.

run: make upstream
- run: cd provider && go mod tidy
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54.1
working-directory: provider
skip-pkg-cache: true
7 changes: 2 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
linters:
enable:
- deadcode
- errcheck
- goconst
- gofmt
- golint
- gosec
- govet
- ineffassign
- interfacer
- lll
- megacheck
- misspell
- nakedret
- structcheck
- revive
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes here allow the linter to trigger without warnings on deprecated linters.

- unconvert
- varcheck
- unused
enable-all: false
run:
skip-files:
Expand Down
1 change: 1 addition & 0 deletions provider/cmd/pulumi-resource-xyz/bridge-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
26 changes: 18 additions & 8 deletions provider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ import (
"fmt"
"path"

// Allow embedding bridge-metadata.json in the provider.
_ "embed"

"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/tokens"
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
"github.com/terraform-providers/terraform-provider-xyz/xyz"

// Replace this provider with the provider you are bridging.
xyz "github.com/iwahbe/terraform-provider-xyz/provider"

"github.com/pulumi/pulumi-xyz/provider/pkg/version"
)
Expand All @@ -41,16 +46,19 @@ const (
// It should validate that the provider can be configured, and provide actionable errors in the case
// it cannot be. Configuration variables can be read from `vars` using the `stringValue` function -
// for example `stringValue(vars, "accessKey")`.
func preConfigureCallback(vars resource.PropertyMap, c shim.ResourceConfig) error {
func preConfigureCallback(resource.PropertyMap, shim.ResourceConfig) error {
return nil
}

//go:embed cmd/pulumi-resource-xyz/bridge-metadata.json
var metadata []byte

// Provider returns additional overlaid schema and metadata associated with the provider..
func Provider() tfbridge.ProviderInfo {
// Create a Pulumi provider mapping
prov := tfbridge.ProviderInfo{
// Instantiate the Terraform provider
P: shimv2.NewProvider(xyz.Provider()),
P: shimv2.NewProvider(xyz.New(version.Version)()),
Name: "xyz",
// DisplayName is a way to be able to change the casing of the provider
// name when being displayed on the Pulumi registry
Expand Down Expand Up @@ -80,8 +88,9 @@ func Provider() tfbridge.ProviderInfo {
Repository: "https://github.com/pulumi/pulumi-xyz",
// The GitHub Org for the provider - defaults to `terraform-providers`. Note that this
// should match the TF provider module's require directive, not any replace directives.
GitHubOrg: "",
Config: map[string]*tfbridge.SchemaInfo{
GitHubOrg: "",
MetadataInfo: tfbridge.NewProviderMetadata(metadata),
Config: map[string]*tfbridge.SchemaInfo{
// Add any required configuration here, or remove the example below if
// no additional points are required.
// "region": {
Expand Down Expand Up @@ -147,9 +156,10 @@ func Provider() tfbridge.ProviderInfo {
},
}

// These are new API's that you may opt to use to automatically compute resource tokens,
// and apply auto aliasing for full backwards compatibility.
// For more information, please reference: https://pkg.go.dev/github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge#ProviderInfo.ComputeTokens
// These are new API's that you may opt to use to automatically compute resource
// tokens, and apply auto aliasing for full backwards compatibility. For more
// information, please reference:
// https://pkg.go.dev/github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge#ProviderInfo.ComputeTokens
prov.MustComputeTokens(tokens.SingleModule("xyz_", mainMod,
tokens.MakeStandard(mainPkg)))
prov.MustApplyAutoAliases()
Expand Down
Loading