Skip to content

Commit

Permalink
Merge pull request #1 from aspect-build/initial
Browse files Browse the repository at this point in the history
initial commit of working plugin
  • Loading branch information
alexeagle authored Nov 21, 2022
2 parents c654b50 + 0b5a5c3 commit f5f8ffc
Show file tree
Hide file tree
Showing 12 changed files with 301 additions and 313 deletions.
2 changes: 1 addition & 1 deletion .aspect/cli/plugins.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Configuration of plugins to the Aspect CLI
# See https://github.com/aspect-build/aspect-cli/blob/main/docs/help/topics/plugins.md
- name: hello-world
- name: fix-visibility
# This file is created by running `bazel build :dev` so that we can easily test local changes.
# Since the bazel-bin folder is in .gitignore, you'll get a warning on the first run.
# Users will install the plugin from a pre-built binary, using the instructions in the release notes.
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release_notes.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
To use this plugin, add it to your `.aspect/cli/plugins.yaml` file like so:

```
- name: hello-world
from: github.com/aspect-build/aspect-cli-plugin-template
- name: fix-visibility
from: github.com/aspect-build/plugin-fix-visibility
version: ${GITHUB_REF_NAME}
```
17 changes: 9 additions & 8 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ load("//release:release.bzl", "local_plugin")

# Run this target to update the go_* rules in this file
# bazel run //:gazelle
# gazelle:resolve go github.com/bazelbuild/buildtools/edit @com_github_bazelbuild_buildtools//edit:go_default_library
gazelle(name = "gazelle")

# Run this target to update the go.bzl file in this folder
Expand All @@ -18,19 +19,19 @@ gazelle(
command = "update-repos",
)

