Skip to content

Commit 0f35ce0

Browse files
committed
docs: add Go workspace examples
1 parent 0d98fec commit 0f35ce0

File tree

1 file changed

+141
-2
lines changed

1 file changed

+141
-2
lines changed

README.md

+141-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
- name: golangci-lint
5757
uses: golangci/golangci-lint-action@v6
5858
with:
59-
version: v1.58
59+
version: v1.59
6060
```
6161
6262
</details>
@@ -94,7 +94,146 @@ jobs:
9494
- name: golangci-lint
9595
uses: golangci/golangci-lint-action@v6
9696
with:
97-
version: v1.58
97+
version: v1.59
98+
```
99+
100+
You will also likely need to add the following `.gitattributes` file to ensure that line endings for Windows builds are properly formatted:
101+
102+
```.gitattributes
103+
*.go text eol=lf
104+
```
105+
106+
</details>
107+
108+
<details>
109+
<summary>Go Workspace Example</summary>
110+
111+
```yaml
112+
name: golangci-lint
113+
114+
on:
115+
pull_request:
116+
push:
117+
branches:
118+
- "main"
119+
- "master"
120+
121+
env:
122+
GO_VERSION: stable
123+
GOLANGCI_LINT_VERSION: v1.59
124+
125+
jobs:
126+
detect-modules:
127+
runs-on: ubuntu-latest
128+
outputs:
129+
modules: ${{ steps.set-modules.outputs.modules }}
130+
steps:
131+
- uses: actions/checkout@v4
132+
- uses: actions/setup-go@v5
133+
with:
134+
go-version: ${{ env.GO_VERSION }}
135+
- id: set-modules
136+
run: echo "modules=$(go list -m -json | jq -s '.' | jq -c '[.[].Dir]')" >> $GITHUB_OUTPUT
137+
138+
golangci-lint:
139+
needs: detect-modules
140+
runs-on: ubuntu-latest
141+
strategy:
142+
matrix:
143+
modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }}
144+
steps:
145+
- uses: actions/checkout@v4
146+
- uses: actions/setup-go@v5
147+
with:
148+
go-version: ${{ env.GO_VERSION }}
149+
- name: golangci-lint ${{ matrix.modules }}
150+
uses: golangci/golangci-lint-action@v6
151+
with:
152+
version: ${{ env.GOLANGCI_LINT_VERSION }}
153+
working-directory: ${{ matrix.modules }}
154+
```
155+
156+
</details>
157+
158+
<details>
159+
<summary>Go Workspace Example (Multiple OS)</summary>
160+
161+
```yaml
162+
# golangci-lint.yml
163+
name: golangci-lint (multi OS)
164+
165+
on:
166+
pull_request:
167+
push:
168+
branches:
169+
- "main"
170+
- "master"
171+
172+
jobs:
173+
golangci-lint:
174+
strategy:
175+
matrix:
176+
go-version: [ stable, oldstable ]
177+
os: [ubuntu-latest, macos-latest, windows-latest]
178+
uses: ./.github/workflows/.workspace.yml
179+
with:
180+
os: ${{ matrix.os }}
181+
go-version: ${{ matrix.go-version }}
182+
repository: ${{ inputs.repository }}
183+
golangci-lint-version: v1.59
184+
```
185+
186+
```yaml
187+
# ./.github/workflows/.golangci-lint-reusable.yml
188+
name: golangci-lint-reusable
189+
190+
on:
191+
workflow_call:
192+
inputs:
193+
os:
194+
description: 'OS'
195+
required: true
196+
type: string
197+
go-version:
198+
description: 'Go version'
199+
required: true
200+
type: string
201+
default: stable
202+
golangci-lint-version:
203+
description: 'Golangci-lint version'
204+
type: string
205+
default: 'v1.59.1'
206+
207+
jobs:
208+
detect-modules:
209+
runs-on: ${{ inputs.os }}
210+
outputs:
211+
modules: ${{ steps.set-modules.outputs.modules }}
212+
steps:
213+
- uses: actions/checkout@v4
214+
- uses: actions/setup-go@v5
215+
with:
216+
go-version: ${{ inputs.go-version }}
217+
- id: set-modules
218+
shell: bash # require for Windows to be able to use $GITHUB_OUTPUT https://github.com/actions/runner/issues/2224
219+
run: echo "modules=$(go list -m -json | jq -s '.' | jq -c '[.[].Dir]')" >> $GITHUB_OUTPUT
220+
221+
golangci-lint:
222+
needs: detect-modules
223+
runs-on: ${{ inputs.os }}
224+
strategy:
225+
matrix:
226+
modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }}
227+
steps:
228+
- uses: actions/checkout@v4
229+
- uses: actions/setup-go@v5
230+
with:
231+
go-version: ${{ inputs.go-version }}
232+
- name: golangci-lint ${{ matrix.modules }}
233+
uses: golangci/golangci-lint-action@v6
234+
with:
235+
version: ${{ inputs.golangci-lint-version }}
236+
working-directory: ${{ matrix.modules }}
98237
```
99238

100239
You will also likely need to add the following `.gitattributes` file to ensure that line endings for Windows builds are properly formatted:

0 commit comments

Comments
 (0)