Skip to content

Commit

Permalink
Avoid cache collisions for PRs with same branch name
Browse files Browse the repository at this point in the history
by including unique PR number into cache key

CircleCI branch name substitution using {{ .Branch }}
does not prefix names with the repo name.
Thus PRs from separate forks using the same branch name could collide.

https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables
https://circleci.com/docs/2.0/configuration-reference/#save_cache
  • Loading branch information
ruffsl committed Jul 31, 2019
1 parent b40cdaa commit b99b98a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ references:
restore_ccache: &restore_ccache
restore_cache:
name: Restore CCache
key: ccache-v1-{{ arch }}-{{ .Branch }}-{{ checksum "/opt/ros_ws/checksum.txt" }}
key: ccache-v1-{{ arch }}-{{ .Branch }}-{{ .Environment.CIRCLE_PR_NUMBER }}-{{ checksum "/opt/ros_ws/checksum.txt" }}
restore_underlay_cache: &restore_underlay_cache
restore_cache:
name: Restore Underlay Cache
Expand Down Expand Up @@ -109,7 +109,7 @@ references:
restore_overlay_cache: &restore_overlay_cache
restore_cache:
name: Restore Overlay Cache
key: overlay-cache-v1-{{ arch }}-{{ .Branch }}-{{ checksum "/opt/nav2_ws/checksum.txt" }}
key: overlay-cache-v1-{{ arch }}-{{ .Branch }}-{{ .Environment.CIRCLE_PR_NUMBER }}-{{ checksum "/opt/nav2_ws/checksum.txt" }}
build_overlay: &build_overlay
run:
name: Build Overlay
Expand All @@ -130,14 +130,14 @@ references:
save_ccache: &save_ccache
save_cache:
name: Save CCache
key: ccache-v1-{{ arch }}-{{ .Branch }}-{{ checksum "/opt/ros_ws/checksum.txt" }}
key: ccache-v1-{{ arch }}-{{ .Branch }}-{{ .Environment.CIRCLE_PR_NUMBER }}-{{ checksum "/opt/ros_ws/checksum.txt" }}
paths:
- /root/.ccache
when: always
save_overlay_cache: &save_overlay_cache
save_cache:
name: Save Overlay Cache
key: overlay-cache-v1-{{ arch }}-{{ .Branch }}-{{ checksum "/opt/nav2_ws/checksum.txt" }}
key: overlay-cache-v1-{{ arch }}-{{ .Branch }}-{{ .Environment.CIRCLE_PR_NUMBER }}-{{ checksum "/opt/nav2_ws/checksum.txt" }}
paths:
- /opt/nav2_ws
copy_build_logs: &copy_build_logs
Expand Down

0 comments on commit b99b98a

Please sign in to comment.