Skip to content

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

Merged
merged 1 commit into from
May 23, 2017
Merged

build(ci): skip tests on CI when only markdown files have changed #4452

merged 1 commit into from
May 23, 2017

Conversation

chouclee
Copy link
Contributor

@chouclee chouclee commented May 10, 2017

Skip both unit tests and e2e tests on CI when commits contain only markdown files (*.md)
solves #3967

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label May 10, 2017
@chouclee chouclee changed the title build(ci): skip tests if only markdown files are changed build(ci): skip tests on CI when only markdown files have changed May 10, 2017
@chouclee chouclee closed this May 10, 2017
@chouclee chouclee reopened this May 10, 2017
@jelbourn jelbourn requested a review from devversion May 15, 2017 22:00
for filename in $(git diff --name-only $TRAVIS_BRANCH...HEAD); do
if ! [[ "$filename" =~ .*\.md ]]; then
skip_tests=false
break
Copy link
Member

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?

Copy link
Contributor Author

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.

@@ -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
Copy link
Member

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?

Copy link
Contributor Author

@chouclee chouclee May 20, 2017

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)

Copy link
Member

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.

Copy link
Contributor Author

@chouclee chouclee May 22, 2017

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.

Copy link
Member

@devversion devversion May 22, 2017

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?

Copy link
Contributor Author

@chouclee chouclee May 22, 2017

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.

@chouclee
Copy link
Contributor Author

Another thing came to my mind, maybe we can just skip CI build if only docs are being changed.
What do you think about? @jelbourn

@jelbourn
Copy link
Member

@chouclee isn't that what this already is?

@devversion
Copy link
Member

@chouclee You are talking about the "per-commit" builds right?

I don't think we should skip those. The material2-docs-content still needs to be deployed and I think it's still good to publish the material2-builds for every commit that lands in master. (As same as in @angular/angular)

@chouclee chouclee closed this May 22, 2017
@chouclee chouclee deleted the build-skip-tests branch May 22, 2017 04:38
@chouclee chouclee restored the build-skip-tests branch May 22, 2017 04:38
@chouclee chouclee reopened this May 22, 2017
@chouclee chouclee closed this May 22, 2017
@chouclee chouclee reopened this May 22, 2017
@chouclee
Copy link
Contributor Author

@devversion PR updated.

skip_tests=false
break
fi
done
Copy link
Member

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

Copy link
Contributor Author

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:

  1. [[ "$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.

  2. I changed the regex ${fileDiff} =~ ^(.*\.md\s*)*$ to ${fileDiff} =~ ^(.*\.md\s*)+$. Although I doubt anyone would push an empty commit...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem

  1. I didn't write that. Just copied it from your PR changes
  2. It's fine. But I prefer the * just to be on the saf eside.

Copy link
Contributor Author

@chouclee chouclee May 22, 2017

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?

Copy link
Member

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 +

Copy link
Contributor Author

@chouclee chouclee May 22, 2017

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.

Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

@devversion devversion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@devversion devversion added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels May 23, 2017
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tinayuangao tinayuangao merged commit aee42ae into angular:master May 23, 2017
@chouclee chouclee deleted the build-skip-tests branch May 23, 2017 21:17
@devversion
Copy link
Member

@chouclee By the way. Thanks for your work! It works perfectly 🎉

@chouclee
Copy link
Contributor Author

@devversion I am glad to hear that. Thanks for your review. 😄

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants