Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#2608 from NikhilSharmaWe/checkDocs…
Browse files Browse the repository at this point in the history
…Only

🌱 [ci]: Skipping jobs which are not required when the changes are in only docs
  • Loading branch information
k8s-ci-robot authored May 14, 2022
2 parents 265658e + 94cf13b commit 479cde1
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 11 deletions.
22 changes: 20 additions & 2 deletions .github/workflows/apidiff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,29 @@ 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
needs: check_docs_only
# 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
Expand All @@ -19,7 +37,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/[email protected]
with:
Expand Down
21 changes: 19 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,36 @@ 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
needs: check_docs_only
# 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.45.2 # Always uses the latest patch version.
version: v1.45.2 # 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/[email protected]
Expand Down
31 changes: 24 additions & 7 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,42 @@ 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 }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- ubuntu-latest
- macos-latest
needs: check_docs_only
# 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
Expand All @@ -45,16 +61,17 @@ jobs:
name: Code coverage
needs:
- test
- check_docs_only
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
Expand Down
43 changes: 43 additions & 0 deletions test/check-docs-only.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/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)"
"(OWNERS)"
"(OWNERS_ALIASES)"
"(LICENSE)"
"(docs/)"
)

if ! git diff --name-only $1 | grep -qvE "$(IFS="|"; echo "${DOC_PATTERNS[*]}")"; then
echo "true"
exit 0
fi

0 comments on commit 479cde1

Please sign in to comment.