Skip to content

Commit 1d2b146

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

File tree

3 files changed

+134
-0
lines changed

3 files changed

+134
-0
lines changed

.github/workflows/ci.yaml

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