From 731299e05fe84ccb369fe452cba04d80e7c1b29c Mon Sep 17 00:00:00 2001 From: Jordan Barrett Date: Wed, 5 Jul 2023 14:58:58 +1200 Subject: [PATCH] Enforce import order using gci Add linting to the pre-merge checks to enforce Go import groups: - stdlib - 3rd-party / non-Pebble imports - Pebble imports --- .github/.golangci.yml | 14 ++++++++++++++ .github/workflows/lint.yml | 30 ++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 .github/.golangci.yml create mode 100644 .github/workflows/lint.yml diff --git a/.github/.golangci.yml b/.github/.golangci.yml new file mode 100644 index 00000000..3f49df42 --- /dev/null +++ b/.github/.golangci.yml @@ -0,0 +1,14 @@ +linters: + disable-all: true + enable: + - gci +linters-settings: + gci: + sections: + - standard + - default + - Prefix(github.com/canonical/pebble) +issues: + # these values ensure that all issues will be surfaced + max-issues-per-linter: 0 + max-same-issues: 0 \ No newline at end of file diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..6122d1ea --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,30 @@ +name: Lint +on: [push, pull_request] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-go@v4 + with: + go-mod-file: 'go.mod' + cache: false + + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + id: lint + with: + version: latest + args: '-c .github/.golangci.yml --out-format=colored-line-number' + skip-cache: true + + - name: Print error message + if: always() && steps.lint.outcome == 'failure' + run: | + echo ' + Linting failed. On your local machine, please run + golangci-lint run -c .github/.golangci.yml --fix + and check in the changes.' + exit 1 \ No newline at end of file