Skip to content

Commit 1eefe68

Browse files
committed
feat: workflow and configuration
1 parent 6079794 commit 1eefe68

File tree

3 files changed

+126
-2
lines changed

3 files changed

+126
-2
lines changed

.github/workflows/basic.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: golangci-lint
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
linter:
13+
name: golangci-lint
14+
runs-on: ${{ matrix.os }}
15+
strategy:
16+
matrix:
17+
go-version: ['1.20', 1.x ]
18+
os: [ubuntu-latest, macos-latest] # Go plugins are only supported on linux, freebsd, and darwin.
19+
env:
20+
CGO_ENABLED: 0
21+
steps:
22+
- uses: actions/checkout@v3
23+
- uses: actions/setup-go@v4
24+
with:
25+
go-version: '1.20'
26+
cache: false
27+
28+
- name: Cache Go modules
29+
uses: actions/cache@v3
30+
with:
31+
# In order:
32+
# * Module download cache
33+
# * Build cache (Linux)
34+
# * Build cache (Mac)
35+
path: |
36+
~/go/pkg/mod
37+
~/.cache/go-build
38+
~/Library/Caches/go-build
39+
key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum') }}
40+
restore-keys: |
41+
${{ runner.os }}-${{ matrix.go-version }}-go-
42+
43+
- name: Check and get dependencies
44+
run: |
45+
go mod tidy
46+
git diff --exit-code go.mod
47+
# git diff --exit-code go.sum
48+
49+
- name: Install plugins
50+
run: |
51+
git clone https://github.com/golangci/example-plugin-linter.git
52+
cd example-plugin-linter
53+
go build -o '${{ github.workspace }}/.plugins/example.so' -buildmode=plugin plugin/example.go
54+
working-directory: ${{ runner.temp }}
55+
env:
56+
CGO_ENABLED: 1
57+
58+
- name: golangci-lint
59+
uses: golangci/golangci-lint-action@v3
60+
with:
61+
version: v1.53.2
62+
# The installation mode `goinstall` always uses `CGO_ENABLED=1`.
63+
install-mode: goinstall
64+
args: --timeout=10m
65+
66+
- name: Test
67+
run: go test -v -cover ./...
68+
69+
- name: Build
70+
run: go build -v -ldflags "-s -w" -trimpath

.golangci.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
run:
2+
timeout: 10m
3+
skip-files: []
4+
5+
linters-settings:
6+
custom:
7+
example:
8+
# Path to the `.so` file of the plugin
9+
path: .plugins/example.so
10+
# Only used for documentation purposes.
11+
description: The description of the linter. Shows up when running `golangci-lint linters`.
12+
# Only used for documentation purposes.
13+
original-url: github.com/golangci/example-linter
14+
15+
linters:
16+
disable-all: true
17+
enable:
18+
- example
19+
- typecheck
20+
21+
issues:
22+
exclude-use-default: false
23+
max-per-linter: 0
24+
max-same-issues: 0
25+

readme.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1-
# Golangci-lint-action Example
1+
# Golangci-lint-action and Plugins Example
22

3-
TODO
3+
This repository is an example to explain how to use [custom linters](https://golangci-lint.run/contributing/new-linters/#how-to-add-a-private-linter-to-golangci-lint) (plugins) with the [GitHub Action of golangci-lint](https://github.com/golangci/golangci-lint-action).
4+
5+
## Build and Install Plugins
6+
7+
```yml
8+
- name: Build and install plugins
9+
run: |
10+
git clone https://github.com/golangci/example-plugin-linter.git
11+
cd example-plugin-linter
12+
go build -o '${{ github.workspace }}/.plugins/example.so' -buildmode=plugin plugin/example.go
13+
working-directory: ${{ runner.temp }}
14+
env:
15+
CGO_ENABLED: 1
16+
```
17+
18+
## Install and Run golangci-lint
19+
20+
```yml
21+
- name: golangci-lint
22+
uses: golangci/golangci-lint-action@v3
23+
with:
24+
version: v1.53.2
25+
# The installation mode `goinstall` always uses `CGO_ENABLED=1`.
26+
install-mode: goinstall
27+
args: --timeout=5m
28+
```
29+
30+
## Full Example
31+
32+
The [Workflow](https://github.com/golangci/golangci-lint-action-example/blob/main/.github/workflows/basic.yml).

0 commit comments

Comments
 (0)