DEV Community

Jest and the `--changedSince` flag in GitHub Actions CI

Tierney Cyren on April 09, 2020

Recently, I've been working a lot more with GitHub Actions - both writing actions and creating CI pipelines for projects. Last week I picked up a ...
Collapse
 
edvinasbartkus profile image
Edvinas Bartkus

Great write up!
Switching between branches can be avoided since we can simply fetch and then use "origin/master":

- uses: actions/checkout@v2
- run: git fetch --no-tags --depth=1 origin master
...
- run: yarn test --changedSince=origin/master --coverage
Enter fullscreen mode Exit fullscreen mode
Collapse
 
monapasan profile image
Oleg Yarin • Edited

Thank Tierney for a great post. Very much appreciated!
Do you have a working example with this solution?
I couldn't bring it to work. With you example:

${{ github.event.pull_request.head.sha }}
Enter fullscreen mode Exit fullscreen mode

This can't be resolved in my actions. I used this instead:

git checkout ${GITHUB_REF##*/}
Enter fullscreen mode Exit fullscreen mode

But jest still behaves very weirdly. It still doesn't recognize any changes, even though there are certainly changes with master.

Collapse
 
bnb profile image
Tierney Cyren

Here's an example of where it worked - we've since moved past it to a different model, but this CI setup fully worked: github.com/nodejs/examples/pull/4

Collapse
 
phollaki profile image
Puteáni-Holl Ákos

With actions/checkout@v3 now theres a cleaner way to do it:

- uses: actions/checkout@v3
  with:
    fetch-depth: 0
    ref: ${{ github.event.pull_request.head.sha }}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
ryands17 profile image
Ryan Dsouza

Would this be advisable for PR's that perform automatic dependency updates like Dependabot or Renovate or would I need to add a separate workflow for that?

Collapse
 
lsmonzon profile image
Lucas Monzon

I am trying to implement this change in the pull request event as result jest wants to execute all test