-
Notifications
You must be signed in to change notification settings - Fork 6.8k
build(ci): skip tests on CI when only markdown files have changed #4452
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
Conversation
scripts/ci/build-and-test.sh
Outdated
for filename in $(git diff --name-only $TRAVIS_BRANCH...HEAD); do | ||
if ! [[ "$filename" =~ .*\.md ]]; then | ||
skip_tests=false | ||
break |
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.
Should we check the modes here and just exit before?
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.
Good point. Let me try to change it.
scripts/ci/build-and-test.sh
Outdated
@@ -10,20 +10,29 @@ cd $(dirname $0)/../.. | |||
source scripts/ci/sources/mode.sh | |||
source scripts/ci/sources/tunnel.sh | |||
|
|||
# Check if tests can be skipped | |||
skip_tests=true | |||
for filename in $(git diff --name-only $TRAVIS_BRANCH...HEAD); do |
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.
Would it make more sense to use TRAVIS_COMMIT_RANGE
?
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.
@devversion
Please check: travis-ci/travis-ci#2668 TRAVIS_COMMIT_RANGE
will include outdated commit if user does a force push (which is very common to update a PR)
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.
But If I recall correctly, for Push builds the $TRAVIS_BRANCH
will be master
and the merged commit will be HEAD
/ master
as well.
This would mean that the diff
will be always empty for push builds.
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.
@devversion HEAD
would be PR merged into master
when $TRAVIS_BRANCH
is set to master
. Then the diff
would be your PR commits. You can try it.
I already tested this PR within my forked material2
repo. And just did another one:
https://travis-ci.org/chouclee/material2/builds/234685761 (md
file change only)
https://travis-ci.org/chouclee/material2/builds/234687221 (md
and js
file, this is a hard push to update PR).
You can find the tests were skipped in first CI build, but not in second one.
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.
I didn't talk about PRs. Also good that you tested it for PRs.
Can you try merging your PR on your fork and see if everything works there too?
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.
I see what you meant. You are right, for Push build, the diff
would be empty.
I should check the $TRAVIS_PULL_REQUEST
first.
And I did a little search:
https://github.com/GoogleCloudPlatform/python-docs-samples/blob/72fa14b3957cacfdfe3113d14b8d77204f7ec9f7/nox.py#L84
If it's a Push, there are two choices. $TRAVIS_COMMIT
or $TRAVIS_COMMIT_RANGE
. Then the question is, do material2
allow any user directly push commits to master without a PR? If it's not allowed, then both variables look fine to me since we cannot force update a Pull Request
commit.
Another thing came to my mind, maybe we can just skip CI build if only docs are being changed. |
@chouclee isn't that what this already is? |
@chouclee You are talking about the "per-commit" builds right? I don't think we should skip those. The |
@devversion PR updated. |
scripts/ci/build-and-test.sh
Outdated
skip_tests=false | ||
break | ||
fi | ||
done |
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.
Thinking if we could make it more simple
if [[ "$TRAVIS_PULL_REQUEST" = "false" ]]; then
fileDiff=$(git diff --name-only $TRAVIS_COMMIT_RANGE)
else
fileDiff=$(git diff --name-only $TRAVIS_BRANCH...HEAD)
fi
if [[ ${fileDiff} =~ ^(.*\.md\s*)*$ ]] && (is_e2e || is_unit); then
echo "Skipping e2e and unit tests since only markdown files changed"
exit 0
fi
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.
Cool, I just learned something new from you.
Only two things:
-
[[ "$TRAVIS_PULL_REQUEST" = "false" ]]
would print as+[[ false = \f\a\l\s\e ]]
in Travis output, and quotes are unnecessary.
[ "$TRAVIS_PULL_REQUEST" = "false" ] would print as ``+[[ false = false ]]. I think it's more readable. -
I changed the regex
${fileDiff} =~ ^(.*\.md\s*)*$
to${fileDiff} =~ ^(.*\.md\s*)+$
. Although I doubt anyone would push an empty commit...
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.
No problem
- I didn't write that. Just copied it from your PR changes
- It's fine. But I prefer the
*
just to be on the saf eside.
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.
Do you mind sharing that why *
is safer here?
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.
Just in case there would be any empty commit. Which happens very unlikely but it just gives us the flexibility. No real benefit of using +
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.
I am confused... +
is to tackle the empty commit case (e.g. trigger CI with an empty commit)...
If it's an empty commit, *
would skip the tests, but +
would't. The feature here is to skip tests only md
files are changed. That's why I use +
-- skip tests iff md
files are changed.
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.
If the commit is empty then it's fine to skip the tests as well. No source code change is 100% guaranteed.
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.
Sure. I restored +
to *
.
Skip e2e and unit tests for Push/PR build
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.
LGTM
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.
LGTM
@chouclee By the way. Thanks for your work! It works perfectly 🎉 |
@devversion I am glad to hear that. Thanks for your review. 😄 |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Skip both unit tests and e2e tests on CI when commits contain only markdown files (
*.md
)solves #3967