You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ci: skip riot runs based on diff from last successful run (second attempt) [backport 1.18] (#6636)
Backport 5875e8a from #6631 to 1.18.
__Based on #6600, which was reverted from 1.x__
This pull request reduces the amount of duplicated work done in CI on
pull request builds by skipping a given riot job based on the changes
since the last time that job succeeded.
The approach taken here reduces the amount of time spent waiting for
jobs to pass after updating a branch from trunk, ensuring that only
those jobs that might have been affected by the update are run.
This logic is supported by CircleCI's `save_cache` and `restore_cache`
directives. The cache key includes the branch name, job name, and node
number to ensure uniqueness for each branch/job/node combination.
`restore_cache` uses a prefix match on this key format.
No new skips are applied on `*.x` branches, which mitigates much of the
risk of this change.
Here's a detailed description of the logical flow.
1. A commit with SHA `A` is pushed to a new branch, changing
`contrib/cherrypy/middleware.py`.
2. As on current 1.x, CI jobs are selected based on the commit's diff.
The `cherrypy` job starts.
3. The `restore_cache` step in the `cherrypy` job finds no cache.
4. The `cherrypy` job succeeds and writes a file to the CI runner's
filesystem containing the Git hash of the current HEAD, `A`. This is the
"latest successful commit" for the `cherrypy` job on this branch.
5. The `save_cache` step caches this file under a key that includes the
branch name, `cherrypy`, and the epoch timestamp.
6. Another commit with SHA `B` is pushed to the branch, changing
`contrib/falcon/patch.py`. The branch now contains changes to `falcon`
and `cherrypy`.
7. The dynamic configuration generator selects the `falcon` and
`cherrypy` jobs to run.
8. In the `falcon` job, the `restore_cache` step finds no cache at the
key `*-falcon-*`. In the `cherrypy` job, this step finds a cache.
9. The `falcon` job runs similarly to steps 4 and 5. The `cherrypy` job
opens the file it found in the cache and passes the resulting Git SHA to
`needs_testrun.py`. This script runs `git diff B A`, finds that none of
the changes in that diff affect `cherrypy`, and exits before running
`riot`.
**Why not do this check during the setup step?**
The new diff check added in this pull request requires access to the
CircleCI cache on a per-job basis, which is only available from inside
each job.
**How was this tested?**
1. [This
commit](https://app.circleci.com/pipelines/github/DataDog/dd-trace-py/43108/workflows/c149c29b-d3b2-47dc-b1f0-06696d865134)
changed the `pylons` and `asynctest` suites, causing the `asynctest`
suite to fail. CI correctly shows both the pass and the fail.
2. [This
commit](https://app.circleci.com/pipelines/github/DataDog/dd-trace-py/43117/workflows/0ffa0c7e-7e9c-41ee-852c-3b691b120f1a)
fixed the `asynctest` failure. CI shows that the `pylons` job was
skipped and the `asynctest` job was re-run.
3. [This
commit](https://app.circleci.com/pipelines/github/DataDog/dd-trace-py/43118/workflows/00174ec3-98ad-46a1-8b58-35811feda777)
reverted the changes to both suites. CI did not queue either of them.
## Checklist
- [x] Change(s) are motivated and described in the PR description.
- [x] Testing strategy is described if automated tests are not included
in the PR.
- [x] Risk is outlined (performance impact, potential for breakage,
maintainability, etc).
- [x] Change is maintainable (easy to change, telemetry, documentation).
- [x] [Library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
are followed. If no release note is required, add label
`changelog/no-changelog`.
- [x] Documentation is included (in-code, generated user docs, [public
corp docs](https://github.com/DataDog/documentation/)).
- [x] Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))
## Reviewer Checklist
- [x] Title is accurate.
- [x] No unnecessary changes are introduced.
- [x] Description motivates each change.
- [x] Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes unless absolutely necessary.
- [x] Testing strategy adequately addresses listed risk(s).
- [x] Change is maintainable (easy to change, telemetry, documentation).
- [x] Release note makes sense to a user of the library.
- [x] Reviewer has explicitly acknowledged and discussed the performance
implications of this PR as reported in the benchmarks PR comment.
- [x] Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
Co-authored-by: Emmett Butler <[email protected]>
0 commit comments