From 12a90ab5bdccdaa6914e2cc443adaebaea5112e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Tue, 19 Nov 2024 11:52:31 +0100 Subject: [PATCH] chore: run lint stage before the test one --- .github/workflows/ci-lint-go.yml | 63 ++++++++++++++++++++++++++++++++ .github/workflows/ci-test-go.yml | 47 ------------------------ .github/workflows/ci.yml | 15 ++++++++ 3 files changed, 78 insertions(+), 47 deletions(-) create mode 100644 .github/workflows/ci-lint-go.yml diff --git a/.github/workflows/ci-lint-go.yml b/.github/workflows/ci-lint-go.yml new file mode 100644 index 0000000000..9c3ebab832 --- /dev/null +++ b/.github/workflows/ci-lint-go.yml @@ -0,0 +1,63 @@ +name: Run lint for a Go project +run-name: "${{ inputs.project-directory }}" + +on: + workflow_call: + inputs: + project-directory: + required: true + type: string + default: "." + description: "The directory where the Go project is located." + +permissions: + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + # pull-requests: read + +jobs: + lint-go-project: + name: "lint: ${{ inputs.project-directory }}" + runs-on: 'ubuntu-latest' + continue-on-error: false + steps: + - name: Check out code into the Go module directory + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 + + - name: Set up Go + uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5 + with: + go-version-file: "${{ inputs.project-directory == '' && '.' || inputs.project-directory }}/go.mod" + cache-dependency-path: "${{ inputs.project-directory == '' && '.' || inputs.project-directory }}/go.sum" + id: go + + - name: golangci-lint + uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6.1.1 + with: + # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version + version: v1.61.0 + # Optional: working directory, useful for monorepos + working-directory: ${{ inputs.project-directory }} + # Optional: golangci-lint command line arguments. + args: --verbose + # Optional: if set to true then the all caching functionality will be complete disabled, + # takes precedence over all other caching options. + skip-cache: true + + - name: generate + working-directory: ./${{ inputs.project-directory }} + shell: bash + run: | + make generate + git --no-pager diff && [[ 0 -eq $(git status --porcelain | wc -l) ]] + + - name: modVerify + working-directory: ./${{ inputs.project-directory }} + run: go mod verify + + - name: modTidy + working-directory: ./${{ inputs.project-directory }} + shell: bash + run: | + make tidy + git --no-pager diff && [[ 0 -eq $(git status --porcelain | wc -l) ]] diff --git a/.github/workflows/ci-test-go.yml b/.github/workflows/ci-test-go.yml index deba5690f2..ad0f8150d8 100644 --- a/.github/workflows/ci-test-go.yml +++ b/.github/workflows/ci-test-go.yml @@ -40,55 +40,8 @@ permissions: # pull-requests: read jobs: - lint-go-project: - name: "lint: ${{ inputs.project-directory }}" - runs-on: 'ubuntu-latest' - continue-on-error: false - steps: - - name: Check out code into the Go module directory - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 - - - name: Set up Go - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5 - with: - go-version-file: "${{ inputs.project-directory == '' && '.' || inputs.project-directory }}/go.mod" - cache-dependency-path: "${{ inputs.project-directory == '' && '.' || inputs.project-directory }}/go.sum" - id: go - - - name: golangci-lint - uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6.1.1 - with: - # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version - version: v1.61.0 - # Optional: working directory, useful for monorepos - working-directory: ${{ inputs.project-directory }} - # Optional: golangci-lint command line arguments. - args: --verbose - # Optional: if set to true then the all caching functionality will be complete disabled, - # takes precedence over all other caching options. - skip-cache: true - - - name: generate - working-directory: ./${{ inputs.project-directory }} - shell: bash - run: | - make generate - git --no-pager diff && [[ 0 -eq $(git status --porcelain | wc -l) ]] - - - name: modVerify - working-directory: ./${{ inputs.project-directory }} - run: go mod verify - - - name: modTidy - working-directory: ./${{ inputs.project-directory }} - shell: bash - run: | - make tidy - git --no-pager diff && [[ 0 -eq $(git status --porcelain | wc -l) ]] - test-go-project: name: "test: ${{ inputs.project-directory }}/${{ inputs.go-version }}" - needs: lint-go-project # Modulegen can run the tests on all platforms continue-on-error: ${{ !inputs.fail-fast }} env: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3c51a9c621..80371362df 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,11 +39,24 @@ jobs: echo "${{ steps.set-modified-modules-count.outputs.modules_count }} modules in the build" echo "${{ steps.set-modified-modules.outputs.modules }}" + lint: + # only run if there are modules to lint + if: ${{ needs.detect-modules.outputs.modules_count > 0 }} + needs: + - detect-modules + strategy: + matrix: + module: ${{ fromJSON(needs.detect-modules.outputs.modules) }} + uses: ./.github/workflows/ci-lint-go.yml + with: + project-directory: "${{ matrix.module }}" + test: # only run if there are modules to test if: ${{ needs.detect-modules.outputs.modules_count > 0 }} needs: - detect-modules + - lint strategy: matrix: go-version: [1.22.x, 1.x] @@ -64,6 +77,7 @@ jobs: if: ${{ contains(fromJSON(needs.detect-modules.outputs.modules), '') }} needs: - detect-modules + - lint name: "Test with reaper off" strategy: matrix: @@ -84,6 +98,7 @@ jobs: if: ${{ contains(fromJSON(needs.detect-modules.outputs.modules), '') }} needs: - detect-modules + - lint name: "Test with Rootless Docker" strategy: matrix: