Skip to content

Commit

Permalink
🌱 add a verify rule for golang files import order
Browse files Browse the repository at this point in the history
This PR uses the [gci tool](https://github.com/daixiang0/gci) to make all go files' import section with a specific order, it will organize import with group with order:
1. standard library modules
2. 3rd party modules
3. modules in OCM org, like the `open-cluster-management.io/api`
4. current project `open-cluster-management.io/ocm` modules

developers can use the `make format-gofiles-import` to format the import automatically and the `make verify-gofiles-import-format` to check for any violation.

Signed-off-by: zhujian <jiazhu@redhat.com>
  • Loading branch information
zhujian7 committed Jun 8, 2023
1 parent 4c9dcc7 commit 574bd6a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
13 changes: 2 additions & 11 deletions .github/workflows/pre.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,10 @@ jobs:
go-version: ${{ env.GO_VERSION }}
- name: verify
run: make verify

verify-deps:
name: verify-deps
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v3
- name: install Go
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
- name: verify-deps
run: make verify-deps
- name: verify-gofiles-import-format
run: make verify-gofiles-import-format

build:
name: build
Expand Down
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ verify-gocilint:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.2
golangci-lint run --timeout=3m --modules-download-mode vendor ./...

install-golang-gci:
go install github.com/daixiang0/gci@v0.10.1

format-gofiles-import: install-golang-gci
gci write --skip-generated -s standard -s default -s "prefix(open-cluster-management.io)" -s "prefix(open-cluster-management.io/ocm)" cmd pkg test dependencymagnet

verify-gofiles-import-format: install-golang-gci
@output=$$(gci diff --skip-generated -s standard -s default -s "prefix(open-cluster-management.io)" -s "prefix(open-cluster-management.io/ocm)" cmd pkg test dependencymagnet); \
if [ -n "$$output" ]; then \
echo "Diff output is not empty: $$output"; \
exit 1; \
else \
echo "Diff output is empty"; \
fi

verify: verify-crds

ensure-operator-sdk:
Expand Down

0 comments on commit 574bd6a

Please sign in to comment.