From 6ed812fe88d4a5eebb9a531f6221560134d5883f Mon Sep 17 00:00:00 2001 From: Michael Gasch Date: Tue, 31 May 2022 15:33:45 +0200 Subject: [PATCH] chore: Add Go boilerplate check Closes: #2749 Closes: #2713 Signed-off-by: Michael Gasch --- .github/workflows/govmomi-go-lint.yaml | 70 +++++++++++++++++++++++++- hack/boilerplate/boilerplate.go.txt | 15 ++++++ 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 hack/boilerplate/boilerplate.go.txt diff --git a/.github/workflows/govmomi-go-lint.yaml b/.github/workflows/govmomi-go-lint.yaml index 7db94f8a9..356b87577 100644 --- a/.github/workflows/govmomi-go-lint.yaml +++ b/.github/workflows/govmomi-go-lint.yaml @@ -22,7 +22,6 @@ on: branches: [ 'main', 'master' ] jobs: - lint: name: Lint Files runs-on: ubuntu-20.04 @@ -40,3 +39,72 @@ jobs: - name: Go Lint run: make lint + + boilerplate: + name: Boilerplate Check + runs-on: ubuntu-latest + strategy: + fail-fast: false # Keep running if one leg fails. + matrix: + extension: + - go + + # Map between extension and human-readable name. + include: + - extension: go + language: Go + + steps: + - name: Check out code + uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.18 + id: go + + - name: Install Tools + run: | + TEMP_PATH="$(mktemp -d)" + cd "$TEMP_PATH" + + echo '::group::🐶 Installing reviewdog ... https://github.com/reviewdog/reviewdog' + curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s -- -b "${TEMP_PATH}" 2>&1 + echo '::endgroup::' + + echo '::group:: Installing boilerplate-check ... https://github.com/mattmoor/boilerplate-check' + go install github.com/mattmoor/boilerplate-check/cmd/boilerplate-check@latest + echo '::endgroup::' + + echo "${TEMP_PATH}" >> "$GITHUB_PATH" + + - id: boilerplate_txt + uses: andstor/file-existence-action@v1 + with: + files: ./hack/boilerplate/boilerplate.${{ matrix.extension }}.txt + + - name: ${{ matrix.language }} license boilerplate + shell: bash + if: ${{ steps.boilerplate_txt.outputs.files_exists == 'true' }} + env: + REVIEWDOG_GITHUB_API_TOKEN: ${{ github.token }} + run: | + set -e + cd "${GITHUB_WORKSPACE}" || exit 1 + + echo '::group:: Running github.com/mattmoor/boilerplate-check for ${{ matrix.language }} with reviewdog 🐶 ...' + # Don't fail because of boilerplate-check + set +o pipefail + boilerplate-check check \ + --boilerplate ./hack/boilerplate/boilerplate.${{ matrix.extension }}.txt \ + --file-extension ${{ matrix.extension }} \ + --exclude "(vendor|third_party|dist)/" | + reviewdog -efm="%A%f:%l: %m" \ + -efm="%C%.%#" \ + -name="${{ matrix.language }} headers" \ + -reporter="github-pr-check" \ + -filter-mode="diff_context" \ + -fail-on-error="true" \ + -level="error" + echo '::endgroup::' diff --git a/hack/boilerplate/boilerplate.go.txt b/hack/boilerplate/boilerplate.go.txt new file mode 100644 index 000000000..8f9156361 --- /dev/null +++ b/hack/boilerplate/boilerplate.go.txt @@ -0,0 +1,15 @@ +/* +Copyright (c) 2014-2022 VMware, Inc. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ \ No newline at end of file