Skip to content
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

Adding Maven cache to CircleCI config #503

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,37 @@ version: 2
lint_steps: &lint_steps
steps:
- checkout
- restore_cache:
name: Restore Maven cache
keys:
# when pom.xml file changes, use increasingly general patterns to restore cache
# Linting has own cache as deps not downloaded during test phases. If doesn't exist will
# fall back on any available cache.
- &maven-cache maven-cache-{{ .Branch }}-{{ checksum "pom.xml" }}-lint
- maven-cache-{{ .Branch }}-
- maven-cache-
- run: ./mvnw verify -B -Dhttps.protocols=TLSv1.2 -DskipTests
- save_cache:
key: *maven-cache
paths:
- ~/.m2
build_steps: &build_steps
steps:
- checkout
- restore_cache:
name: Restore Maven cache
keys:
# when pom.xml file changes, use increasingly general patterns to restore cache
Copy link
Contributor

Choose a reason for hiding this comment

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

could you explain this a little? The save-cache step uses the maven-cache anchor, which appears to be defined here.

So the value for maven-cache is (for example) maven-cache-master-ab2c3ffef33. What are the other 2 below this then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The other two are there incase this is a brand new branch. If the branch is new it will then try and find the latest cache that begins maven-cache-{{ .Branch }}- and if that fails then just grabs the latest version of the cache that maches maven-cache- (i.e. any branch). It then will save the cache after the first run as maven-cache-{{ .Branch }}-{{ checksum "pom.xml" }}-lint as that is what the maven-cache anchor value is.

Copy link
Contributor

Choose a reason for hiding this comment

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

ooooh, thanks, that is helpful. So the anchor value for maven-cache is always the first (most specific) key. The cache-loading is circle-ci functionality that will pick the best key, but when it goes to save the key, it will save with the most specific key.

- &maven-cache maven-cache-{{ .Branch }}-{{ checksum "pom.xml" }}
- maven-cache-{{ .Branch }}-
- maven-cache-
- setup_remote_docker
- run: ./mvnw test -B -Dhttps.protocols=TLSv1.2 -Dcheckstyle.skip=true -Dtests.log_level=info -Djdk.attach.allowAttachSelf=true
- save_cache:
when: always # Save even when test fails so we can reuse cache
key: *maven-cache
paths:
- ~/.m2
- run:
when: on_fail
command: for log in target/surefire-reports/*.txt; do echo "$log ========================" ; cat $log ; done
Expand Down
Loading