ci(cache): improve ci cache in ci pipeline (#680)

* ci(cache): improve ci cache in ci pipeline

* refactor: use composite actions for ci jobs

* refactor: use composite action for node/pnpm setup

* refactor(ci): improve cache restore logic in ci pipeline

* fix(ci): fix ci node_modules cache handling

* fix(ci): improve ci pipeline cache

* fix(ci): fix ci pipeline cache

* fix(ci): upload cache properly

* fix(ci): add restore key

* refactor(ci): use matrix for simplified jobs

* refactor(ci): use matrix for simplified jobs

* fix(ci): remove problematic restore-keys from node_modules cache

* fix(ci): reorder cache logic

* chore: move turbo to dependency

* chore: update CI pipeline for improved testing workflow

* refactor(ci): enhance CI pipeline with matrix strategy for quality checks and cache management

* fix(ci): add restore-keys for improved cache efficiency

* fix(ci): add restore-keys for improved cache efficiency

* fix(ci): update cache action to use restore for node_modules
This commit is contained in:
Shintaro Jokagi 2025-06-18 17:18:13 +12:00 committed by GitHub
parent b6d59257c3
commit 6b7458c30e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 153 additions and 139 deletions

View file

@ -1,189 +1,200 @@
name: CI Pipeline name: CI Pipeline
on: on:
pull_request: pull_request:
types: [opened, synchronize, reopened] types: [opened, synchronize, reopened]
concurrency: concurrency:
group: ci-pipeline-${{ github.head_ref }} group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true cancel-in-progress: true
jobs: jobs:
check_changes:
name: Check Changes
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
exists: ${{ steps.filter.outputs.exists }}
steps:
- uses: actions/checkout@v4
- name: Filter changes
uses: yumemi-inc/path-filter@v2
id: filter
with:
patterns: |
**
!**.md
!.gitignore
!.gitattributes
!.vscode/**
!.env.example
setup: setup:
name: Setup Dependencies
needs: check_changes
if: ${{ needs.check_changes.outputs.exists == 'true' }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: - name: Check if node_modules cache exists
node-version: lts/* id: check-node-modules-cache
- uses: pnpm/action-setup@v4
with:
version: 10.11.0
- name: Cache node_modules
id: cache-deps
uses: actions/cache@v4 uses: actions/cache@v4
with: with:
path: | path: |
.turbo
node_modules node_modules
key: ${{ runner.os }}-turbo-${{ github.sha }} */node_modules
restore-keys: | key: ${{ runner.os }}-node-modules-${{ hashFiles('**/pnpm-lock.yaml') }}
${{ runner.os }}-turbo- lookup-only: true
- name: Verify pnpm installation
run: pnpm --version
- name: Install dependencies
run: pnpm install --frozen-lockfile
eslint:
runs-on: ubuntu-latest
needs: setup
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js - name: Setup Node.js
uses: actions/setup-node@v4 uses: actions/setup-node@v4
with: with:
node-version: 22 node-version: lts/*
- uses: pnpm/action-setup@v4
- name: Setup pnpm
if: steps.check-node-modules-cache.outputs.cache-hit != 'true'
uses: pnpm/action-setup@v4
with: with:
version: 10.11.0 version: 10.11.0
- name: Restore node_modules from cache run_install: false
uses: actions/cache@v4
- name: Install dependencies
if: steps.check-node-modules-cache.outputs.cache-hit != 'true'
run: pnpm install --frozen-lockfile
- name: Save node_modules cache
if: steps.check-node-modules-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with: with:
path: | path: |
.turbo
node_modules node_modules
key: ${{ runner.os }}-turbo-${{ github.sha }} */node_modules
restore-keys: | key: ${{ runner.os }}-node-modules-${{ hashFiles('**/pnpm-lock.yaml') }}
${{ runner.os }}-turbo-
- name: Run Eslint check
run: pnpm exec turbo run lint
prettier: quality_checks:
name: ${{ matrix.name }}
needs: [check_changes, setup]
if: ${{ needs.check_changes.outputs.exists == 'true' }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: setup strategy:
matrix:
include:
- check: lint
name: Lint
- check: format
name: Format
- check: test
name: Test
- check: spell
name: Spell Check
- check: build
name: Build
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- uses: pnpm/action-setup@v4
with:
version: 10.11.0
- name: Restore node_modules from cache
uses: actions/cache@v4
with:
path: |
.turbo
node_modules
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
- name: Run Prettier check
run: pnpm exec turbo run format
cspell: - name: Restore Turborepo Cache
runs-on: ubuntu-latest
needs: setup
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- uses: pnpm/action-setup@v4
with:
version: 10.11.0
- name: Restore node_modules from cache
uses: actions/cache@v4 uses: actions/cache@v4
with: with:
path: | path: .turbo
.turbo key: ${{ runner.os }}-turbo-${{ matrix.check }}-${{ github.sha }}
node_modules restore-keys: ${{ runner.os }}-turbo-${{ matrix.check }}-
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
- name: Run cspell check
run: pnpm exec turbo run spell
vitest: - name: Restore node_modules cache
runs-on: ubuntu-latest uses: actions/cache/restore@v4
needs: setup
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- uses: pnpm/action-setup@v4
with:
version: 10.11.0
- name: Restore node_modules from cache
uses: actions/cache@v4
with: with:
path: | path: |
.turbo
node_modules node_modules
key: ${{ runner.os }}-turbo-${{ github.sha }} */node_modules
restore-keys: | key: ${{ runner.os }}-node-modules-${{ hashFiles('**/pnpm-lock.yaml') }}
${{ runner.os }}-turbo- restore-keys: ${{ runner.os }}-node-modules-
- name: Run Vitest tests
run: pnpm exec turbo test
build: - name: Setup Node.js
runs-on: ubuntu-latest uses: actions/setup-node@v4
needs: setup
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: with:
node-version: lts/* node-version: lts/*
- uses: pnpm/action-setup@v4
- name: Setup pnpm
uses: pnpm/action-setup@v4
with: with:
version: 10.11.0 version: 10.11.0
- name: Restore node_modules from cache run_install: false
uses: actions/cache@v4
with: - name: Run ${{ matrix.name }}
path: | run: pnpm exec turbo run ${{ matrix.check }}
.turbo
node_modules
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
- name: Build project
run: pnpm exec turbo run build
- name: Upload build output
uses: actions/upload-artifact@v4
with:
name: build
path: |
dist
playwright: playwright:
name: Playwright Tests
needs: [check_changes, setup, quality_checks]
if: ${{ needs.check_changes.outputs.exists == 'true' }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: build
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
fetch-depth: 0 fetch-depth: 0
- uses: actions/setup-node@v4
with: - name: Restore Turborepo Cache
node-version: lts/*
- uses: pnpm/action-setup@v4
with:
version: 10.11.0
- name: Restore node_modules from cache
uses: actions/cache@v4 uses: actions/cache@v4
with: with:
path: | path: .turbo
.turbo
node_modules
key: ${{ runner.os }}-turbo-${{ github.sha }} key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: | restore-keys: ${{ runner.os }}-turbo-
${{ runner.os }}-turbo-
- name: Restore node_modules cache
uses: actions/cache/restore@v4
with:
path: |
node_modules
*/node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: ${{ runner.os }}-node-modules-
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.11.0
run_install: false
- name: Cache Playwright Browsers
uses: actions/cache@v4
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: ${{ runner.os }}-playwright-
- name: Install Playwright Browsers - name: Install Playwright Browsers
run: pnpm exec playwright install --with-deps run: pnpm exec playwright install --with-deps
- name: Download build output
uses: actions/download-artifact@v4 - name: Run Playwright Tests
with:
name: build
path: dist
- name: Run Playwright tests
run: pnpm exec turbo run test:playwright run: pnpm exec turbo run test:playwright
verify:
name: Verify
needs: [check_changes, quality_checks, playwright]
runs-on: ubuntu-latest
if: always()
outputs:
success: ${{ steps.set-result.outputs.success }}
steps:
- name: Set Result
id: set-result
run: |
# Check if changes exist but no jobs ran, or if any job failed or was cancelled
if [[ "${{ needs.check_changes.outputs.exists }}" != "true" ]]; then
echo "success=true" >> $GITHUB_OUTPUT
echo "No relevant changes detected - pipeline passed"
elif [[ "${{ contains(needs.*.result, 'failure') }}" == "true" || "${{ contains(needs.*.result, 'cancelled') }}" == "true" ]]; then
echo "success=false" >> $GITHUB_OUTPUT
echo "Pipeline failed - some jobs failed or were cancelled"
exit 1
else
echo "success=true" >> $GITHUB_OUTPUT
echo "All jobs completed successfully"
fi

View file

@ -52,6 +52,7 @@
"Pdzly", "Pdzly",
"Ribaric", "Ribaric",
"taroj", "taroj",
"Turborepo",
"testid", "testid",
"theming", "theming",
"tuta", "tuta",
@ -65,6 +66,7 @@
"wmfcdm", "wmfcdm",
"XPCOM", "XPCOM",
"xmark", "xmark",
"yumemi",
"zsync" "zsync"
], ],
"flagWords": [], "flagWords": [],

