Skip to content

Commit ac8c7ab

Browse files
committed
Feat: add golangci-lint ci
Signed-off-by: fengshunli <[email protected]>
1 parent d7db7c6 commit ac8c7ab

File tree

3 files changed

+132
-0
lines changed

3 files changed

+132
-0
lines changed

.github/workflows/ci.yaml

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- develop
8+
- release-*
9+
pull_request: {}
10+
workflow_dispatch: {}
11+
12+
env:
13+
GO_VERSION: 1.18
14+
15+
jobs:
16+
17+
verify:
18+
runs-on: ubuntu-22.04
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v3
22+
- name: Verify Code
23+
run: make verify
24+
25+
golangci-lint:
26+
runs-on: ubuntu-22.04
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v3
30+
with:
31+
submodules: true
32+
- name: Setup Go
33+
uses: actions/setup-go@v4
34+
with:
35+
go-version: ${{ env.GO_VERSION }}
36+
- name: Lint golang code
37+
uses: golangci/golangci-lint-action@v3
38+
with:
39+
version: v1.47.3
40+
args: -v
41+
skip-cache: true
42+
43+
markdownlint-misspell-shellcheck:
44+
runs-on: ubuntu-22.04
45+
# this image is build from Dockerfile
46+
# https://github.com/pouchcontainer/pouchlinter/blob/master/Dockerfile
47+
container: pouchcontainer/pouchlinter:v0.1.2
48+
steps:
49+
- name: Checkout
50+
uses: actions/checkout@v3
51+
- name: Run misspell
52+
run: find ./* -name "*" | xargs misspell -error
53+
- name: Lint markdown files
54+
run: find ./ -name "*.md" | grep -v enhancements | grep -v .github | xargs mdl -r ~MD010,~MD013,~MD022,~MD024,~MD029,~MD031,~MD032,~MD033,~MD034,~MD036
55+
56+
unit-tests:
57+
runs-on: ubuntu-22.04
58+
steps:
59+
- uses: actions/checkout@v3
60+
with:
61+
submodules: true
62+
- name: Fetch History
63+
run: git fetch --prune --unshallow
64+
- name: Setup Go
65+
uses: actions/setup-go@v4
66+
with:
67+
go-version: ${{ env.GO_VERSION }}
68+
- name: Cache Go Dependencies
69+
uses: actions/cache@v3
70+
with:
71+
path: ~/go/pkg/mod
72+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
73+
restore-keys: ${{ runner.os }}-go-
74+
- name: Run Unit Tests
75+
run: make test
76+
- name: Publish Unit Test Coverage
77+
if: github.repository == 'opencurve/curveadm'
78+
uses: codecov/codecov-action@v3
79+
with:
80+
name: codecov-umbrella
81+
token: ${{ secrets.CODECOV_TOKEN }}
82+
flags: unittests
83+
files: ./cover.out
84+
fail_ci_if_error: true
85+
verbose: true
86+
e2e-tests:
87+
runs-on: ubuntu-22.04
88+
steps:
89+
- uses: actions/checkout@v3
90+
with:
91+
fetch-depth: 0
92+
- uses: actions/setup-go@v4
93+
with:
94+
go-version: ${{ env.GO_VERSION }}
95+
- uses: actions/cache@v3
96+
with:
97+
path: ~/go/pkg/mod
98+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
99+
restore-keys: ${{ runner.os }}-go-
100+
101+
- name: Run e2e Tests
102+
run: make e2e-tests

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,6 @@ test:
6363

6464
upload:
6565
@NOSCMD=$(NOSCMD) bash build/package/upload.sh $(VERSION)
66+
67+
verify:
68+
scripts/verify_mod.sh

scripts/verify_mod.sh

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2022 The OpenYurt Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -e
18+
set -u
19+
20+
YURT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
21+
22+
go mod tidy
23+
24+
if [ ! -z "$(git diff ${YURT_ROOT}/go.mod ${YURT_ROOT}/go.sum)" ]; then
25+
echo "Verify go mod error, please ensure go.mod has been tidied"
26+
exit -1
27+
fi

0 commit comments

Comments
 (0)