diff --git a/.github/actions/setup-cache/action.yml b/.github/actions/setup-cache/action.yml new file mode 100644 index 00000000..1358d19a --- /dev/null +++ b/.github/actions/setup-cache/action.yml @@ -0,0 +1,32 @@ +name: Setup Cache +description: Prepare Snack's build cache in GitHub Actions + +runs: + using: composite + steps: + - name: 🔍 Find modules cache + id: modules-cache + run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT + shell: bash + + - name: ♻️ Restore modules cache + uses: actions/cache@v3 + with: + path: ${{ steps.modules-cache.outputs.dir }} + key: yarn-TEST_1-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + yarn-TEST_1-${{ runner.os }}- + + - name: 📦 Install monorepo dependencies + run: yarn install --frozen-lockfile + shell: bash + + - name: ♻️ Restore build cache + uses: actions/cache@v3 + with: + key: turbo-TEST_4-${{ runner.os }}-${{ github.sha }} + restore-keys: | + turbo-TEST_4-${{ runner.os }}- + path: | + node_modules/.cache/turbo + packages/*/.turbo diff --git a/.github/workflows/packages.yml b/.github/workflows/packages.yml index 354df791..f27cd92a 100644 --- a/.github/workflows/packages.yml +++ b/.github/workflows/packages.yml @@ -8,6 +8,7 @@ on: workflow_dispatch: pull_request: paths: + - .github/actions/setup-cache/** - .github/workflows/packages.yml - packages/** - .eslint* @@ -17,6 +18,7 @@ on: push: branches: [main] paths: + - .github/actions/setup-cache/** - .github/workflows/packages.yml - packages/** - .eslint* @@ -54,10 +56,9 @@ jobs: uses: actions/setup-node@v3 with: node-version: 18.x - cache: yarn - - name: 📦 Install monorepo dependencies - run: yarn install --frozen-lockfile + - name: 🏗 Setup cache + uses: ./.github/actions/setup-cache # When coupled within the monorepo, make sure to build all packages related to the tested one - name: 🛠 Build dependencies