From e990cbba01dbe7fc316eb61f56a93f894dc2ba2c Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Thu, 13 Jul 2023 11:03:29 +0200 Subject: [PATCH] Configured storing Nx cache in GHA to speed up builds refs https://github.com/TryGhost/DevOps/issues/47 - this allows us to store and restore the cache for TS builds, which should speed up the whole process --- .github/workflows/ci.yml | 14 +++++++++++++- .gitignore | 3 +++ nx.json | 3 ++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 570982ce80..5d1904b148 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,6 +20,10 @@ env: ~/.cache/ms-playwright/ CACHED_BUILD_PATHS: | ${{ github.workspace }}/ghost/*/build + NX_CACHE_RESTORE_KEYS: | + nx-Linux-${{ github.ref }}-${{ github.sha }} + nx-Linux-${{ github.ref }} + nx-Linux concurrency: group: ${{ github.head_ref || github.run_id }} @@ -100,7 +104,7 @@ jobs: changed_any_code: ${{ steps.changed.outputs.any-code }} base_commit: ${{ env.BASE_COMMIT }} is_canary_branch: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/arch') }} - is_git_sync: ${{ github.head_ref == 'main' || github.ref == 'refs/heads/main' }} + is_main: ${{ github.ref == 'refs/heads/main' }} job_install_deps: name: Install Dependencies @@ -117,6 +121,14 @@ jobs: id: compute_lockfile_hash run: echo "hash=${{ hashFiles('yarn.lock') }}" >> "$GITHUB_OUTPUT" + - name: Nx cache + uses: actions/cache@v3 + id: cache_nx + with: + path: .nxcache + key: nx-Linux-${{ github.ref }}-${{ env.HEAD_COMMIT }} + restore-keys: ${{needs.job_get_metadata.outputs.is_main == 'false' && env.NX_CACHE_RESTORE_KEYS || 'nx-never-restore'}} + - name: Check dependency cache uses: actions/cache@v3 id: cache_dependencies diff --git a/.gitignore b/.gitignore index 56e6e43263..d34e475636 100644 --- a/.gitignore +++ b/.gitignore @@ -48,6 +48,9 @@ typings/ # Optional npm cache directory .npm +# Nx cache +.nxcache + # Optional eslint cache .eslintcache diff --git a/nx.json b/nx.json index 0669a990e4..4d368d0265 100644 --- a/nx.json +++ b/nx.json @@ -8,7 +8,8 @@ "lint", "test", "test:unit" - ] + ], + "cacheDirectory": ".nxcache" } } },