Skip to content

Commit

Permalink
Cache .git to improve checkout time (#33845)
Browse files Browse the repository at this point in the history
Summary:
Caching the .git to speed up the checkout.

https://circleci.com/docs/2.0/caching/#source-caching

<img width="1429" alt="Screenshot 2022-05-17 at 11 11 54" src="https://user-images.githubusercontent.com/17830956/168787771-5501b113-674e-4d43-b93f-90bf46882c14.png">

This doesn't work on the machines that use a docker executor

<img width="1426" alt="Screenshot 2022-05-17 at 12 17 14" src="https://user-images.githubusercontent.com/17830956/168789017-538a6d04-c53d-4ac7-ba12-0eccff397675.png">

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[Infrastructure] - Cache .git to improve checkout time

Pull Request resolved: #33845

Test Plan: Run the change on Circle

Reviewed By: hramos, cortinico

Differential Revision: D36443844

Pulled By: f-meloni

fbshipit-source-id: 7b07e177f4527ed5956f03ad622838f20ad64950
  • Loading branch information
f-meloni authored and facebook-github-bot committed May 18, 2022
1 parent 56e9aa3 commit 7b703eb
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ references:

cache_keys:
buck_cache_key: &buck_cache_key v3-buck-v2019.01.10.01-{{ checksum "scripts/circleci/buck_fetch.sh" }}}
checkout_cache_key: &checkout_cache_key v1-checkout
gems_cache_key: &gems_cache_key v1-gems-{{ checksum "Gemfile.lock" }}
gradle_cache_key: &gradle_cache_key v1-gradle-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}-{{ checksum "ReactAndroid/gradle.properties" }}
hermes_cache_key: &hermes_cache_key v1-hermes-{{ .Environment.CIRCLE_JOB }}-{{ checksum "/tmp/hermes/hermesversion" }}
Expand Down Expand Up @@ -102,6 +103,23 @@ executors:
# COMMANDS
# -------------------------
commands:
# Checkout with cache, on machines that are using Docker the cache is ignored
checkout_code_with_cache:
parameters:
checkout_base_cache_key:
default: *checkout_cache_key
type: string
steps:
- restore_cache:
keys:
- << parameters.checkout_base_cache_key >>-{{ .Branch }}-{{ .Revision }}
- << parameters.checkout_base_cache_key >>-{{ .Branch }}-
- << parameters.checkout_base_cache_key >>
- checkout
- save_cache:
key: << parameters.checkout_base_cache_key >>-{{ .Branch }}-{{ .Revision }}
paths:
- ".git"

setup_artifacts:
steps:
Expand Down Expand Up @@ -419,7 +437,7 @@ jobs:
environment:
- REPORTS_DIR: "./reports/junit"
steps:
- checkout
- checkout_code_with_cache
- setup_artifacts
- setup_ruby
- run:
Expand Down Expand Up @@ -657,7 +675,7 @@ jobs:
- PROJECT_NAME: "iOSTemplateProject"

steps:
- checkout
- checkout_code_with_cache
- run_yarn
- attach_workspace:
at: .
Expand Down Expand Up @@ -687,7 +705,7 @@ jobs:
test_ios_rntester:
executor: reactnativeios
steps:
- checkout
- checkout_code_with_cache
- run_yarn

# The macOS machine can run out of storage if Hermes is enabled and built from source.
Expand Down Expand Up @@ -742,7 +760,7 @@ jobs:
- ANDROID_TOOLS_VERSION: 31.0.0
- GRADLE_OPTS: -Dorg.gradle.daemon=false
steps:
- checkout
- checkout_code_with_cache

- run:
name: Install Node
Expand Down Expand Up @@ -933,7 +951,7 @@ jobs:
environment:
- HERMES_WS_DIR: *hermes_workspace_root
steps:
- checkout
- checkout_code_with_cache
- *attach_hermes_workspace
- restore_cache:
key: *hermes_cache_key
Expand Down Expand Up @@ -1057,7 +1075,7 @@ jobs:
default: false
executor: reactnativeios
steps:
- checkout
- checkout_code_with_cache
- run_yarn
- add_ssh_keys:
fingerprints:
Expand Down

0 comments on commit 7b703eb

Please sign in to comment.