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

linting: Restore code generation checks #21356

Merged
merged 4 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
65 changes: 33 additions & 32 deletions .github/workflows/terraform_provider.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,38 +153,39 @@ jobs:
# - name: providerlint
# run: make providerlint

# go_generate:
# name: go generate
# needs: [go_build]
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# # See also: https://github.com/actions/setup-go/pull/62
# - run: echo "GO_VERSION=$(cat .go-version)" >> $GITHUB_ENV
# - uses: actions/setup-go@v2
# with:
# go-version: ${{ env.GO_VERSION }}
# # See also: https://github.com/actions/setup-go/issues/54
# - name: go env
# run: |
# echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_ENV
# - uses: actions/cache@v2
# continue-on-error: true
# timeout-minutes: 2
# with:
# path: ${{ env.GOCACHE }}
# key: ${{ runner.os }}-GOCACHE-${{ hashFiles('go.sum') }}-${{ hashFiles('aws/**') }}
# - uses: actions/cache@v2
# continue-on-error: true
# timeout-minutes: 2
# with:
# path: ~/go/pkg/mod
# key: ${{ runner.os }}-go-pkg-mod-${{ hashFiles('go.sum') }}
# - run: make gen
# - name: Check for Git Differences
# run: |
# git diff --compact-summary --exit-code || \
# (echo; echo "Unexpected difference in directories after code generation. Run 'make gen' command and commit."; exit 1)
go_generate:
name: go generate
needs: [go_build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# See also: https://github.com/actions/setup-go/pull/62
- run: echo "GO_VERSION=$(cat .go-version)" >> $GITHUB_ENV
- uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
# See also: https://github.com/actions/setup-go/issues/54
- name: go env
run: |
echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_ENV
- uses: actions/cache@v2
continue-on-error: true
timeout-minutes: 2
with:
path: ${{ env.GOCACHE }}
key: ${{ runner.os }}-GOCACHE-${{ hashFiles('go.sum') }}-${{ hashFiles('internal/**') }}
- uses: actions/cache@v2
continue-on-error: true
timeout-minutes: 2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-pkg-mod-${{ hashFiles('go.sum') }}
- run: go install golang.org/x/tools/cmd/goimports
- run: make gen
- name: Check for Git Differences
run: |
git diff --compact-summary --exit-code || \
(echo; echo "Unexpected difference in directories after code generation. Run 'make gen' command and commit."; exit 1)

go_test:
name: go test
Expand Down
1 change: 1 addition & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ build: fmtcheck
gen:
rm -f internal/service/**/*_gen.go
go generate ./...
goimports -w ./$(PKG_NAME)
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to add cd tools && go install golang.org/x/tools/cmd/goimports to the tools target, else

% make gen
rm -f internal/service/**/*_gen.go
go generate ./...
goimports -w ./internal
make: goimports: No such file or directory
make: *** [gen] Error 1
% cd tools && go install golang.org/x/tools/cmd/goimports
% goimports -w ./internal


sweep:
@echo "WARNING: This will destroy infrastructure. Use only in development accounts."
Expand Down
17 changes: 8 additions & 9 deletions internal/generate/listpages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,28 @@ For example, the EC2 API defines both [`DescribeInstancesPages`](https://docs.aw
The `listpages` executable is called as follows:

```console
$ go run main.go -function <function-name>[,<function-name>] <source-package>
$ go run main.go -ListOps <function-name>[,<function-name>]
```

* `<source-package>`: The full Go package name of the AWS Go SDK package to be extended, e.g. `github.com/aws/aws-sdk-go/service/cloudwatchevents`
* `<function-name>`: Name of a function to wrap

Optional Flags:

* `-paginator`: Name of the pagination token field (default `NextToken`)
* `-package`: Override the package name for the generated code (By default, uses the environment variable `$GOPACKAGE` set by `go generate`)
* `-Paginator`: Name of the pagination token field (default `NextToken`)
* `-Export`: Whether to export the generated functions

To use with `go generate`, add the following directive to a Go file

```go
//go:generate go run <relative-path-to-generators>/generators/listpages/main.go -function=<comma-separated-list-of-functions> <aws-sdk-package>
//go:generate go run <relative-path-to-generators>/generate/listpages/main.go -ListOps=<comma-separated-list-of-functions>
```

For example, in the file `aws/internal/service/cloudwatchevents/lister/list.go`
For example, in the file `internal/service/cloudwatchevents/generate.go`

```go
//go:generate go run ../../../generators/listpages/main.go -function=ListEventBuses,ListRules,ListTargetsByRule github.com/aws/aws-sdk-go/service/cloudwatchevents
//go:generate go run -tags generate ../../generate/listpages/main.go -ListOps=ListEventBuses,ListRules,ListTargetsByRule

package lister
package cloudwatchevents
```

Generates the file `aws/internal/service/cloudwatchevents/lister/list_pages_gen.go` with the functions `ListEventBusesPages`, `ListRulesPages`, and `ListTargetsByRulePages`.
generates the file `internal/service/cloudwatchevents/list_pages_gen.go` with the functions `listEventBusesPages`, `listRulesPages`, and `listTargetsByRulePages` as well as their `...WithContext` equivalents.
1 change: 0 additions & 1 deletion internal/generate/listpages/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,6 @@ func init() {
awsServiceNames["apigateway"] = "APIGateway"
awsServiceNames["apigatewaymanagement"] = "APIGatewayManagement"
awsServiceNames["apigatewayv2"] = "APIGatewayV2"
awsServiceNames["apigatewayv2"] = "ApiGatewayV2"
awsServiceNames["appconfig"] = "AppConfig"
awsServiceNames["appflow"] = "AppFlow"
awsServiceNames["appintegrations"] = "AppIntegrations"
Expand Down
4 changes: 2 additions & 2 deletions internal/generate/namevaluesfilters/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The `namevaluesfilters` package is designed to provide a consistent interface fo

This package implements a single `NameValuesFilters` type, which covers all filter handling logic, such as merging filters, via functions on the single type. The underlying implementation is compatible with Go operations such as `len()`.

Full documentation for this package can be found on [GoDoc](https://godoc.org/github.com/hashicorp/terraform-provider-aws/aws/internal/namevaluesfilters).
Full documentation for this package can be found on [GoDoc](https://godoc.org/github.com/hashicorp/terraform-provider-aws/internal/generate/namevaluesfilters).

Many AWS Go SDK services that support resource filtering have their service-specific Go type conversion functions to and from `NameValuesFilters` code generated. Converting from `NameValuesFilters` to AWS Go SDK types is done via `{SERVICE}Filters()` functions on the type. For more information about this code generation, see the [`generators/servicefilters` README](generators/servicefilters/README.md).

Expand All @@ -13,7 +13,7 @@ Any filtering functions that cannot be generated should be hand implemented in a
## Code Structure

```text
aws/internal/namevaluesfilters
internal/generate/namevaluesfilters
├── generators
│ └── servicefilters (generates service_filters_gen.go)
├── name_values_filters_test.go (unit tests for core logic)
Expand Down
7 changes: 2 additions & 5 deletions internal/generate/tagresource/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ The `tagresource` package is designed to provide a generator and consistent inte
## Code Structure

```text
aws/internal/tagresource
├── generator/main.go (generates tag resource)
├── tag_resources_test.go (unit tests for shared tag resource logic)
├── tag_resources.go (shared tag resource logic)
└── service_generation_customizations.go (AWS Go SDK service customizations for generator)
internal/generate/tagresource
└── main.go (generates tag resource)
```
2 changes: 1 addition & 1 deletion internal/generate/tags/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This generator (`main.go`) generates files named `tags_gen`, such as `internal/s
Control the code generated using flags of the directives that you include in a `generate.go` file for an individual service. For example, a file such as `internal/service/ecs/generate.go` may contain three directives (and a package declaration). This generator corresponds to the `../../generate/tags/main.go` directive. (The other directives are documented in their respective packages.)

```go
//go:generate go run ../../generate/listpages/main.go -ListOps=DescribeCapacityProviders -Export
//go:generate go run ../../generate/listpages/main.go -ListOps=DescribeCapacityProviders
//go:generate go run ../../generate/tagresource/main.go
//go:generate go run ../../generate/tags/main.go -GetTag -ListTags -ServiceTagsSlice -UpdateTags

Expand Down
2 changes: 1 addition & 1 deletion internal/service/amplify/generate.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate go run ../../generate/listpages/main.go -ListOps=ListApps -Export
//go:generate go run ../../generate/listpages/main.go -ListOps=ListApps
//go:generate go run ../../generate/tags/main.go -ListTags -ServiceTagsMap -UpdateTags
// ONLY generate directives and package declaration! Do not add anything else to this file.

Expand Down
8 changes: 4 additions & 4 deletions internal/service/amplify/list_pages_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/service/amplify/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func sweepApps(region string) error {
input := &amplify.ListAppsInput{}
var sweeperErrs *multierror.Error

err = ListAppsPages(conn, input, func(page *amplify.ListAppsOutput, lastPage bool) bool {
err = listAppsPages(conn, input, func(page *amplify.ListAppsOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/apigatewayv2/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func FindAPI(conn *apigatewayv2.ApiGatewayV2, input *apigatewayv2.GetApiInput) (
func FindAPIs(conn *apigatewayv2.ApiGatewayV2, input *apigatewayv2.GetApisInput) ([]*apigatewayv2.Api, error) {
var apis []*apigatewayv2.Api

err := GetAPIsPages(conn, input, func(page *apigatewayv2.GetApisOutput, lastPage bool) bool {
err := getAPIsPages(conn, input, func(page *apigatewayv2.GetApisOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/apigatewayv2/generate.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate go run ../../generate/listpages/main.go -ListOps=GetApis,GetDomainNames -Export
//go:generate go run ../../generate/listpages/main.go -ListOps=GetApis,GetDomainNames
//go:generate go run ../../generate/tags/main.go -ListTags -ListTagsOp=GetTags -ServiceTagsMap -UpdateTags
// ONLY generate directives and package declaration! Do not add anything else to this file.

Expand Down
14 changes: 7 additions & 7 deletions internal/service/apigatewayv2/list_pages_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/service/apigatewayv2/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func sweepDomainNames(region string) error {
input := &apigatewayv2.GetDomainNamesInput{}
var sweeperErrs *multierror.Error

err = GetDomainNamesPages(conn, input, func(page *apigatewayv2.GetDomainNamesOutput, lastPage bool) bool {
err = getDomainNamesPages(conn, input, func(page *apigatewayv2.GetDomainNamesOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/appstream/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func FindImageBuilderByName(ctx context.Context, conn *appstream.AppStream, name

var result *appstream.ImageBuilder

err := DescribeImageBuildersPagesWithContext(ctx, conn, input, func(page *appstream.DescribeImageBuildersOutput, lastPage bool) bool {
err := describeImageBuildersPagesWithContext(ctx, conn, input, func(page *appstream.DescribeImageBuildersOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/appstream/generate.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate go run ../../generate/listpages/main.go -ListOps=DescribeFleets,DescribeImageBuilders,DescribeStacks -Export
//go:generate go run ../../generate/listpages/main.go -ListOps=DescribeFleets,DescribeImageBuilders,DescribeStacks
//go:generate go run ../../generate/tags/main.go -ListTags -ServiceTagsMap -UpdateTags
// ONLY generate directives and package declaration! Do not add anything else to this file.

Expand Down
20 changes: 10 additions & 10 deletions internal/service/appstream/list_pages_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions internal/service/appstream/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func sweepFleet(region string) error {

input := &appstream.DescribeFleetsInput{}

err = DescribeFleetsPagesWithContext(context.TODO(), conn, input, func(page *appstream.DescribeFleetsOutput, lastPage bool) bool {
err = describeFleetsPagesWithContext(context.TODO(), conn, input, func(page *appstream.DescribeFleetsOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}
Expand Down Expand Up @@ -104,7 +104,7 @@ func sweepImageBuilder(region string) error {

input := &appstream.DescribeImageBuildersInput{}

err = DescribeImageBuildersPagesWithContext(context.TODO(), conn, input, func(page *appstream.DescribeImageBuildersOutput, lastPage bool) bool {
err = describeImageBuildersPagesWithContext(context.TODO(), conn, input, func(page *appstream.DescribeImageBuildersOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}
Expand Down Expand Up @@ -155,7 +155,7 @@ func sweepStack(region string) error {

input := &appstream.DescribeStacksInput{}

err = DescribeStacksPagesWithContext(context.TODO(), conn, input, func(page *appstream.DescribeStacksOutput, lastPage bool) bool {
err = describeStacksPagesWithContext(context.TODO(), conn, input, func(page *appstream.DescribeStacksOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/autoscalingplans/generate.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate go run ../../generate/listpages/main.go -ListOps=DescribeScalingPlans -Export
//go:generate go run ../../generate/listpages/main.go -ListOps=DescribeScalingPlans
// ONLY generate directives and package declaration! Do not add anything else to this file.

package autoscalingplans
Loading