Skip to content

Commit

Permalink
docs: add Go workspace examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Jun 22, 2024
1 parent 0d98fec commit 2e04336
Showing 1 changed file with 140 additions and 2 deletions.
142 changes: 140 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.58
version: v1.59
```
</details>
Expand Down Expand Up @@ -94,7 +94,145 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.58
version: v1.59
```
You will also likely need to add the following `.gitattributes` file to ensure that line endings for Windows builds are properly formatted:

```.gitattributes
*.go text eol=lf
```

</details>

<details>
<summary>Go Workspace Example</summary>

```yaml
name: golangci-lint
on:
pull_request:
push:
branches:
- "main"
- "master"
env:
GO_VERSION: stable
GOLANGCI_LINT_VERSION: v1.59
jobs:
detect-modules:
runs-on: ubuntu-latest
outputs:
modules: ${{ steps.set-modules.outputs.modules }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- id: set-modules
run: echo "modules=$(go list -m -json | jq -s '.' | jq -c '[.[].Dir]')" >> $GITHUB_OUTPUT
golangci-lint:
needs: detect-modules
runs-on: ubuntu-latest
strategy:
matrix:
modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: golangci-lint ${{ matrix.modules }}
uses: golangci/golangci-lint-action@v6
with:
version: ${{ env.GOLANGCI_LINT_VERSION }}
working-directory: ${{ matrix.modules }}
```

</details>

<details>
<summary>Go Workspace Example (Multiple OS)</summary>

```yaml
# golangci-lint.yml
name: golangci-lint (multi OS)
on:
pull_request:
push:
branches:
- "main"
- "master"
jobs:
golangci-lint:
strategy:
matrix:
go-version: [ stable, oldstable ]
os: [ubuntu-latest, macos-latest, windows-latest]
uses: ./.github/workflows/.workspace.yml
with:
os: ${{ matrix.os }}
go-version: ${{ matrix.go-version }}
repository: ${{ inputs.repository }}
golangci-lint-version: v1.59
```

```yaml
# ./.github/workflows/.golangci-lint-reusable.yml
name: golangci-lint-reusable
on:
workflow_call:
inputs:
os:
description: 'OS'
required: true
type: string
go-version:
description: 'Go version'
required: true
type: string
default: stable
golangci-lint-version:
description: 'Golangci-lint version'
type: string
default: 'v1.59.1'
jobs:
detect-modules:
runs-on: ${{ inputs.os }}
outputs:
modules: ${{ steps.set-modules.outputs.modules }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ inputs.go-version }}
- id: set-modules
run: echo "modules=$(go list -m -json | jq -s '.' | jq -c '[.[].Dir]')" >> $GITHUB_OUTPUT
golangci-lint:
needs: detect-modules
runs-on: ${{ inputs.os }}
strategy:
matrix:
modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ inputs.go-version }}
- name: golangci-lint ${{ matrix.modules }}
uses: golangci/golangci-lint-action@v6
with:
version: ${{ inputs.golangci-lint-version }}
working-directory: ${{ matrix.modules }}
```

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

0 comments on commit 2e04336

Please sign in to comment.