Skip to content

Commit

Permalink
ci: cache dependencies (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Sep 3, 2023
1 parent ca9b405 commit 2a322e9
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 3 deletions.
65 changes: 65 additions & 0 deletions .github/actions/setup-and-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Setup and cache
description: Setup for node, pnpm and cache for dependencies
inputs:
node-version:
required: false
description: Node version for setup-node
default: 18.x

runs:
using: composite

steps:
- name: Install pnpm
uses: pnpm/action-setup@v2

- name: Set node version to ${{ inputs.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node-version }}

- name: Resolve pnpm store
id: resolve-pnpm-store
shell: bash
run: echo "PNPM_STORE=$(pnpm store path)" >> $GITHUB_OUTPUT

- name: Cache pnpm store ${{ steps.resolve-pnpm-store.outputs.PNPM_STORE }}
uses: actions/cache@v3
id: pnpm-store-cache
with:
path: ${{ steps.resolve-pnpm-store.outputs.PNPM_STORE }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-
- name: Resolve package versions
id: resolve-package-versions
shell: bash
run: >
echo "$(
node -e "
const fs = require('fs');
const lockfile = fs.readFileSync('./pnpm-lock.yaml', 'utf8');
const pattern = (name) => new RegExp(name + ':\\\s+specifier: [\\\s\\\w\\\.^]+version: (\\\d+\\\.\\\d+\\\.\\\d+)');
const playwrightVersion = lockfile.match(pattern('playwright'))[1];
console.log('PLAYWRIGHT_VERSION=' + playwrightVersion);
"
)" >> $GITHUB_OUTPUT
- name: Print versions
shell: bash
run: echo "${{ toJson(steps.resolve-package-versions.outputs) }}"

- name: Check resolved package versions
shell: bash
if: contains(fromJSON('[null, "", "undefined"]'), steps.resolve-package-versions.outputs.PLAYWRIGHT_VERSION)
run: echo "Failed to resolve package versions. See log above." && exit 1

- name: Cache Playwright v${{ steps.resolve-package-versions.outputs.PLAYWRIGHT_VERSION }}
uses: actions/cache@v3
id: playwright-cache
with:
path: ${{ env.PLAYWRIGHT_BROWSERS_PATH }}
key: ${{ runner.os }}-playwright-${{ steps.resolve-package-versions.outputs.PLAYWRIGHT_VERSION }}
restore-keys: |
${{ runner.os }}-playwright-
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: CI

env:
PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/.cache/ms-playwright

on:
push:
branches:
Expand All @@ -13,7 +16,7 @@ jobs:

steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
- uses: ./.github/actions/setup-and-cache

- name: Install
run: pnpm install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
- uses: ./.github/actions/setup-and-cache

- run: |
pnpm install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/new-meetup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- uses: pnpm/action-setup@v2
- uses: ./.github/actions/setup-and-cache

- name: Create new meetup
id: new_meetup
Expand Down

0 comments on commit 2a322e9

Please sign in to comment.