github.com/ungtb10d/cli/v2@v2.0.0-20221110210412-98537dd9d6a1/.github/workflows/lint.yml (about) 1 name: Lint 2 on: 3 push: 4 paths: 5 - "**.go" 6 - go.mod 7 - go.sum 8 pull_request: 9 paths: 10 - "**.go" 11 - go.mod 12 - go.sum 13 14 permissions: 15 contents: read 16 17 jobs: 18 lint: 19 runs-on: ubuntu-latest 20 21 steps: 22 - name: Set up Go 1.18 23 uses: actions/setup-go@v3 24 with: 25 go-version: 1.18 26 27 - name: Check out code 28 uses: actions/checkout@v3 29 30 - name: Restore Go modules cache 31 uses: actions/cache@v3 32 with: 33 path: ~/go/pkg/mod 34 key: go-${{ runner.os }}-${{ hashFiles('go.mod') }} 35 restore-keys: | 36 go-${{ runner.os }}- 37 38 - name: Verify dependencies 39 run: | 40 go mod verify 41 go mod download 42 43 LINT_VERSION=1.46.0 44 curl -fsSL https://github.com/golangci/golangci-lint/releases/download/v${LINT_VERSION}/golangci-lint-${LINT_VERSION}-linux-amd64.tar.gz | \ 45 tar xz --strip-components 1 --wildcards \*/golangci-lint 46 mkdir -p bin && mv golangci-lint bin/ 47 48 - name: Run checks 49 run: | 50 STATUS=0 51 assert-nothing-changed() { 52 local diff 53 "$@" >/dev/null || return 1 54 if ! diff="$(git diff -U1 --color --exit-code)"; then 55 printf '\e[31mError: running `\e[1m%s\e[22m` results in modifications that you must check into version control:\e[0m\n%s\n\n' "$*" "$diff" >&2 56 git checkout -- . 57 STATUS=1 58 fi 59 } 60 61 assert-nothing-changed go fmt ./... 62 assert-nothing-changed go mod tidy 63 64 bin/golangci-lint run --out-format=github-actions --timeout=3m || STATUS=$? 65 66 exit $STATUS