Skip to content

Commit

Permalink
CI: Add pre-commit linters, autoformatters (#299)
Browse files Browse the repository at this point in the history
* Add pre-commit linters, formatters

Signed-off-by: Yuki Sawa <[email protected]>

* add descriptive name for fail msg step

Signed-off-by: Yuki Sawa <[email protected]>

* shorten precommit makefile cmd

Signed-off-by: Yuki Sawa <[email protected]>

* make fix_format

Signed-off-by: Yuki Sawa <[email protected]>

* autoformat all lint errs

Signed-off-by: Yuki Sawa <[email protected]>

* backtick quote to avoid formatter

Signed-off-by: Yuki Sawa <[email protected]>

* add shfmt for bash linting

Signed-off-by: Yuki Sawa <[email protected]>
  • Loading branch information
ysawa0 authored Oct 5, 2021
1 parent 1c1d46e commit 21fc4d3
Show file tree
Hide file tree
Showing 64 changed files with 552 additions and 339 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
- uses: actions/checkout@v2
- name: check format
run: make check_format

build:
runs-on: ubuntu-latest
steps:
Expand All @@ -25,3 +26,22 @@ jobs:
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}

precommits:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- uses: actions/setup-python@v2
with:
python-version: "3.9"

- uses: actions/setup-go@v2
with:
go-version: "1.16"

- name: run pre-commits
run: |
make precommit_install
pre-commit run -a
30 changes: 29 additions & 1 deletion .github/workflows/pullrequest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,44 @@ on:
jobs:
check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: check format
run: make check_format

build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: build and test
run: make docker_tests

precommits:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- uses: actions/setup-python@v2
with:
python-version: "3.9"

- uses: actions/setup-go@v2
with:
go-version: "1.16"

- name: run pre-commits
run: |
make precommit_install
pre-commit run -a
# If previous stage fails, print resolution steps
- if: ${{ failure() }}
name: Read for resolution steps
run: |
make docker_tests
echo "Pre-commits failed! Run 'make precommit_install' then 'pre-commits run -a' to fix."
exit 1
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Build and push :release image
on:
push:
tags:
- 'v*'
- "v*"

jobs:
check:
Expand All @@ -23,4 +23,4 @@ jobs:
make docker_push
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
64 changes: 32 additions & 32 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
on:
workflow_dispatch:
schedule:
- cron: '0 */4 * * *'
- cron: "0 */4 * * *"

jobs:
prune_stale:
name: Prune Stale
runs-on: ubuntu-latest

steps:
- name: Prune Stale
uses: actions/[email protected]
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
# Different amounts of days for issues/PRs are not currently supported but there is a PR
# open for it: https://github.com/actions/stale/issues/214
days-before-stale: 30
days-before-close: 7
stale-issue-message: >
This issue has been automatically marked as stale because it has not had activity in the
last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or "no stalebot" or other activity
occurs. Thank you for your contributions.
close-issue-message: >
This issue has been automatically closed because it has not had activity in the
last 37 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted" or "no stalebot".
Thank you for your contributions.
stale-pr-message: >
This pull request has been automatically marked as stale because it has not had
activity in the last 30 days. It will be closed in 7 days if no further activity occurs. Please
feel free to give a status update now, ping for review, or re-open when it's ready.
Thank you for your contributions!
close-pr-message: >
This pull request has been automatically closed because it has not had
activity in the last 37 days. Please feel free to give a status update now, ping for review, or re-open when it's ready.
Thank you for your contributions!
stale-issue-label: 'stale'
exempt-issue-labels: 'no stalebot,help wanted'
stale-pr-label: 'stale'
exempt-pr-labels: 'no stalebot'
operations-per-run: 500
ascending: true
- name: Prune Stale
uses: actions/[email protected]
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
# Different amounts of days for issues/PRs are not currently supported but there is a PR
# open for it: https://github.com/actions/stale/issues/214
days-before-stale: 30
days-before-close: 7
stale-issue-message: >
This issue has been automatically marked as stale because it has not had activity in the
last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or "no stalebot" or other activity
occurs. Thank you for your contributions.
close-issue-message: >
This issue has been automatically closed because it has not had activity in the
last 37 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted" or "no stalebot".
Thank you for your contributions.
stale-pr-message: >
This pull request has been automatically marked as stale because it has not had
activity in the last 30 days. It will be closed in 7 days if no further activity occurs. Please
feel free to give a status update now, ping for review, or re-open when it's ready.
Thank you for your contributions!
close-pr-message: >
This pull request has been automatically closed because it has not had
activity in the last 37 days. Please feel free to give a status update now, ping for review, or re-open when it's ready.
Thank you for your contributions!
stale-issue-label: "stale"
exempt-issue-labels: "no stalebot,help wanted"
stale-pr-label: "stale"
exempt-pr-labels: "no stalebot"
operations-per-run: 500
ascending: true
31 changes: 31 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
default_language_version:
python: python3
repos:
- repo: https://github.com/tekwizely/pre-commit-golang
rev: v1.0.0-beta.4
hooks:
- id: go-imports
args: ["-w", "-local", "github.com/envoyproxy/ratelimit"]
- id: go-fumpt
args: ["-w"]

- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v2.4.1"
hooks:
- id: prettier
exclude: "test/config/bad_yaml.yaml"

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-json
- id: check-merge-conflict
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 2.1.5
hooks:
- id: shfmt
1 change: 1 addition & 0 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
singleQuote: false
21 changes: 16 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@ We welcome contributions from the community. Here are some guidelines.

# Coding style

* Ratelimit uses golang's `fmt` too.
- Ratelimit uses [gofumpt](https://github.com/mvdan/gofumpt) and [goimports](https://pkg.go.dev/golang.org/x/tools/cmd/goimports) for Go styling.

# Submitting a PR

* Fork the repo and create your PR.
* Tests will automatically run for you.
* When all of the tests are passing, tag @envoyproxy/ratelimit-maintainers and
- Fork the repo.
- Before commiting any code, install the pre-commits by:

```bash
make precommit_install
# Example usage if you want to run it manually
pre-commit run # Run against staged changes
pre-commit run -a # Run against all files
```

- Pre-commits will automatically format your code at commit time.
- Create your PR.
- Tests will automatically run for you.
- When all of the tests are passing, tag @envoyproxy/ratelimit-maintainers and
we will review it and merge.
* Party time.
- Party time.

# DCO: Sign your work

Expand Down
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,14 @@ docker_image: docker_tests
docker_push: docker_image
docker push $(IMAGE):$(VERSION)

.PHONY: integration-tests
integration-tests:
.PHONY: integration_tests
integration_tests:
docker-compose --project-dir $(PWD) -f integration-test/docker-compose-integration-test.yml up --build --exit-code-from tester

# docker-compose --project-dir $(PWD) -f integration-test/docker-compose-integration-test.yml up --build --exit-code-from tester
.PHONY: precommit_install
precommit_install:
python3 -m pip install -r requirements-dev.txt
go install mvdan.cc/[email protected]
go install mvdan.cc/sh/v3/cmd/shfmt@latest
go install golang.org/x/tools/cmd/[email protected]
pre-commit install
4 changes: 2 additions & 2 deletions OWNERS.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
* Matt Klein ([mattklein123](https://github.com/mattklein123)) ([email protected])
* Yuki Sawa ([ysawa0](https://github.com/ysawa0)) ([email protected])
- Matt Klein ([mattklein123](https://github.com/mattklein123)) ([email protected])
- Yuki Sawa ([ysawa0](https://github.com/ysawa0)) ([email protected])
Loading

0 comments on commit 21fc4d3

Please sign in to comment.