Best practices for caching npm + Playwright + pre-commit in GitHub Action #187290
Replies: 2 comments 1 reply
-
|
Excellent question! Here are best practices for caching each component in GitHub Actions: 1. npm packagesUse the - name: Cache npm dependencies
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles(package-lock.json) }}
restore-keys: |
${{ runner.os }}-npm-2. Playwright browsersCache the Playwright browser binaries: - name: Cache Playwright browsers
uses: actions/cache@v4
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles(package-lock.json) }}3. pre-commit hooksCache the pre-commit environment: - name: Cache pre-commit
uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: ${{ runner.os }}-pre-commit-${{ hashFiles(.pre-commit-config.yaml) }}
restore-keys: |
${{ runner.os }}-pre-commit-Full example workflow:jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache npm
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles(package-lock.json) }}
- name: Cache Playwright
uses: actions/cache@v4
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles(package-lock.json) }}
- name: Cache pre-commit
uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: ${{ runner.os }}-pre-commit-${{ hashFiles(.pre-commit-config.yaml) }}
- name: Install dependencies
run: npm ci
- name: Install Playwright browsers
run: npx playwright install --with-deps
- name: Run pre-commit
uses: pre-commit/action@v3.0.1This setup should significantly speed up your CI runs by avoiding redundant installations! |
Beta Was this translation helpful? Give feedback.
-
|
🕒 Discussion Activity Reminder 🕒 This Discussion has been labeled as dormant by an automated system for having no activity in the last 60 days. Please consider one the following actions: 1️⃣ Close as Out of Date: If the topic is no longer relevant, close the Discussion as 2️⃣ Provide More Information: Share additional details or context — or let the community know if you've found a solution on your own. 3️⃣ Mark a Reply as Answer: If your question has been answered by a reply, mark the most helpful reply as the solution. Note: This dormant notification will only apply to Discussions with the Thank you for helping bring this Discussion to a resolution! 💬 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Why are you starting this discussion?
Question
What GitHub Actions topic or product is this about?
General
Discussion Details
I'm trying to optimize my CI workflow by adding caching.
Current setup that needs caching:
Each run reinstalls everything from scratch. What's the best way to cache:
Any examples or recommended actions?
Beta Was this translation helpful? Give feedback.
All reactions