Skip to content

Commit

Permalink
Enforce Golang linting in CI (#1187)
Browse files Browse the repository at this point in the history
### Proposed changes

- Run golangci-lint in CI
- Fix linting issues in Go code
- Replace deprecated linters

### Related issues (optional)

Fixes: #1185
  • Loading branch information
rquitales authored Jun 7, 2024
1 parent 0404693 commit 92465dc
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 20 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ env:
ALT_AWS_PROFILE: ${{ secrets.ALT_AWS_PROFILE }}
AWS_REGION: us-west-2
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOLANGCI_LINT_VERSION: v1.59.0
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NUGET_PUBLISH_KEY: ${{ secrets.NUGET_PUBLISH_KEY }}
Expand Down Expand Up @@ -49,8 +50,14 @@ jobs:
run: |
echo "$HOME/.yarn/bin" >> $GITHUB_PATH
echo "$HOME/.config/yarn/global/node_modules/.bin" >> $GITHUB_PATH
- name: Run lint
- name: Run nodejs linter
run: make lint
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: ${{ env.GOLANGCI_LINT_VERSION }}
args: -c ../.golangci.yml
working-directory: provider
- name: Run unit tests
run: make test_unit_tests
prerequisites:
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ env:
ALT_AWS_PROFILE: ${{ secrets.ALT_AWS_PROFILE }}
AWS_REGION: us-west-2
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOLANGCI_LINT_VERSION: v1.59.0
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NUGET_PUBLISH_KEY: ${{ secrets.NUGET_PUBLISH_KEY }}
Expand Down Expand Up @@ -49,8 +50,14 @@ jobs:
run: |
echo "$HOME/.yarn/bin" >> $GITHUB_PATH
echo "$HOME/.config/yarn/global/node_modules/.bin" >> $GITHUB_PATH
- name: Run lint
- name: Run nodejs linter
run: make lint
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: ${{ env.GOLANGCI_LINT_VERSION }}
args: -c ../.golangci.yml
working-directory: provider
- name: Run unit tests
run: make test_unit_tests
prerequisites:
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ env:
ALT_AWS_PROFILE: ${{ secrets.ALT_AWS_PROFILE }}
AWS_REGION: us-west-2
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOLANGCI_LINT_VERSION: v1.59.0
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NUGET_PUBLISH_KEY: ${{ secrets.NUGET_PUBLISH_KEY }}
Expand Down Expand Up @@ -50,8 +51,14 @@ jobs:
run: |
echo "$HOME/.yarn/bin" >> $GITHUB_PATH
echo "$HOME/.config/yarn/global/node_modules/.bin" >> $GITHUB_PATH
- name: Run lint
- name: Run nodejs linter
run: make lint
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: ${{ env.GOLANGCI_LINT_VERSION }}
args: -c ../.golangci.yml
working-directory: provider
- name: Run unit tests
run: make test_unit_tests
build_sdk:
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/run-acceptance-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ env:
ALT_AWS_PROFILE: ${{ secrets.ALT_AWS_PROFILE }}
AWS_REGION: us-west-2
GITHUB_TOKEN: ${{ secrets.PULUMI_BOT_TOKEN }}
GOLANGCI_LINT_VERSION: v1.59.0
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
PROVIDER: eks
Expand Down Expand Up @@ -69,8 +70,14 @@ jobs:
run: |
echo "$HOME/.yarn/bin" >> $GITHUB_PATH
echo "$HOME/.config/yarn/global/node_modules/.bin" >> $GITHUB_PATH
- name: Run lint
- name: Run nodejs linter
run: make lint
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: ${{ env.GOLANGCI_LINT_VERSION }}
args: -c ../.golangci.yml
working-directory: provider
- name: Run unit tests
run: make test_unit_tests
prerequisites:
Expand Down
12 changes: 4 additions & 8 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
linters:
enable:
- deadcode
- errcheck
- goconst
- gofmt
- golint
- gosec
- gosimple
- govet
- ineffassign
- interfacer
- lll
- megacheck
- misspell
- nakedret
- structcheck
- revive
- staticcheck
- unused
- unconvert
- varcheck
enable-all: false
run:
skip-files:
- schema.go
- pulumiManifest.go
timeout: 10m
16 changes: 9 additions & 7 deletions provider/cmd/pulumi-gen-eks/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -92,7 +91,7 @@ func k8sRef(ref string) string {
return fmt.Sprintf("/kubernetes/%s/schema.json%s", k8sVersion, ref)
}

// nolint: lll
//nolint:lll,goconst
func generateSchema() schema.PackageSpec {
return schema.PackageSpec{
Name: "eks",
Expand Down Expand Up @@ -1679,6 +1678,7 @@ func generateSchema() schema.PackageSpec {
}
}

//nolint:lll
func nodeGroupProperties(cluster, v2 bool) map[string]schema.PropertySpec {
props := map[string]schema.PropertySpec{
"nodeSubnetIds": {
Expand Down Expand Up @@ -1936,8 +1936,10 @@ func nodeGroupProperties(cluster, v2 bool) map[string]schema.PropertySpec {

props["launchTemplateTagSpecifications"] = schema.PropertySpec{
TypeSpec: schema.TypeSpec{
Type: "array",
Items: &schema.TypeSpec{Ref: awsRef("#/types/aws:ec2%2FLaunchTemplateTagSpecification:LaunchTemplateTagSpecification")},
Type: "array",
Items: &schema.TypeSpec{
Ref: awsRef("#/types/aws:ec2%2FLaunchTemplateTagSpecification:LaunchTemplateTagSpecification"),
},
},
Description: "The tag specifications to apply to the launch template.",
}
Expand Down Expand Up @@ -2096,13 +2098,13 @@ func vpcCniProperties(kubeconfig bool) map[string]schema.PropertySpec {

func rawMessage(v interface{}) schema.RawMessage {
bytes, err := json.Marshal(v)
contract.Assert(err == nil)
contract.Assertf(err == nil, "failed to marshal raw message: %v", err)
return bytes
}

func readSchema(schemaPath string, version string) *schema.Package {
// Read in, decode, and import the schema.
schemaBytes, err := ioutil.ReadFile(schemaPath)
schemaBytes, err := os.ReadFile(schemaPath)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -2156,7 +2158,7 @@ func mustWriteFile(rootDir, filename string, contents []byte) {
if err := os.MkdirAll(filepath.Dir(outPath), 0755); err != nil {
panic(err)
}
err := ioutil.WriteFile(outPath, contents, 0600)
err := os.WriteFile(outPath, contents, 0600)
if err != nil {
panic(err)
}
Expand Down
4 changes: 3 additions & 1 deletion provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ func testProviderUpgrade(t *testing.T, example string) {

test := pulumitest.NewPulumiTest(t, dir, options...)

result := providertest.PreviewProviderUpgrade(t, test, providerName, baselineVersion, optproviderupgrade.DisableAttach())
result := providertest.PreviewProviderUpgrade(t, test, providerName, baselineVersion,
optproviderupgrade.DisableAttach(),
)
assertpreview.HasNoReplacements(t, result)
}

0 comments on commit 92465dc

Please sign in to comment.