-
Notifications
You must be signed in to change notification settings - Fork 1.8k
ci: skip running builds and tests if no code changed #8768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aThorp96
wants to merge
1
commit into
tektoncd:main
Choose a base branch
from
aThorp96:skip-build-tests-when-no-changes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+39
−3
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
name: ci | ||
|
||
on: | ||
- pull_request | ||
on: [pull_request] | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.event.pull-request.number || github.ref }} | ||
|
@@ -16,9 +15,40 @@ permissions: | |
checks: write # Used to annotate code in the PR | ||
|
||
jobs: | ||
changes: | ||
name: categorize changes | ||
runs-on: ubuntu-latest | ||
outputs: | ||
non-docs: ${{ steps.detect.outputs.non-docs }} | ||
yaml: ${{ steps.detect.outputs.yaml }} | ||
steps: | ||
- name: Get base depth | ||
id: base-depth | ||
run: echo "base-depth=$(expr ${{ github.event.pull_request.commits }} + 1)" >> $GITHUB_OUTPUT | ||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | ||
with: | ||
ref: ${{ github.event.pull_request.head.sha }} | ||
fetch-depth: ${{ steps.base-depth.outputs.base-depth }} | ||
- name: detect | ||
id: detect | ||
run: | | ||
git fetch origin ${{ github.base_ref }} | ||
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }} | tr ' ' '\n') | ||
|
||
echo -e "Changed files:\n${CHANGED_FILES}" | ||
|
||
# If no files are changed at all, then `grep -v` will match even though no change outputs | ||
# should be true. Skipping output on an empty set of changes eliminates the false positive | ||
if [[ -n "${CHANGED_FILES}" ]]; then | ||
echo "non-docs=$(echo \"${CHANGED_FILES}\" | grep -qv '**\.md' && echo 'true' )" | tee -a $GITHUB_OUTPUT | ||
echo "yaml=$(echo \"${CHANGED_FILES}\" | grep -q '**\.ya\?ml' && echo 'true' )" | tee -a $GITHUB_OUTPUT | ||
fi | ||
|
||
build: | ||
name: build | ||
runs-on: ubuntu-latest | ||
needs: [changes] | ||
if: ${{ needs.changes.outputs.non-docs == 'true' }} | ||
steps: | ||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | ||
- uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0 | ||
|
@@ -30,6 +60,8 @@ jobs: | |
buildFips: | ||
name: buildFips | ||
runs-on: ubuntu-latest | ||
needs: [changes] | ||
if: ${{ needs.changes.outputs.non-docs == 'true' }} | ||
steps: | ||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | ||
- uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0 | ||
|
@@ -40,15 +72,16 @@ jobs: | |
go build -v -tags "disable_spire,disable_tls" ./cmd/entrypoint | ||
echo "Build finished with exit code: $?" | ||
linting: | ||
needs: [build] | ||
name: lint | ||
runs-on: ubuntu-latest | ||
needs: [changes] | ||
steps: | ||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | ||
- uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0 | ||
with: | ||
go-version-file: "go.mod" | ||
- name: gofmt | ||
if: ${{ needs.changes.outputs.non-docs == 'true' }} | ||
run: | | ||
gofmt_out=$(gofmt -d $(find * -name '*.go' ! -path 'vendor/*' ! -path 'third_party/*')) | ||
if [[ -n "$gofmt_out" ]]; then | ||
|
@@ -57,15 +90,18 @@ jobs: | |
echo "$gofmt_out" | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0 | ||
if: ${{ needs.changes.outputs.non-docs == 'true' }} | ||
with: | ||
version: v2.1.6 | ||
only-new-issues: true | ||
args: --timeout=10m | ||
- name: yamllint | ||
if: ${{ needs.changes.outputs.yaml == 'true' }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine, however I'm mostly concerned with E2E test. We should skip them if they're not relevant as they take a lot of runners and time. Everything else is small/quick enough that I would not bother touching it at the risk of over-optimising. |
||
run: | | ||
apt-get update && apt-get install -y yamllint | ||
make yamllint | ||
- name: check-license | ||
if: ${{ needs.changes.outputs.non-docs == 'true' }} | ||
run: | | ||
go install github.com/google/[email protected] | ||
go-licenses check ./... | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could clone the full repository here, but that could take some time and is probably not necessary. This should help the pre-check go much quicker