[CI] Refactor composite action task-cache (#9583)
## Introduction In this previous PR https://github.com/twentyhq/twenty/pull/9448 we've refactored the storybook build caching flow to be using the new [actions/cache](https://github.com/actions/cache) `restore` and `save` functions, which significantly improve caching operations duration. In this way, in this PR, we've standardize both of the `restore` and `save` by refactoring the `task-cache` composite action. By creating two new composite actions `save-cache` and `restore-cache` that centralize the paths to cache and the way to compute the primary key. ## Misc - **If no cache** is hit, then a job duration will long for its task duration and nothing else, previously the cache upload would sometimes take up to 3 mins. - **if cache** is hit, then mainly the only time consuming step is the dependencies installation ( which is theory is also cached, in fact twice. We will be having a look on this issue in an upcoming PR )
This commit is contained in:
32
.github/workflows/actions/restore-cache/action.yml
vendored
Normal file
32
.github/workflows/actions/restore-cache/action.yml
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
name: Restore cache
|
||||
inputs:
|
||||
key:
|
||||
required: true
|
||||
description: Prefix to the cache key
|
||||
type: string
|
||||
additional-paths:
|
||||
required: false
|
||||
type: string
|
||||
outputs:
|
||||
cache-primary-key:
|
||||
description: actions/cache/restore cache-primary-key outputs proxy
|
||||
value: ${{ steps.restore-cache.outputs.cache-primary-key }}
|
||||
cache-hit:
|
||||
description: String bool indicating whether cache has been directly or indirectly hit
|
||||
value: ${{ steps.restore-cache.outputs.cache-hit != 'false' || steps.restore-cache.outputs.cache-matched-key != '' }}
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Restore cache
|
||||
uses: actions/cache/restore@v4
|
||||
id: restore-cache
|
||||
with:
|
||||
path: |
|
||||
.cache
|
||||
.nx/cache
|
||||
node_modules/.cache
|
||||
packages/*/node_modules/.cache
|
||||
${{ inputs.additional-paths }}
|
||||
key: ${{ inputs.key }}-${{ github.ref_name }}-${{ github.sha }}
|
||||
restore-keys: ${{ inputs.key }}-${{ github.ref_name }}-
|
||||
23
.github/workflows/actions/save-cache/action.yml
vendored
Normal file
23
.github/workflows/actions/save-cache/action.yml
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
name: Save cache
|
||||
inputs:
|
||||
key:
|
||||
required: true
|
||||
description: Primary key to the cache, should be retrieved from `cache-restore` composite action outputs.
|
||||
type: string
|
||||
additional-paths:
|
||||
required: false
|
||||
type: string
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: Save cache
|
||||
uses: actions/cache/save@v4
|
||||
with:
|
||||
key: ${{ inputs.key }}
|
||||
path: |
|
||||
.cache
|
||||
.nx/cache
|
||||
node_modules/.cache
|
||||
packages/*/node_modules/.cache
|
||||
${{ inputs.additional-paths }}
|
||||
31
.github/workflows/actions/task-cache/action.yaml
vendored
31
.github/workflows/actions/task-cache/action.yaml
vendored
@ -1,31 +0,0 @@
|
||||
name: Restore Tasks Cache CI
|
||||
inputs:
|
||||
tag:
|
||||
required: false
|
||||
types: [string]
|
||||
tasks:
|
||||
required: false
|
||||
types: [string]
|
||||
default: all
|
||||
suffix:
|
||||
required: false
|
||||
types: [string]
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: Compute tasks key
|
||||
id: tasks-key
|
||||
shell: bash
|
||||
run: echo "key=${{ inputs.tasks }}" | tr , - >> $GITHUB_OUTPUT
|
||||
- name: Restore tasks cache
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: |
|
||||
.cache
|
||||
.nx/cache
|
||||
node_modules/.cache
|
||||
packages/*/node_modules/.cache
|
||||
key: tasks-cache-${{ github.ref_name }}-${{ inputs.tag }}-${{ steps.tasks-key.outputs.key }}${{ inputs.suffix }}-${{ github.sha }}
|
||||
restore-keys: |
|
||||
tasks-cache-${{ github.ref_name }}-${{ inputs.tag }}-${{ steps.tasks-key.outputs.key }}${{ inputs.suffix }}-
|
||||
Reference in New Issue
Block a user