Skip to content

Commit 479cde1

Browse files
authored
Merge pull request #2608 from NikhilSharmaWe/checkDocsOnly
🌱 [ci]: Skipping jobs which are not required when the changes are in only docs
2 parents 265658e + 94cf13b commit 479cde1

File tree

4 files changed

+106
-11
lines changed

4 files changed

+106
-11
lines changed

.github/workflows/apidiff.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,29 @@ on:
66
pull_request:
77

88
jobs:
9+
check_docs_only:
10+
name: check_docs_only
11+
runs-on: ubuntu-18.04
12+
outputs:
13+
skip: ${{ steps.check_docs_only.outputs.skip }}
14+
steps:
15+
- uses: actions/checkout@v2
16+
with:
17+
fetch-depth: 0
18+
- id: check_docs_only
19+
# Since PR's are squashed prior to merging to the branch checked out (default branch),
20+
# HEAD^ will resolve to the previous point in history.
21+
run: |
22+
REF="HEAD^"
23+
[[ -z "${{ github.base_ref }}" ]] || REF=$(git show-ref ${{ github.base_ref }} | head -1 | cut -d' ' -f2)
24+
echo "::set-output name=skip::$(test/check-docs-only.sh $REF)"
25+
926
go-apidiff:
1027
name: Verify API differences
1128
runs-on: ubuntu-latest
29+
needs: check_docs_only
1230
# Pull requests from different repository only trigger this checks
13-
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository
31+
if: (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) && needs.check_docs_only.outputs.skip != 'true'
1432
steps:
1533
- name: Clone the code
1634
uses: actions/checkout@v2
@@ -19,7 +37,7 @@ jobs:
1937
- name: Setup Go
2038
uses: actions/setup-go@v2
2139
with:
22-
go-version: '1.17'
40+
go-version: "1.17"
2341
- name: Execute go-apidiff
2442
uses: joelanford/[email protected]
2543
with:

.github/workflows/lint.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,36 @@ on:
66
pull_request:
77

88
jobs:
9+
check_docs_only:
10+
name: check_docs_only
11+
runs-on: ubuntu-18.04
12+
outputs:
13+
skip: ${{ steps.check_docs_only.outputs.skip }}
14+
steps:
15+
- uses: actions/checkout@v2
16+
with:
17+
fetch-depth: 0
18+
- id: check_docs_only
19+
# Since PR's are squashed prior to merging to the branch checked out (default branch),
20+
# HEAD^ will resolve to the previous point in history.
21+
run: |
22+
REF="HEAD^"
23+
[[ -z "${{ github.base_ref }}" ]] || REF=$(git show-ref ${{ github.base_ref }} | head -1 | cut -d' ' -f2)
24+
echo "::set-output name=skip::$(test/check-docs-only.sh $REF)"
925
1026
lint:
1127
name: golangci-lint
1228
runs-on: ubuntu-latest
29+
needs: check_docs_only
1330
# Pull requests from the same repository won't trigger this checks as they were already triggered by the push
14-
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
31+
if: (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository) && needs.check_docs_only.outputs.skip != 'true'
1532
steps:
1633
- name: Clone the code
1734
uses: actions/checkout@v2
1835
- name: Run linter
1936
uses: golangci/golangci-lint-action@v2
2037
with:
21-
version: v1.45.2 # Always uses the latest patch version.
38+
version: v1.45.2 # Always uses the latest patch version.
2239
only-new-issues: true # Show only new issues if it's a pull request
2340
- name: Report failure
2441
uses: nashmaniac/[email protected]

.github/workflows/unit-tests.yml

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,42 @@ on:
55
push:
66
pull_request:
77

8-
98
jobs:
9+
check_docs_only:
10+
name: check_docs_only
11+
runs-on: ubuntu-18.04
12+
outputs:
13+
skip: ${{ steps.check_docs_only.outputs.skip }}
14+
steps:
15+
- uses: actions/checkout@v2
16+
with:
17+
fetch-depth: 0
18+
- id: check_docs_only
19+
# Since PR's are squashed prior to merging to the branch checked out (default branch),
20+
# HEAD^ will resolve to the previous point in history.
21+
run: |
22+
REF="HEAD^"
23+
[[ -z "${{ github.base_ref }}" ]] || REF=$(git show-ref ${{ github.base_ref }} | head -1 | cut -d' ' -f2)
24+
echo "::set-output name=skip::$(test/check-docs-only.sh $REF)"
1025
1126
test:
1227
name: ${{ matrix.os }}
1328
runs-on: ${{ matrix.os }}
1429
strategy:
1530
matrix:
1631
os:
17-
- ubuntu-latest
18-
- macos-latest
32+
- ubuntu-latest
33+
- macos-latest
34+
needs: check_docs_only
1935
# Pull requests from the same repository won't trigger this checks as they were already triggered by the push
20-
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
36+
if: (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository) && needs.check_docs_only.outputs.skip != 'true'
2137
steps:
2238
- name: Clone the code
2339
uses: actions/checkout@v2
2440
- name: Setup Go
2541
uses: actions/setup-go@v2
2642
with:
27-
go-version: '1.17'
43+
go-version: "1.17"
2844
# This step is needed as the following one tries to remove
2945
# kustomize for each test but has no permission to do so
3046
- name: Remove pre-installed kustomize
@@ -45,16 +61,17 @@ jobs:
4561
name: Code coverage
4662
needs:
4763
- test
64+
- check_docs_only
4865
runs-on: ubuntu-latest
4966
# Pull requests from the same repository won't trigger this checks as they were already triggered by the push
50-
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
67+
if: (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository) && needs.check_docs_only.outputs.skip != 'true'
5168
steps:
5269
- name: Clone the code
5370
uses: actions/checkout@v2
5471
- name: Setup Go
5572
uses: actions/setup-go@v2
5673
with:
57-
go-version: '1.17'
74+
go-version: "1.17"
5875
- name: Generate the coverage output
5976
run: make test-coverage
6077
- name: Send the coverage output

test/check-docs-only.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2018 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# This script runs goreleaser using the build/.goreleaser.yml config.
18+
# While it can be run locally, it is intended to be run by cloudbuild
19+
# in the goreleaser/goreleaser image.
20+
21+
set -e
22+
23+
# If running in Github actions: this should be set to "github.base_ref".
24+
: ${1?"the first argument must be set to a commit-ish reference"}
25+
26+
# Patterns to ignore.
27+
declare -a DOC_PATTERNS
28+
DOC_PATTERNS=(
29+
"(\.md)"
30+
"(\.MD)"
31+
"(\.png)"
32+
"(\.pdf)"
33+
"(netlify\.toml)"
34+
"(OWNERS)"
35+
"(OWNERS_ALIASES)"
36+
"(LICENSE)"
37+
"(docs/)"
38+
)
39+
40+
if ! git diff --name-only $1 | grep -qvE "$(IFS="|"; echo "${DOC_PATTERNS[*]}")"; then
41+
echo "true"
42+
exit 0
43+
fi

0 commit comments

Comments
 (0)