From 359097d455fd618edbd85c92c9bad78e60451d7b Mon Sep 17 00:00:00 2001 From: Nikhil Sharma Date: Tue, 12 Apr 2022 19:43:51 +0530 Subject: [PATCH] changes to not run tests when the changes are only in docs or comments --- .github/workflows/apidiff.yml | 21 +++++++++++++-- .github/workflows/lint.yml | 20 +++++++++++++-- .github/workflows/testdata.yml | 20 +++++++++++++-- .github/workflows/unit-tests.yml | 29 ++++++++++++++++----- .github/workflows/verify.yml | 28 +++++++++++++++----- test/check-docs-only.sh | 44 ++++++++++++++++++++++++++++++++ 6 files changed, 143 insertions(+), 19 deletions(-) create mode 100644 test/check-docs-only.sh diff --git a/.github/workflows/apidiff.yml b/.github/workflows/apidiff.yml index e62ca838a69..e108d9e142f 100644 --- a/.github/workflows/apidiff.yml +++ b/.github/workflows/apidiff.yml @@ -6,11 +6,28 @@ on: pull_request: jobs: + check_docs_only: + name: check_docs_only + runs-on: ubuntu-18.04 + outputs: + skip: ${{ steps.check_docs_only.outputs.skip }} + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - id: check_docs_only + # Since PR's are squashed prior to merging to the branch checked out (default branch), + # HEAD^ will resolve to the previous point in history. + run: | + REF="HEAD^" + [[ -z "${{ github.base_ref }}" ]] || REF=$(git show-ref ${{ github.base_ref }} | head -1 | cut -d' ' -f2) + echo "::set-output name=skip::$(test/check-docs-only.sh $REF)" + go-apidiff: name: Verify API differences runs-on: ubuntu-latest # Pull requests from different repository only trigger this checks - if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository + if: (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) && needs.check_docs_only.outputs.skip != 'true' steps: - name: Clone the code uses: actions/checkout@v2 @@ -19,7 +36,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v2 with: - go-version: '1.17' + go-version: "1.17" - name: Execute go-apidiff uses: joelanford/go-apidiff@v0.2.0 with: diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 3359186c7aa..a79c0faf2bc 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -6,19 +6,35 @@ on: pull_request: jobs: + check_docs_only: + name: check_docs_only + runs-on: ubuntu-18.04 + outputs: + skip: ${{ steps.check_docs_only.outputs.skip }} + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - id: check_docs_only + # Since PR's are squashed prior to merging to the branch checked out (default branch), + # HEAD^ will resolve to the previous point in history. + run: | + REF="HEAD^" + [[ -z "${{ github.base_ref }}" ]] || REF=$(git show-ref ${{ github.base_ref }} | head -1 | cut -d' ' -f2) + echo "::set-output name=skip::$(test/check-docs-only.sh $REF)" lint: name: golangci-lint runs-on: ubuntu-latest # Pull requests from the same repository won't trigger this checks as they were already triggered by the push - if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository + if: (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository) && needs.check_docs_only.outputs.skip != 'true' steps: - name: Clone the code uses: actions/checkout@v2 - name: Run linter uses: golangci/golangci-lint-action@v2 with: - version: v1.41 # Always uses the latest patch version. + version: v1.41 # Always uses the latest patch version. only-new-issues: true # Show only new issues if it's a pull request - name: Report failure uses: nashmaniac/create-issue-action@v1.1 diff --git a/.github/workflows/testdata.yml b/.github/workflows/testdata.yml index fd0fbb05e1e..878ce0e7739 100644 --- a/.github/workflows/testdata.yml +++ b/.github/workflows/testdata.yml @@ -6,19 +6,35 @@ on: pull_request: jobs: + check_docs_only: + name: check_docs_only + runs-on: ubuntu-18.04 + outputs: + skip: ${{ steps.check_docs_only.outputs.skip }} + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - id: check_docs_only + # Since PR's are squashed prior to merging to the branch checked out (default branch), + # HEAD^ will resolve to the previous point in history. + run: | + REF="HEAD^" + [[ -z "${{ github.base_ref }}" ]] || REF=$(git show-ref ${{ github.base_ref }} | head -1 | cut -d' ' -f2) + echo "::set-output name=skip::$(test/check-docs-only.sh $REF)" testdata: name: Verify testdata directory runs-on: ubuntu-latest # Pull requests from the same repository won't trigger this checks as they were already triggered by the push - if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository + if: (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository) && needs.check_docs_only.outputs.skip != 'true' steps: - name: Clone the code uses: actions/checkout@v2 - name: Setup Go uses: actions/setup-go@v2 with: - go-version: '1.17' + go-version: "1.17" - name: Remove pre-installed kustomize # This step is needed as the following one tries to remove # kustomize for each test but has no permission to do so diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index b59db892cf2..160c22fc914 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -5,8 +5,23 @@ on: push: pull_request: - jobs: + check_docs_only: + name: check_docs_only + runs-on: ubuntu-18.04 + outputs: + skip: ${{ steps.check_docs_only.outputs.skip }} + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - id: check_docs_only + # Since PR's are squashed prior to merging to the branch checked out (default branch), + # HEAD^ will resolve to the previous point in history. + run: | + REF="HEAD^" + [[ -z "${{ github.base_ref }}" ]] || REF=$(git show-ref ${{ github.base_ref }} | head -1 | cut -d' ' -f2) + echo "::set-output name=skip::$(test/check-docs-only.sh $REF)" test: name: ${{ matrix.os }} @@ -14,17 +29,17 @@ jobs: strategy: matrix: os: - - ubuntu-latest - - macos-latest + - ubuntu-latest + - macos-latest # Pull requests from the same repository won't trigger this checks as they were already triggered by the push - if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository + if: (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository) && needs.check_docs_only.outputs.skip != 'true' steps: - name: Clone the code uses: actions/checkout@v2 - name: Setup Go uses: actions/setup-go@v2 with: - go-version: '1.17' + go-version: "1.17" # This step is needed as the following one tries to remove # kustomize for each test but has no permission to do so - name: Remove pre-installed kustomize @@ -47,14 +62,14 @@ jobs: - test runs-on: ubuntu-latest # Pull requests from the same repository won't trigger this checks as they were already triggered by the push - if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository + if: (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository) && needs.check_docs_only.outputs.skip != 'true' steps: - name: Clone the code uses: actions/checkout@v2 - name: Setup Go uses: actions/setup-go@v2 with: - go-version: '1.17' + go-version: "1.17" - name: Generate the coverage output run: make test-coverage - name: Send the coverage output diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index 6f3ac87fa9c..c161cbecb6b 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -4,15 +4,31 @@ on: pull_request_target: types: [opened, edited, reopened] - jobs: + check_docs_only: + name: check_docs_only + runs-on: ubuntu-18.04 + outputs: + skip: ${{ steps.check_docs_only.outputs.skip }} + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - id: check_docs_only + # Since PR's are squashed prior to merging to the branch checked out (default branch), + # HEAD^ will resolve to the previous point in history. + run: | + REF="HEAD^" + [[ -z "${{ github.base_ref }}" ]] || REF=$(git show-ref ${{ github.base_ref }} | head -1 | cut -d' ' -f2) + echo "::set-output name=skip::$(test/check-docs-only.sh $REF)" verify: name: Verify PR contents runs-on: ubuntu-latest + if: needs.check_docs_only.outputs.skip != 'true' steps: - - name: Verifier action - id: verifier - uses: kubernetes-sigs/kubebuilder-release-tools@v0.1.1 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} + - name: Verifier action + id: verifier + uses: kubernetes-sigs/kubebuilder-release-tools@v0.1.1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/test/check-docs-only.sh b/test/check-docs-only.sh new file mode 100644 index 00000000000..66287508754 --- /dev/null +++ b/test/check-docs-only.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +# Copyright 2018 The Kubernetes Authors. +# +# 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. + +# This script runs goreleaser using the build/.goreleaser.yml config. +# While it can be run locally, it is intended to be run by cloudbuild +# in the goreleaser/goreleaser image. + +set -e + +# If running in Github actions: this should be set to "github.base_ref". +: ${1?"the first argument must be set to a commit-ish reference"} + +# Patterns to ignore. +declare -a DOC_PATTERNS +DOC_PATTERNS=( + "(\.md)" + "(\.MD)" + "(\.png)" + "(\.pdf)" + "(netlify\.toml)" + "(website/)" + "(changelog/)" + "(OWNERS)" + "(OWNERS_ALIASES)" + "(LICENSE)" +) + +if ! git diff --name-only $1 | grep -qvE "$(IFS="|"; echo "${DOC_PATTERNS[*]}")"; then + echo "true" + exit 0 +fi \ No newline at end of file