# gazelle:prefix github.com/aspect-build/aspect-cli-plugin-template
# gazelle:prefix github.com/aspect-build/plugin-fix-visibility
go_library(
name = "aspect-cli-plugin-template_lib",
name = "plugin-fix-visibility_lib",
srcs = ["plugin.go"],
importpath = "github.com/aspect-build/aspect-cli-plugin-template",
importpath = "github.com/aspect-build/plugin-fix-visibility",
visibility = ["//:__subpackages__"],
deps = [
"@bazel_gazelle//label:go_default_library",
"@build_aspect_cli//bazel/buildeventstream",
"@build_aspect_cli//bazel/command_line",
"@build_aspect_cli//pkg/bazel",
"@build_aspect_cli//pkg/ioutils",
"@build_aspect_cli//pkg/plugin/sdk/v1alpha3/config",
"@build_aspect_cli//pkg/plugin/sdk/v1alpha3/plugin",
"@com_github_bazelbuild_buildtools//edit:go_default_library",
"@com_github_hashicorp_go_plugin//:go-plugin",
"@com_github_manifoldco_promptui//:promptui",
],
Expand All @@ -39,15 +40,15 @@ go_library(
# Only used for local development.
# Release binaries are created by the target in /release
go_binary(
name = "aspect-cli-plugin-template",
embed = [":aspect-cli-plugin-template_lib"],
name = "plugin-fix-visibility",
embed = [":plugin-fix-visibility_lib"],
visibility = ["//visibility:public"],
)

# Copy the plugin to bazel-bin/plugin and checksum it.
# Referenced by the .aspect/cli/plugins.yaml in the `From:` line.
local_plugin(
name = "dev",
binary = ":aspect-cli-plugin-template",
binary = ":plugin-fix-visibility",
path = "plugin",
)
256 changes: 55 additions & 201 deletions LICENSE

Large diffs are not rendered by default.

41 changes: 13 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
# Template for aspect-cli plugins
# Fix-visibility plugin

This repo provides the fastest way to make a plugin for the [aspect cli].
This is a plugin for the [Aspect CLI].

It contains a plugin written in Go, with a GitHub actions CI/CD pipeline to release it.
It listens to Bazel's build event protocol and filters for the Aborted_ANALYSIS_FAILURE event.
If the Analysis Failure is due to a message containing `is not visible from target` this indicates
that the `visibility` attribute of a target doesn't include the package where our target is defined.

More details about aspect cli plugins is on the [plugin documentation].
After the build completes, the plugin offers to repair the problem by adding the missing `visibility` entry.

## Instructions
In this demo, we uncomment the `alias` target from `example/BUILD.bazel` and run `bazel build example` to see the failure.
The plugin offers to automatically add the missing entry to `visibility` of the `//:dev` target,
then we run the same build again, and it passes.
The demo then runs `git diff` so you can see what edit was made.

Create a new repo with the green "Use this template" button above.
Then in your repo...

1. Find-and-replace `hello_world` with your plugin name.
1. Find-and-replace `github.com/aspect-build/aspect-cli-plugin-template` with the name of your Go module. See <https://go.dev/doc/modules/developing>
1. Delete everything above the SNIP line below, and start coding on your features!

---------- %< SNIP %< ------------

# My Plugin

This is a plugin for the Aspect CLI.
[![asciicast](https://asciinema.org/a/1IRPgMQmhJC3L8RM1XTwRYUfa.svg)](https://asciinema.org/a/1IRPgMQmhJC3L8RM1XTwRYUfa)

## Developing

To try the plugin, first check that you have the most recent [aspect cli release] installed.
To try the plugin, first check that you have Aspect installed, by running `bazel version` and checking for
`Aspect CLI version` in the output.

First build the plugin from source:

Expand All @@ -35,16 +30,6 @@ Note that the `.aspect/cli/plugins.yaml` file has a reference to the path under
On the first build, you'll see a warning printed that the plugin doesn't exist at this path.
This is just the development flow for working on plugins; users will reference the plugin's releases which are downloaded for them automatically.

Now just run `aspect`. You should see that `hello-world` appears in the help output. This shows that our plugin was loaded and contributed a custom command to the CLI.

```
Usage:
aspect [command]
Custom Commands from Plugins:
hello-world Print 'Hello World!' to the command line.
```

## Releasing

Just push a tag to your GitHub repo.
Expand Down
5 changes: 5 additions & 0 deletions example/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Uncomment and build this package to see the feature work.
# alias(
# name = "example",
# actual = "//:dev",
# )
15 changes: 11 additions & 4 deletions go.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def deps():
go_repository(
name = "com_github_bazelbuild_rules_go",
importpath = "github.com/bazelbuild/rules_go",
sum = "h1:cmObMtgIOaEU944SqXtJ9DnlS8IPGGa7pdRnsrpQzXM=",
version = "v0.34.0",
sum = "h1:ViPR65vOrg74JKntAUFY6qZkheBKGB6to7wFd8gCRU4=",
version = "v0.35.0",
)
go_repository(
name = "com_github_bgentry_go_netrc",
Expand Down Expand Up @@ -236,8 +236,8 @@ def deps():
go_repository(
name = "com_github_google_go_cmp",
importpath = "github.com/google/go-cmp",
sum = "h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=",
version = "v0.5.8",
sum = "h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=",
version = "v0.5.9",
)
go_repository(
name = "com_github_google_martian",
Expand Down Expand Up @@ -740,6 +740,13 @@ def deps():
sum = "h1:7uVkIFmeBqHfdjD+gZwtXXI+RODJ2Wc4O7MPEh/QiW4=",
version = "v1.3.0",
)
go_repository(
name = "net_starlark_go",
importpath = "go.starlark.net",
sum = "h1:xwwDQW5We85NaTk2APgoN9202w/l0DVGp+GZMfsrh7s=",
version = "v0.0.0-20210223155950-e043a3d3c984",
)

go_repository(
name = "org_golang_google_api",
importpath = "google.golang.org/api",
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
module github.com/aspect-build/aspect-cli-plugin-template
module github.com/aspect-build/plugin-fix-visibility

go 1.19

require (
aspect.build/cli v1.0.1
github.com/bazelbuild/bazel-gazelle v0.28.0
github.com/bazelbuild/buildtools v0.0.0-20221004120235-7186f635531b
github.com/hashicorp/go-plugin v1.4.5
github.com/manifoldco/promptui v0.9.0
)
Expand Down
7 changes: 6 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/bazelbuild/bazel-gazelle v0.28.0 h1:sPdMMujcMt5jeSLGFko5yF1XBD5MDqm6YeFoXx9ORm4=
github.com/bazelbuild/bazel-gazelle v0.28.0/go.mod h1:5Qer6FCMBeotA8eQYJEPxn2eAbHmTApPxyd7aD4A0S8=
github.com/bazelbuild/bazelisk v1.13.2 h1:SpigbUorngcfDULmft0WkdrYVCqqqsFPEW4hm8UA+Gk=
github.com/bazelbuild/bazelisk v1.13.2/go.mod h1:jVD8/E7hMAXgWKCljEz8hOV0PZ+nFBgCpjIOJ6Xyzus=
github.com/bazelbuild/buildtools v0.0.0-20221004120235-7186f635531b h1:jhiMzJ+8unnLRtV8rpbWBFE9pFNzIqgUTyZU5aA++w8=
github.com/bazelbuild/buildtools v0.0.0-20221004120235-7186f635531b/go.mod h1:689QdV3hBP7Vo9dJMmzhoYIyo/9iMhEmHkJcnaPRCbo=
github.com/bazelbuild/rules_go v0.34.0/go.mod h1:MC23Dc/wkXEyk3Wpq6lCqz0ZAYOZDw2DR5y3N1q2i7M=
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas=
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4=
Expand Down Expand Up @@ -118,7 +122,7 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
Expand Down Expand Up @@ -230,6 +234,7 @@ go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
go.starlark.net v0.0.0-20210223155950-e043a3d3c984/go.mod h1:t3mmBBPzAVvK0L0n1drDmrQsJ8FoIx4INCqVMTr/Zo0=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand Down
Loading

0 comments on commit f5f8ffc

Please sign in to comment.