From 2e04336b218b349171e0e82bb7cf1507259d22e6 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sat, 22 Jun 2024 20:59:34 +0200 Subject: [PATCH] docs: add Go workspace examples --- README.md | 142 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 140 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bc882fee63..a8b3042848 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v6 with: - version: v1.58 + version: v1.59 ``` @@ -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 +``` + + + +
+Go Workspace Example + +```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 }} +``` + +
+ +
+Go Workspace Example (Multiple OS) + +```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: