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

Contribution docs #36

Merged
merged 15 commits into from
Dec 11, 2024
48 changes: 22 additions & 26 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,39 @@
# Contributing

First of all, thank you for your interest in contributing to this project.
Thank you for your interest in contributing to this project!

Before creating a pull request, please read and follow this contributing guide.
Before participating in this project's activities, please read and follow [code of conduct](https://github.com/buildkite-plugins/monorepo-diff-buildkite-plugin/blob/master/CODE_OF_CONDUCT.md).
Before opening a pull request, please review and follow the guidelines outlined in this document. Additionally, be sure to read our [Code of Conduct](https://github.com/buildkite-plugins/monorepo-diff-buildkite-plugin/blob/master/CODE_OF_CONDUCT.md) to understand expected behavior within the project.

Please create an [issue](https://github.com/buildkite-plugins/monorepo-diff-buildkite-plugin/issues) before submitting a pull request. If it is a proposal for a new feature or changing existing functionality, initiate a discussion with maintainers first. If it's a fix for know bugs, a discussion is not required.
If you plan to submit a pull request, we ask that you first create an [issue](https://github.com/buildkite-plugins/monorepo-diff-buildkite-plugin/issues). For new features or modifications to existing functionality, please start a discussion with the maintainers. For straightforward bug fixes, an issue is enough without a preliminary discussion.

## Developing

- [Install Go.](https://golang.org/doc/install)
- The project uses Makefile. Install `make` command.
- Fork this repository.
- Clone the forked repository.
- Make changes (see [Formatting](https://github.com/buildkite-plugins/monorepo-diff-buildkite-plugin/blob/master/CONTRIBUTING.md#formatting)) and commit to your fork. Commit messages should follow the [Conventional Commits](https://www.conventionalcommits.org/) style.
- Add appropriate unit tests (see [Testing](https://github.com/buildkite-plugins/monorepo-diff-buildkite-plugin/blob/master/CONTRIBUTING.md#testing)) for your changes.
- Update documentation if appropriate.
- Create a pull request with your changes.
- Github action will run the necessary checks against your pull request.
- A maintainer will review the pull request once all checks are
- A maintainer will merge and create a release (see [Releasing](https://github.com/buildkite-plugins/monorepo-diff-buildkite-plugin/blob/master/CONTRIBUTING.md#releasing)).
To get started with development:

- [Install Go](https://golang.org/doc/install).
- Ensure you have `make` installed, as this project uses a Makefile.
- Fork this repository and clone your fork locally.
- Make your changes (see [Formatting](https://github.com/buildkite-plugins/monorepo-diff-buildkite-plugin/blob/master/CONTRIBUTING.md#formatting)) and commit to your fork. Use [Conventional Commits](https://www.conventionalcommits.org/) style for commit messages.
- Add relevant unit tests (see [Testing](https://github.com/buildkite-plugins/monorepo-diff-buildkite-plugin/blob/master/CONTRIBUTING.md#testing)) for your changes.
- Update documentation if necessary.
- Open a pull request, a maintainer will assist in reviewing the pull request
- After review and approval, a maintainer will merge your pull request and create a release (see [Releasing](https://github.com/buildkite-plugins/monorepo-diff-buildkite-plugin/blob/master/CONTRIBUTING.md#releasing)).

## Testing

All changes must be unit tested and meet the project test coverage threshold (73%) requirement.
Run `make test` to run all tests and generate coverage reports before submitting a pull request.
All changes must be unit tested, and test coverage should meet the project's minimum threshold of 73%. Run `make test` to execute all tests and generate coverage reports before submitting a pull request.
jeremybumsted marked this conversation as resolved.
Show resolved Hide resolved

To write the `bats` tests for plugin,
1. Modify the tests
2. Run `docker-compose build plugin_test && docker-compose run --rm plugin_test`
For `bats` plugin tests:
1. Modify the tests as needed.
2. Run `make build-docker-test && make test-docker` to build the Docker image and execute the tests within the Docker container.

## Formatting

All code must be formatted with `gofmt` (with the latest Go version) and pass `go vet`. The plugin must be linted with [buildkite-plugin-linter](https://github.com/buildkite-plugins/buildkite-plugin-linter). Run `make quality` to run all formatting checks.
Please format all code with `gofmt` using the latest version of Go and ensure it passes `go vet`. Additionally, the plugin must be linted with the [buildkite-plugin-linter](https://github.com/buildkite-plugins/buildkite-plugin-linter).

## Releasing

One of the maintainers will create a release after merging the pull request.
- Ensure documentation is updated appropriately.
- Update all occurrences of plugin version in [README.md]( https://github.com/buildkite-plugins/monorepo-diff-buildkite-plugin/blob/master/README.md ).
- create and push the next tag version
- Github actions will automatically create the release.
Once a pull request is merged, a maintainer will create a new release:
- Confirm that documentation is updated as needed.
- Update all plugin version references in [README.md](https://github.com/buildkite-plugins/monorepo-diff-buildkite-plugin/blob/master/README.md).
- Create and push a new version tag.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ test-go:
.PHONY: build-docker-test
build-docker-test:
ifneq (${HAS_DOCKER},)
docker-compose build plugin_test
docker build -t ${NAME} -f tests/Dockerfile .
endif

.PHONY: test-docker
test-docker: build-docker-test
ifneq (${HAS_DOCKER},)
docker-compose run --rm plugin_test
docker run --rm ${NAME} go test -race -coverprofile=coverage.out -covermode=atomic
endif

.PHONY: test
Expand All @@ -31,7 +31,7 @@ quality:
go fmt
go mod tidy
ifneq (${HAS_DOCKER},)
docker-compose run --rm plugin_lint
docker run --rm buildkite/plugin-linter:latest --id buildkite-plugins/monorepo-diff
endif

.PHONY: build
Expand Down
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Configuration supports 2 different step types.
steps:
- label: "Triggering pipelines"
plugins:
- monorepo-diff#v1.1.0:
- monorepo-diff#v1.2.0:
diff: "git diff --name-only HEAD~1"
watch:
- path: app/
Expand All @@ -76,7 +76,7 @@ steps:
steps:
- label: "Triggering pipelines with plugin"
plugins:
- monorepo-diff#v1.1.0:
- monorepo-diff#v1.2.0:
watch:
- path: test/.buildkite/
config: # Required [trigger step configuration]
Expand Down Expand Up @@ -143,7 +143,7 @@ git diff --name-only "$LATEST_TAG"
steps:
- label: "Triggering pipelines"
plugins:
- monorepo-diff#v1.1.0:
- monorepo-diff#v1.2.0:
diff: "git diff --name-only HEAD~1"
watch:
- path: "bar-service/"
Expand All @@ -170,7 +170,7 @@ A default `config` to run if no paths are matched, the `config` key is not reuir
steps:
- label: "Triggering pipelines"
plugins:
- monorepo-diff#v1.1.0:
- monorepo-diff#v1.2.0:
diff: "git diff --name-only HEAD~1"
watch:
- path: "bar-service/"
Expand All @@ -192,7 +192,7 @@ The object values provided in this configuration will be appended to `env` prope
steps:
- label: "Triggering pipelines"
plugins:
- monorepo-diff#v1.1.0:
- monorepo-diff#v1.2.0:
diff: "git diff --name-only HEAD~1"
watch:
- path: "foo-service/"
Expand All @@ -214,7 +214,7 @@ Add `log_level` property to set the log level. Supported log levels are `debug`
steps:
- label: "Triggering pipelines"
plugins:
- monorepo-diff#v1.1.0:
- monorepo-diff#v1.2.0:
diff: "git diff --name-only HEAD~1"
log_level: "debug" # defaults to "info"
watch:
Expand Down Expand Up @@ -245,7 +245,7 @@ By setting `wait` to `true`, the build will wait until the triggered pipeline bu
steps:
- label: "Triggering pipelines"
plugins:
- monorepo-diff#v1.1.0:
- monorepo-diff#v1.2.0:
diff: "git diff --name-only $(head -n 1 last_successful_build)"
interpolation: false
env:
Expand Down Expand Up @@ -291,3 +291,8 @@ Thanks to [@chronotc](https://github.com/chronotc) and [Monebag](https://github.
## License

MIT (see [LICENSE](LICENSE))


## How to Contribute

Please read [contributing guide](https://github.com/buildkite-plugins/monorepo-diff-buildkite-plugin/blob/master/CONTRIBUTING.md).
4 changes: 2 additions & 2 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,11 @@ func parseEnv(raw interface{}) (map[string]string, error) {

func getPluginName(s string) string {
ref := s
if strings.HasPrefix(ref, "github.com/") && ! strings.Contains(ref, "://") {
if strings.HasPrefix(ref, "github.com/") && !strings.Contains(ref, "://") {
ref = "https://" + ref
}

u, err := url.Parse(ref);
u, err := url.Parse(ref)
// if URL could not be parsed, assume it is a direct reference
if err != nil {
return s
Expand Down
28 changes: 22 additions & 6 deletions tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
FROM goreleaser/goreleaser:v1.13.1-amd64 as go
# Stage 1: Build the Go plugin using Goreleaser
FROM goreleaser/goreleaser:v2.3.0-amd64 as go

WORKDIR /plugin

COPY . .

RUN goreleaser build --rm-dist --skip-validate --config .goreleaser-test.yml
RUN goreleaser build --clean --skip=validate --config .goreleaser-test.yml

FROM buildkite/plugin-tester
# Stage 2: Lint the plugin using Buildkite plugin-linter
FROM buildkite/plugin-linter:latest as linter

WORKDIR /plugin

# Copy the plugin code from the previous stage to lint it
COPY --from=go /plugin /plugin

# Run the Buildkite plugin linter to validate the plugin
RUN plugin-linter --id buildkite-plugins/monorepo-diff

# Stage 3: Final image for testing the plugin
FROM golang:1.20 as test-stage

WORKDIR /plugin

# Copy the plugin code and artifacts from previous stages
COPY --from=go /plugin /plugin
COPY tests /plugin/tests
COPY hooks /plugin/hooks

COPY --from=go \
/plugin/dist/monorepo-diff-buildkite-plugin_linux_amd64_v1/monorepo-diff-buildkite-plugin \
monorepo-diff-buildkite-plugin
# Run the plugin tests
CMD ["go", "test", "-race", "-coverprofile=coverage.out", "-covermode=atomic"]