View file

@ -39,6 +39,7 @@
"@types/react-dom": "^19.1.5", "@types/react-dom": "^19.1.5",
"astro": "5.7.10", "astro": "5.7.10",
"astro-navbar": "2.3.7", "astro-navbar": "2.3.7",
"turbo": "^2.5.4",
"autoprefixer": "10.4.14", "autoprefixer": "10.4.14",
"clsx": "2.1.1", "clsx": "2.1.1",
"date-fns": "4.1.0", "date-fns": "4.1.0",
@ -92,7 +93,6 @@
"prettier": "3.5.3", "prettier": "3.5.3",
"prettier-plugin-astro": "0.14.1", "prettier-plugin-astro": "0.14.1",
"prettier-plugin-tailwindcss": "^0.6.11", "prettier-plugin-tailwindcss": "^0.6.11",
"turbo": "^2.5.4",
"typescript-eslint": "8.33.0", "typescript-eslint": "8.33.0",
"vite-tsconfig-paths": "5.1.4", "vite-tsconfig-paths": "5.1.4",
"vitest": "3.1.3", "vitest": "3.1.3",

6
pnpm-lock.yaml generated
View file

@ -89,6 +89,9 @@ importers:
tailwindcss: tailwindcss:
specifier: 3.4.15 specifier: 3.4.15
version: 3.4.15 version: 3.4.15
turbo:
specifier: ^2.5.4
version: 2.5.4
typescript: typescript:
specifier: 5.6.3 specifier: 5.6.3
version: 5.6.3 version: 5.6.3
@ -204,9 +207,6 @@ importers:
prettier-plugin-tailwindcss: prettier-plugin-tailwindcss:
specifier: ^0.6.11 specifier: ^0.6.11
version: 0.6.12(prettier-plugin-astro@0.14.1)(prettier@3.5.3) version: 0.6.12(prettier-plugin-astro@0.14.1)(prettier@3.5.3)
turbo:
specifier: ^2.5.4
version: 2.5.4
typescript-eslint: typescript-eslint:
specifier: 8.33.0 specifier: 8.33.0
version: 8.33.0(eslint@9.27.0(jiti@2.4.2))(typescript@5.6.3) version: 8.33.0(eslint@9.27.0(jiti@2.4.2))(typescript@5.6.3)

View file

@ -32,7 +32,8 @@
}, },
"test:playwright": { "test:playwright": {
"cache": true, "cache": true,
"inputs": ["**/*.{ts,tsx,js,jsx}"], "dependsOn": ["build"],
"inputs": ["**/*.{ts,tsx,js,jsx,astro}"],
"outputs": ["playwright-report/**", "test-results/**"] "outputs": ["playwright-report/**", "test-results/**"]
} }
}, },