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
on:
pull_request:
types: [opened, synchronize, reopened]
concurrency:
group: ci-pipeline-${{ github.head_ref }}
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
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:
name: Setup Dependencies
needs: check_changes
if: ${{ needs.check_changes.outputs.exists == 'true' }}
runs-on: ubuntu-latest
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: Cache node_modules
id: cache-deps
- name: Check if node_modules cache exists
id: check-node-modules-cache
uses: actions/cache@v4
with:
path: |
.turbo
node_modules
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
- name: Verify pnpm installation
run: pnpm --version
- name: Install dependencies
run: pnpm install --frozen-lockfile
*/node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/pnpm-lock.yaml') }}
lookup-only: true
eslint:
runs-on: ubuntu-latest
needs: setup
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- uses: pnpm/action-setup@v4
node-version: lts/*
- name: Setup pnpm
if: steps.check-node-modules-cache.outputs.cache-hit != 'true'
uses: pnpm/action-setup@v4
with:
version: 10.11.0
- name: Restore node_modules from cache
uses: actions/cache@v4
run_install: false
- 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:
path: |
.turbo
node_modules
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
- name: Run Eslint check
run: pnpm exec turbo run lint
*/node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/pnpm-lock.yaml') }}
prettier:
quality_checks:
name: ${{ matrix.name }}
needs: [check_changes, setup]
if: ${{ needs.check_changes.outputs.exists == 'true' }}
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:
- 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:
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
- name: Restore Turborepo Cache
uses: actions/cache@v4
with:
path: |
.turbo
node_modules
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
- name: Run cspell check
run: pnpm exec turbo run spell
path: .turbo
key: ${{ runner.os }}-turbo-${{ matrix.check }}-${{ github.sha }}
restore-keys: ${{ runner.os }}-turbo-${{ matrix.check }}-
vitest:
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
- name: Restore node_modules cache
uses: actions/cache/restore@v4
with:
path: |
.turbo
node_modules
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
- name: Run Vitest tests
run: pnpm exec turbo test
*/node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: ${{ runner.os }}-node-modules-
build:
runs-on: ubuntu-latest
needs: setup
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
- uses: pnpm/action-setup@v4
- name: Setup pnpm
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: Build project
run: pnpm exec turbo run build
- name: Upload build output
uses: actions/upload-artifact@v4
with:
name: build
path: |
dist
run_install: false
- name: Run ${{ matrix.name }}
run: pnpm exec turbo run ${{ matrix.check }}
playwright:
name: Playwright Tests
needs: [check_changes, setup, quality_checks]
if: ${{ needs.check_changes.outputs.exists == 'true' }}
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- 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
- name: Restore Turborepo Cache
uses: actions/cache@v4
with:
path: |
.turbo
node_modules
path: .turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
restore-keys: ${{ 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
run: pnpm exec playwright install --with-deps
- name: Download build output
uses: actions/download-artifact@v4
with:
name: build
path: dist
- name: Run Playwright tests
- name: Run Playwright Tests
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",
"Ribaric",
"taroj",
"Turborepo",
"testid",
"theming",
"tuta",
@ -65,6 +66,7 @@
"wmfcdm",
"XPCOM",
"xmark",
"yumemi",
"zsync"
],
"flagWords": [],

View file

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

6
pnpm-lock.yaml generated
View file

@ -89,6 +89,9 @@ importers:
tailwindcss:
specifier: 3.4.15
version: 3.4.15
turbo:
specifier: ^2.5.4
version: 2.5.4
typescript:
specifier: 5.6.3
version: 5.6.3
@ -204,9 +207,6 @@ importers:
prettier-plugin-tailwindcss:
specifier: ^0.6.11
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:
specifier: 8.33.0
version: 8.33.0(eslint@9.27.0(jiti@2.4.2))(typescript@5.6.3)

View file

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