Skip to content

Commit

Permalink
Disarm any go:embed directives before running golangci-lint for nativ…
Browse files Browse the repository at this point in the history
…e providers (#1078)

The pulumi-kubernetes provider embeds a minified version of a Pulumi
JSON schema in the built binary. This file is not checked into source,
only the non minified version is. `golangci-lint` is unable to compile
the provider for linting if the file does not exist. This PR ensures
that we disable any go:embed directives by doing a simple find/replace.

This is necessary as `golangci-lint` is unable to skip processing
files/directories. Instead, the `exclude-dirs/files` directives will
still parse those files/directories, but just suppress warnings/errors.
If it is not compilable, in this case due to missing embed files, the
linter will also fail. See
https://golangci-lint.run/welcome/faq/#why-do-you-have-typecheck-errors

Seehttps://github.com/pulumi/pulumi-kubernetes/pull/3355 for example
passing run that modifies the workflow file directly.
  • Loading branch information
rquitales authored Dec 9, 2024
1 parent 4c6f12f commit 0bd42a4
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,9 @@ jobs:
with:
go-version: ${{ env.GOVERSION }}
cache-dependency-path: "**/*.sum"
- name: Disarm go:embed directives to enable linters that compile source code
run: git grep -l 'go:embed' -- provider | xargs --no-run-if-empty sed -i
's/go:embed/ goembed/g'
- name: golangci-lint provider pkg
uses: golangci/golangci-lint-action@d6238b002a20823d52840fda27e2d4891c5952dc # v4.0.1
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,9 @@ jobs:
with:
go-version: ${{ env.GOVERSION }}
cache-dependency-path: "**/*.sum"
- name: Disarm go:embed directives to enable linters that compile source code
run: git grep -l 'go:embed' -- provider | xargs --no-run-if-empty sed -i
's/go:embed/ goembed/g'
- name: golangci-lint provider pkg
uses: golangci/golangci-lint-action@d6238b002a20823d52840fda27e2d4891c5952dc # v4.0.1
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,9 @@ jobs:
with:
go-version: ${{ env.GOVERSION }}
cache-dependency-path: "**/*.sum"
- name: Disarm go:embed directives to enable linters that compile source code
run: git grep -l 'go:embed' -- provider | xargs --no-run-if-empty sed -i
's/go:embed/ goembed/g'
- name: golangci-lint provider pkg
uses: golangci/golangci-lint-action@d6238b002a20823d52840fda27e2d4891c5952dc # v4.0.1
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@ jobs:
with:
go-version: ${{ env.GOVERSION }}
cache-dependency-path: "**/*.sum"
- name: Disarm go:embed directives to enable linters that compile source code
run: git grep -l 'go:embed' -- provider | xargs --no-run-if-empty sed -i
's/go:embed/ goembed/g'
- name: golangci-lint provider pkg
uses: golangci/golangci-lint-action@d6238b002a20823d52840fda27e2d4891c5952dc # v4.0.1
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,9 @@ jobs:
with:
go-version: ${{ env.GOVERSION }}
cache-dependency-path: "**/*.sum"
- name: Disarm go:embed directives to enable linters that compile source code
run: git grep -l 'go:embed' -- provider | xargs --no-run-if-empty sed -i
's/go:embed/ goembed/g'
- name: golangci-lint provider pkg
uses: golangci/golangci-lint-action@d6238b002a20823d52840fda27e2d4891c5952dc # v4.0.1
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,9 @@ jobs:
with:
go-version: ${{ env.GOVERSION }}
cache-dependency-path: "**/*.sum"
- name: Disarm go:embed directives to enable linters that compile source code
run: git grep -l 'go:embed' -- provider | xargs --no-run-if-empty sed -i
's/go:embed/ goembed/g'
- name: golangci-lint provider pkg
uses: golangci/golangci-lint-action@d6238b002a20823d52840fda27e2d4891c5952dc # v4.0.1
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,9 @@ jobs:
with:
go-version: ${{ env.GOVERSION }}
cache-dependency-path: "**/*.sum"
- name: Disarm go:embed directives to enable linters that compile source code
run: git grep -l 'go:embed' -- provider | xargs --no-run-if-empty sed -i
's/go:embed/ goembed/g'
- name: golangci-lint provider pkg
uses: golangci/golangci-lint-action@d6238b002a20823d52840fda27e2d4891c5952dc # v4.0.1
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,9 @@ jobs:
with:
go-version: ${{ env.GOVERSION }}
cache-dependency-path: "**/*.sum"
- name: Disarm go:embed directives to enable linters that compile source code
run: git grep -l 'go:embed' -- provider | xargs --no-run-if-empty sed -i
's/go:embed/ goembed/g'
- name: golangci-lint provider pkg
uses: golangci/golangci-lint-action@d6238b002a20823d52840fda27e2d4891c5952dc # v4.0.1
with:
Expand Down
11 changes: 9 additions & 2 deletions native-provider-ci/src/steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -912,8 +912,13 @@ export function InstallandConfigureHelm(provider: string): Step {
return {};
}

export function GolangciLint(): Step {
return {
export function GolangciLint(): Step[] {
const disarmGoEmbed = {
name: "Disarm go:embed directives to enable linters that compile source code",
run: "git grep -l 'go:embed' -- provider | xargs --no-run-if-empty sed -i 's/go:embed/ goembed/g'",
};

const lintStep = {
name: "golangci-lint provider pkg",
uses: action.goLint,
with: {
Expand All @@ -922,6 +927,8 @@ export function GolangciLint(): Step {
"working-directory": "provider",
},
};

return [disarmGoEmbed, lintStep];
}

export function CodegenDuringSDKBuild(provider: string) {
Expand Down
8 changes: 6 additions & 2 deletions native-provider-ci/src/workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -711,13 +711,17 @@ export class TeardownTestClusterJob implements NormalJob {

export class LintJob implements NormalJob {
"runs-on" = "ubuntu-latest";
steps = [steps.CheckoutRepoStep(), steps.InstallGo(), steps.GolangciLint()];
steps = [
steps.CheckoutRepoStep(),
steps.InstallGo(),
...steps.GolangciLint(),
];
name: string;
if: NormalJob["if"];

constructor(name: string) {
this.name = name;
Object.assign(this, { name });
Object.assign(this, { name, steps: this.steps });
}

addDispatchConditional(isWorkflowDispatch: boolean) {
Expand Down

0 comments on commit 0bd42a4

Please sign in to comment.