[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:
Paul Rastoin
2025-01-14 12:06:23 +01:00
committed by GitHub
parent 90d984d27d
commit 6fc691beb0
5 changed files with 105 additions and 86 deletions

View File

@ -10,6 +10,9 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
STORYBOOK_BUILD_CACHE_KEY: storybook-build-depot-ubuntu-22.04-8-runner
jobs:
front-sb-build:
timeout-minutes: 30
@ -46,17 +49,11 @@ jobs:
if: steps.changed-files.outputs.any_changed == 'true'
run: df -h
- name: Restore storybook build cache
id: storybook-build-cache-restore
uses: actions/cache/restore@v4
with:
path: |
.cache
.nx/cache
node_modules/.cache
packages/*/node_modules/.cache
key: storybook-build-depot-ubuntu-22.04-8-runner-${{ github.ref_name }}-${{ github.sha }}
restore-keys: |
storybook-build-depot-ubuntu-22.04-8-runner-${{ github.ref_name }}-
id: restore-storybook-build-cache
if: steps.changed-files.outputs.any_changed == 'true'
uses: ./.github/workflows/actions/restore-cache
with:
key: ${{ env.STORYBOOK_BUILD_CACHE_KEY }}
- name: Front / Write .env
if: steps.changed-files.outputs.any_changed == 'true'
run: npx nx reset:env twenty-front
@ -64,15 +61,10 @@ jobs:
if: steps.changed-files.outputs.any_changed == 'true'
run: npx nx storybook:build twenty-front
- name: Save storybook build cache
if: steps.storybook-build-cache-restore.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
if: steps.changed-files.outputs.any_changed == 'true' && steps.restore-storybook-build-cache.outputs.cache-hit != 'true'
uses: ./.github/workflows/actions/save-cache
with:
key: ${{ steps.storybook-build-cache-restore.outputs.cache-primary-key }}
path: |
.cache
.nx/cache
node_modules/.cache
packages/*/node_modules/.cache
key: ${{ steps.restore-storybook-build-cache.outputs.cache-primary-key }}
front-sb-test:
timeout-minutes: 30
runs-on: depot-ubuntu-22.04-8
@ -107,17 +99,11 @@ jobs:
- name: Install Playwright
if: steps.changed-files.outputs.any_changed == 'true'
run: cd packages/twenty-front && npx playwright install
- name: Restore Storybook build cache
uses: actions/cache/restore@v4
with:
path: |
.cache
.nx/cache
node_modules/.cache
packages/*/node_modules/.cache
key: storybook-build-depot-ubuntu-22.04-8-runner-${{ github.ref_name }}-${{ github.sha }}
restore-keys: |
storybook-build-depot-ubuntu-22.04-8-runner-${{ github.ref_name }}-
- name: Restore storybook build cache
if: steps.changed-files.outputs.any_changed == 'true'
uses: ./.github/workflows/actions/restore-cache
with:
key: ${{ env.STORYBOOK_BUILD_CACHE_KEY }}
- name: Front / Write .env
if: steps.changed-files.outputs.any_changed == 'true'
run: npx nx reset:env twenty-front
@ -128,6 +114,7 @@ jobs:
if: steps.changed-files.outputs.any_changed == 'true'
run: mv packages/twenty-front/coverage/storybook/coverage-storybook.json packages/twenty-front/coverage/storybook/coverage-shard-${{matrix.shard}}.json
- name: Upload coverage artifact
if: steps.changed-files.outputs.any_changed == 'true'
uses: actions/upload-artifact@v4
with:
retention-days: 1
@ -201,17 +188,10 @@ jobs:
if: steps.changed-files.outputs.any_changed == 'true'
uses: ./.github/workflows/actions/yarn-install
- name: Restore storybook build cache
id: storybook-build-cache-restore
uses: actions/cache/restore@v4
with:
path: |
.cache
.nx/cache
node_modules/.cache
packages/*/node_modules/.cache
key: storybook-build-depot-ubuntu-22.04-8-runner-${{ github.ref_name }}-${{ github.sha }}
restore-keys: |
storybook-build-depot-ubuntu-22.04-8-runner-${{ github.ref_name }}-
if: steps.changed-files.outputs.any_changed == 'true'
uses: ./.github/workflows/actions/restore-cache
with:
key: ${{ env.STORYBOOK_BUILD_CACHE_KEY }}
- name: Front / Write .env
if: steps.changed-files.outputs.any_changed == 'true'
run: |
@ -226,6 +206,7 @@ jobs:
runs-on: depot-ubuntu-22.04-8
env:
NX_REJECT_UNKNOWN_LOCAL_CACHE: 0
TASK_CACHE_KEY: front-task-${{ matrix.task }}
strategy:
matrix:
task: [lint, typecheck, test]
@ -252,12 +233,12 @@ jobs:
- name: Install dependencies
if: steps.changed-files.outputs.any_changed == 'true'
uses: ./.github/workflows/actions/yarn-install
- name: Front / Restore ${{ matrix.task }} task cache
- name: Restore ${{ matrix.task }} cache
id: restore-task-cache
if: steps.changed-files.outputs.any_changed == 'true'
uses: ./.github/workflows/actions/task-cache
with:
tag: scope:frontend
tasks: ${{ matrix.task }}
uses: ./.github/workflows/actions/restore-cache
with:
key: ${{ env.TASK_CACHE_KEY }}
- name: Reset .env
if: steps.changed-files.outputs.any_changed == 'true'
uses: ./.github/workflows/actions/nx-affected
@ -270,3 +251,8 @@ jobs:
with:
tag: scope:frontend
tasks: ${{ matrix.task }}
- name: Save ${{ matrix.task }} cache
if: steps.changed-files.outputs.any_changed == 'true' && steps.restore-task-cache.outputs.cache-hit != 'true'
uses: ./.github/workflows/actions/save-cache
with:
key: ${{ steps.restore-task-cache.outputs.cache-primary-key }}