diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 766c8ec03..431877821 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,8 +32,10 @@ jobs: path: .cache/bazel-repo key: bazel-repo - name: Validate changed files - if: github.event_name == 'pull_request' + if: github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'allow sdk change') run: ./.github/workflows/validate_changed_files.sh ${{ github.head_ref }} ${{ github.base_ref }} + - name: Tidy up repository + run: ./.github/workflows/tidy_up_repository.sh - name: bazel test //... env: XDG_CACHE_HOME: .cache/bazel-repo diff --git a/.github/workflows/tidy_up_repository.sh b/.github/workflows/tidy_up_repository.sh new file mode 100755 index 000000000..eaf6eb445 --- /dev/null +++ b/.github/workflows/tidy_up_repository.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +set -o errexit -o nounset -o pipefail + +# First verify if the repository is clean. +if ! git diff --exit-code; then + >&2 echo "ERROR: The repository is not clean - please verify the changes and fix them." + exit 1 +fi + +# Then, run a series of commands that could produce changes to the source tree. +# For each command, we check if the repository is still clean and proceed. +commands=( + "bazel run @go_sdk//:bin/go -- fmt \$(go list ./... | grep -v /bazel-/)" + "bazel run @go_sdk//:bin/go -- mod tidy" + "bazel run //:update_go_deps" + "bazel run //:gazelle" +) + +for cmd in "${commands[@]}"; do + /bin/bash -c "${cmd}" + if ! git diff --exit-code; then + >&2 echo "ERROR: Please run '${cmd}' and commit the changes." + exit 1 + fi +done diff --git a/BUILD.bazel b/BUILD.bazel index 6e2b31182..5000aa53f 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,4 +1,12 @@ load("@bazel_gazelle//:def.bzl", "gazelle") +load("@io_bazel_rules_go//go:def.bzl", "TOOLS_NOGO", "nogo") + +nogo( + name = "nogo", + config = "nogo_config.json", + visibility = ["//visibility:public"], + deps = TOOLS_NOGO, +) # TODO: follow https://sagikazarmark.hu/blog/vanity-import-paths-in-go/ # so we have savvy go imports for users diff --git a/WORKSPACE b/WORKSPACE index 971c02a1b..872ef09d2 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -68,7 +68,10 @@ go_rules_dependencies() go_embed_data_dependencies() -go_register_toolchains(version = "1.17.5") +go_register_toolchains( + version = "1.17.5", + nogo = "@//:nogo", +) gazelle_dependencies() diff --git a/nogo_config.json b/nogo_config.json new file mode 100644 index 000000000..6c10cfe5a --- /dev/null +++ b/nogo_config.json @@ -0,0 +1,38 @@ +{ + "composites": { + "exclude_files": { + "(third_party|vendor|external)/.*": "only run for first-party code" + } + }, + "copylocks": { + "exclude_files": { + "(third_party|vendor|external)/.*": "only run for first-party code" + } + }, + "nilness": { + "exclude_files": { + "(third_party|vendor|external)/.*": "only run for first-party code" + } + }, + "shadow": { + "exclude_files": { + "(third_party|vendor|external)/.*": "only run for first-party code", + "pkg/bazel/bazelisk.go": "copied third-party code" + } + }, + "stdmethods": { + "exclude_files": { + "(third_party|vendor|external)/.*": "only run for first-party code" + } + }, + "unreachable": { + "exclude_files": { + "(third_party|vendor|external)/.*": "only run for first-party code" + } + }, + "unsafeptr": { + "exclude_files": { + "(third_party|vendor|external)/.*": "only run for first-party code" + } + } +} diff --git a/pkg/interceptors/workspace_test.go b/pkg/interceptors/workspace_test.go index eb40c48c1..d1e01f0a5 100644 --- a/pkg/interceptors/workspace_test.go +++ b/pkg/interceptors/workspace_test.go @@ -106,8 +106,8 @@ func TestWorkspaceRootInterceptor(t *testing.T) { cmd := &cobra.Command{Use: "fake"} args := []string{"foo", "bar"} next := func(_ctx context.Context, _cmd *cobra.Command, _args []string) error { - ctx := context.WithValue(ctx, WorkspaceRootKey, expectedWorkspaceRoot) - g.Expect(_ctx).To(Equal(ctx)) + ctxWithWorkspace := context.WithValue(ctx, WorkspaceRootKey, expectedWorkspaceRoot) + g.Expect(_ctx).To(Equal(ctxWithWorkspace)) g.Expect(_cmd).To(Equal(cmd)) g.Expect(_args).To(Equal(args)) return nil diff --git a/pkg/plugin/sdk/v1alpha1/proto/BUILD.bazel b/pkg/plugin/sdk/v1alpha1/proto/BUILD.bazel index fba85b5b5..6ea1935e7 100644 --- a/pkg/plugin/sdk/v1alpha1/proto/BUILD.bazel +++ b/pkg/plugin/sdk/v1alpha1/proto/BUILD.bazel @@ -2,6 +2,8 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library") load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") load("@rules_proto//proto:defs.bzl", "proto_library") +# gazelle:exclude dummy.go + proto_library( name = "proto_proto", srcs = ["plugin.proto"], diff --git a/pkg/plugin/sdk/v1alpha1/proto/dummy.go b/pkg/plugin/sdk/v1alpha1/proto/dummy.go index 7ecf3b15f..39c829766 100644 --- a/pkg/plugin/sdk/v1alpha1/proto/dummy.go +++ b/pkg/plugin/sdk/v1alpha1/proto/dummy.go @@ -1,6 +1,3 @@ -//go:build dummy -// +build dummy - // This file exists to make the go tooling happy. This package is generated by // bazel. package proto diff --git a/pkg/plugin/sdk/v1alpha2/proto/BUILD.bazel b/pkg/plugin/sdk/v1alpha2/proto/BUILD.bazel index f4a33c018..166eb81d5 100644 --- a/pkg/plugin/sdk/v1alpha2/proto/BUILD.bazel +++ b/pkg/plugin/sdk/v1alpha2/proto/BUILD.bazel @@ -2,6 +2,8 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library") load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") load("@rules_proto//proto:defs.bzl", "proto_library") +# gazelle:exclude dummy.go + proto_library( name = "proto_proto", srcs = ["plugin.proto"], diff --git a/pkg/plugin/sdk/v1alpha2/proto/dummy.go b/pkg/plugin/sdk/v1alpha2/proto/dummy.go index 7ecf3b15f..39c829766 100644 --- a/pkg/plugin/sdk/v1alpha2/proto/dummy.go +++ b/pkg/plugin/sdk/v1alpha2/proto/dummy.go @@ -1,6 +1,3 @@ -//go:build dummy -// +build dummy - // This file exists to make the go tooling happy. This package is generated by // bazel. package proto