The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
[CI] Refactor composite action task-cache (#9583)
Paul Rastoin6fc691beb055
diff --git a/.github/workflows/actions/restore-cache/action.yml b/.github/workflows/actions/restore-cache/action.ymlnew file mode 100644index 00000000000..ae4a2cc0a1e--- /dev/null+++ b/.github/workflows/actions/restore-cache/action.yml@@ -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 }}-\ No newline at end of filediff --git a/.github/workflows/actions/save-cache/action.yml b/.github/workflows/actions/save-cache/action.ymlnew file mode 100644index 00000000000..a159b6a48a6--- /dev/null+++ b/.github/workflows/actions/save-cache/action.yml@@ -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 }}\ No newline at end of filediff --git a/.github/workflows/actions/task-cache/action.yaml b/.github/workflows/actions/task-cache/action.yamldeleted file mode 100644index c622c84a1e0..00000000000--- a/.github/workflows/actions/task-cache/action.yaml+++ /dev/null@@ -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 }}-\ No newline at end of filediff --git a/.github/workflows/ci-front.yaml b/.github/workflows/ci-front.yamlindex aa1b55e1824..75627be74e1 100644--- a/.github/workflows/ci-front.yaml+++ b/.github/workflows/ci-front.yaml@@ -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 .envif: 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-cachewith:- 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: 30runs-on: depot-ubuntu-22.04-8@@ -107,17 +99,11 @@ jobs:- name: Install Playwrightif: 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 .envif: 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@v4with: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 .envif: steps.changed-files.outputs.any_changed == 'true'run: |@@ -226,6 +206,7 @@ jobs:runs-on: depot-ubuntu-22.04-8env: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 dependenciesif: 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-cacheif: 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 .envif: steps.changed-files.outputs.any_changed == 'true'uses: ./.github/workflows/actions/nx-affected@@ -270,3 +251,8 @@ jobs:with:tag: scope:frontendtasks: ${{ 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 }}diff --git a/.github/workflows/ci-server.yaml b/.github/workflows/ci-server.yamlindex 03da78e9d8e..f278d759765 100644--- a/.github/workflows/ci-server.yaml+++ b/.github/workflows/ci-server.yaml@@ -10,6 +10,9 @@ concurrency:group: ${{ github.workflow }}-${{ github.ref }}cancel-in-progress: true+env:+ SERVER_SETUP_CACHE_KEY: server-setup+jobs:server-setup:timeout-minutes: 30@@ -57,11 +60,12 @@ jobs:- name: Build twenty-sharedif: steps.changed-files.outputs.any_changed == 'true'run: npx nx build twenty-shared- - name: Server / Restore Task Cache+ - name: Restore server setup+ id: restore-server-setup-cacheif: steps.changed-files.outputs.any_changed == 'true'- uses: ./.github/workflows/actions/task-cache+ uses: ./.github/workflows/actions/restore-cachewith:- tag: scope:backend+ key: ${{ env.SERVER_SETUP_CACHE_KEY }}- name: Server / Run lint & typecheckif: steps.changed-files.outputs.any_changed == 'true'uses: ./.github/workflows/actions/nx-affected@@ -103,6 +107,11 @@ jobs:exit 1fi+ - name: Save server setup+ if: steps.changed-files.outputs.any_changed == 'true' && steps.restore-server-setup-cache.outputs.cache-hit != 'true'+ uses: ./.github/workflows/actions/save-cache+ with:+ key: ${{ steps.restore-server-setup-cache.outputs.cache-primary-key }}server-test:timeout-minutes: 30@@ -129,11 +138,11 @@ jobs:- name: Install dependenciesif: steps.changed-files.outputs.any_changed == 'true'uses: ./.github/workflows/actions/yarn-install- - name: Server / Restore Task Cache+ - name: Restore server setupif: steps.changed-files.outputs.any_changed == 'true'- uses: ./.github/workflows/actions/task-cache+ uses: ./.github/workflows/actions/restore-cachewith:- tag: scope:backend+ key: ${{ env.SERVER_SETUP_CACHE_KEY }}- name: Server / Run Testsif: steps.changed-files.outputs.any_changed == 'true'uses: ./.github/workflows/actions/nx-affected@@ -191,11 +200,11 @@ jobs:echo "BILLING_STRIPE_API_KEY=test-api-key" >> .env.testecho "BILLING_STRIPE_BASE_PLAN_PRODUCT_ID=test-base-plan-product-id" >> .env.testecho "BILLING_STRIPE_WEBHOOK_SECRET=test-webhook-secret" >> .env.test- - name: Server / Restore Task Cache+ - name: Restore server setupif: steps.changed-files.outputs.any_changed == 'true'- uses: ./.github/workflows/actions/task-cache+ uses: ./.github/workflows/actions/restore-cachewith:- tag: scope:backend+ key: ${{ env.SERVER_SETUP_CACHE_KEY }}- name: Server / Run Integration Testsif: steps.changed-files.outputs.any_changed == 'true'uses: ./.github/workflows/actions/nx-affected