From 2e953b75e50b05f925bc1c7239a5b7545d67024b Mon Sep 17 00:00:00 2001 From: apostasie Date: Fri, 13 Dec 2024 15:10:08 -0800 Subject: [PATCH] Add a golint action Signed-off-by: apostasie --- .github/actions/install-go-linters/action.yml | 35 +++++++++++++++++ .github/actions/lint-go/action.yml | 26 ------------- .github/workflows/lint.yml | 38 +++++++++---------- Makefile | 7 +++- 4 files changed, 58 insertions(+), 48 deletions(-) create mode 100644 .github/actions/install-go-linters/action.yml delete mode 100644 .github/actions/lint-go/action.yml diff --git a/.github/actions/install-go-linters/action.yml b/.github/actions/install-go-linters/action.yml new file mode 100644 index 00000000000..ccaae62634e --- /dev/null +++ b/.github/actions/install-go-linters/action.yml @@ -0,0 +1,35 @@ +name: "lint-go" +description: "This action will install go linting tools (golangci-lint and goimports-reviser), and executes them on the codebase." +inputs: + cache-dependency-path: + description: 'Used to specify the path to a dependency file - go.sum' + strategy: + description: "See install-go for info" + _golangci_version: + description: "Internal: the golangci version we want" + default: "89476e7a1eaa0a8a06c17343af960a5fd9e7edb7" # v1.62.2 + _goimports_version: + description: "Internal: the goimports reviser version we want" + default: "f034195cc8a7ffc7cc70d60aa3a25500874eaf04" # v3.8.2 + +runs: + using: composite + steps: + - name: "Install golang" + uses: ./.github/actions/install-go + with: + strategy: ${{ inputs.strategy }} + - name: "`go install` needed tools" + shell: bash + run: | + # go install golangci-lint and goimports-reviser + err="$(go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@${{ inputs._golangci_version }} 2>&1)" || { + echo "Failed installing golangci:" + echo "$err" + exit 1 + } + err="$(go install -v github.com/incu6us/goimports-reviser/v3@${{ inputs._goimports_version }} 2>&1)" || { + echo "Failed installing goimports-reviser:" + echo "$err" + exit 1 + } diff --git a/.github/actions/lint-go/action.yml b/.github/actions/lint-go/action.yml deleted file mode 100644 index 0b386a04467..00000000000 --- a/.github/actions/lint-go/action.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: "Go lint" -description: "This action will install go linting tools (golangci-lint and goimports-reviser), and executes them on the codebase." -inputs: - cache-dependency-path: - description: 'Used to specify the path to a dependency file - go.sum' - strategy: - description: "See intall-go for info" - -runs: - using: composite - steps: - - name: "Install go" - uses: ./.github/actions/install-go - with: - strategy: ${{ inputs.strategy }} - - name: "Run golangci-lint" - uses: golangci/golangci-lint-action@774c35bcccffb734694af9e921f12f57d882ef74 # v6.1.1 - with: - args: --verbose - skip-save-cache: true - skip-cache: true - - name: "Check that go imports ordering is ok" - shell: bash - run: | - go install -v github.com/incu6us/goimports-reviser/v3@f034195cc8a7ffc7cc70d60aa3a25500874eaf04 # v3.8.2 - make lint-imports diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index dc29c55cc29..da814b9c00c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -12,9 +12,6 @@ jobs: timeout-minutes: 5 name: "go | ${{ matrix.goos }} | ${{ matrix.goversion }}" runs-on: "${{ matrix.os }}" - defaults: - run: - shell: bash strategy: matrix: include: @@ -32,37 +29,38 @@ jobs: - os: ubuntu-24.04 goos: linux goversion: canary - env: - GOOS: "${{ matrix.goos }}" steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: fetch-depth: 1 - - name: "Install go" - uses: ./.github/actions/install-go + - name: "Install go linters" + uses: ./.github/actions/install-go-linters with: strategy: ${{ matrix.goversion }} - - name: golangci-lint - uses: golangci/golangci-lint-action@774c35bcccffb734694af9e921f12f57d882ef74 # v6.1.1 - with: - args: --verbose + - name: "`make lint-imports`" + # Import ordering is not influenced by GOOS - running it multiple times is thus unnecessary + # Note we are picking freebsd as the GOOS to run it on, as linux is running multiple times (eg: canary) + if: ${{ matrix.goos=='freebsd' }} + shell: bash + run: | + make lint-imports + - name: "`make lint-go` for ${{ matrix.goos }}" + env: + VERBOSE: true + GOOS: ${{ matrix.goos }} + shell: bash + run: | + make lint-go + other: timeout-minutes: 5 - name: yaml | shell | imports order + name: yaml | shell runs-on: ubuntu-24.04 steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: fetch-depth: 1 - - name: "Install go" - uses: ./.github/actions/install-go - with: - strategy: latest-stable - name: yaml run: make lint-yaml - name: shell run: make lint-shell - - name: go imports ordering - run: | - go install -v github.com/incu6us/goimports-reviser/v3@latest - make lint-imports diff --git a/Makefile b/Makefile index ae4e18c94f3..ca6388b52cb 100644 --- a/Makefile +++ b/Makefile @@ -67,13 +67,16 @@ clean: find . -name \#\* -delete rm -rf $(CURDIR)/_output/* $(MAKEFILE_DIR)/vendor -lint: lint-go lint-imports lint-yaml lint-shell +lint: lint-go-all lint-imports lint-yaml lint-shell -lint-go: +lint-go-all: cd $(MAKEFILE_DIR) && GOOS=linux golangci-lint run $(VERBOSE_FLAG_LONG) ./... && \ GOOS=windows golangci-lint run $(VERBOSE_FLAG_LONG) ./... && \ GOOS=freebsd golangci-lint run $(VERBOSE_FLAG_LONG) ./... +lint-go: + cd $(MAKEFILE_DIR) && golangci-lint run $(VERBOSE_FLAG_LONG) ./... + lint-imports: cd $(MAKEFILE_DIR) && ./hack/lint-imports.sh