Skip to content

Commit cfc7d1a

Browse files
committed
BUILD/MINOR: add checks if the code is formatted
1 parent e0c05d7 commit cfc7d1a

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

.github/workflows/lint.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@ on:
44
branches:
55
- master
66
jobs:
7+
gofumpt:
8+
name: gofumpt
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Check out code
12+
uses: actions/checkout@v2
13+
- name: Set up Go
14+
uses: actions/setup-go@v2
15+
with:
16+
go-version: 1.19
17+
- uses: actions/cache@v2
18+
with:
19+
path: |
20+
~/.cache/go-build
21+
~/go/pkg/mod
22+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
23+
restore-keys: |
24+
${{ runner.os }}-go-
25+
- name: tidy
26+
run: make gofumpt
27+
- name: changes
28+
run: test -z "$(git diff 2> /dev/null)" || exit "Go code not formatted, issue \`make gofumpt\` and commit the result"
729
golangci-lint:
830
name: golangci-lint
931
runs-on: ubuntu-latest

.gitlab-ci.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ diff:
2727
- make generate-native
2828
- test -z "$(git diff 2> /dev/null)" || exit "Specification is not generated, issue \`make generate\` and commit the result"
2929
- test -z "$(git ls-files --others --exclude-standard 2> /dev/null)" || exit "Specification generation created untracked files, cannot proceed"
30-
3130
golangci-lint:
3231
stage: lint
3332
artifacts:
@@ -43,6 +42,19 @@ golangci-lint:
4342
rules:
4443
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
4544
- if: $CI_PIPELINE_SOURCE == 'push'
45+
gofumpt:
46+
stage: lint
47+
rules:
48+
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
49+
- if: $CI_PIPELINE_SOURCE == 'push'
50+
image:
51+
name: $CI_REGISTRY_GO/golang:1.19
52+
entrypoint: [""]
53+
tags:
54+
- go
55+
script:
56+
- make gofumpt
57+
- test -z "$(git diff 2> /dev/null)" || exit 'Go code not formatted, issue \`make gofumpt\` and commit the result'
4658
lint-commit-msg:
4759
stage: lint
4860
image:

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ lint:
2121
cd bin;GOLANGCI_LINT_VERSION=${GOLANGCI_LINT_VERSION} sh lint-check.sh
2222
bin/golangci-lint run --timeout 5m --color always --max-issues-per-linter 0 --max-same-issues 0
2323

24+
.PHONY: gofumpt
25+
gofumpt:
26+
go install mvdan.cc/gofumpt@latest
27+
gofumpt -l -w .
28+
2429
clean:
2530
rm -rf ${DATAPLANEAPI_PATH}/build
2631

0 commit comments

Comments
 (0)