AFFiNE/.github/actions/setup-node/action.yml

124 lines
4.6 KiB
YAML
Raw Normal View History

2023-03-24 18:44:14 +03:00
name: 'AFFiNE Node.js Setup'
description: 'Node.js setup for CI, including cache configuration'
inputs:
extra-flags:
description: 'Extra flags to pass to the yarn install.'
required: false
2023-03-28 03:27:00 +03:00
default: '--immutable --inline-builds'
2023-03-24 18:44:14 +03:00
package-install:
description: 'Run the install step.'
required: false
default: 'true'
playwright-install:
description: 'Run the install step for Playwright.'
required: false
default: 'false'
2023-07-03 14:09:17 +03:00
electron-install:
description: 'Download the Electron binary'
required: false
default: 'true'
2023-03-24 18:58:28 +03:00
npm-token:
description: 'The NPM token to use for private packages.'
required: false
default: ''
2023-07-03 14:09:17 +03:00
hard-link-nm:
description: 'set nmMode to hardlinks-local in .yarnrc.yml'
required: false
default: 'true'
2023-03-24 18:44:14 +03:00
runs:
using: 'composite'
steps:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
registry-url: https://npm.pkg.github.com
scope: '@toeverything'
cache: 'yarn'
2023-07-03 14:09:17 +03:00
- name: Set nmMode
if: ${{ inputs.hard-link-nm == 'true' }}
2023-03-28 02:09:42 +03:00
shell: bash
2023-07-03 14:09:17 +03:00
run: yarn config set nmMode hardlinks-local
2023-03-28 02:09:42 +03:00
2023-03-24 18:44:14 +03:00
- name: yarn install
if: ${{ inputs.package-install == 'true' }}
continue-on-error: true
shell: bash
run: yarn install ${{ inputs.extra-flags }}
env:
2023-03-24 18:58:28 +03:00
NODE_AUTH_TOKEN: ${{ inputs.npm-token }}
2023-03-28 03:27:00 +03:00
HUSKY: '0'
2023-07-03 14:09:17 +03:00
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1'
ELECTRON_SKIP_BINARY_DOWNLOAD: '1'
2023-03-24 18:44:14 +03:00
- name: yarn install (try again)
if: ${{ steps.install.outcome == 'failure' }}
shell: bash
run: yarn install ${{ inputs.extra-flags }}
env:
2023-03-24 18:58:28 +03:00
NODE_AUTH_TOKEN: ${{ inputs.npm-token }}
2023-03-28 03:27:00 +03:00
HUSKY: '0'
2023-07-03 14:09:17 +03:00
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1'
ELECTRON_SKIP_BINARY_DOWNLOAD: '1'
2023-03-24 18:44:14 +03:00
- name: Get installed Playwright version
id: playwright-version
if: ${{ inputs.playwright-install == 'true' }}
2023-03-24 18:44:14 +03:00
shell: bash
run: echo "version=$(yarn why --json @playwright/test | grep -h 'workspace:.' | jq --raw-output '.children[].locator' | sed -e 's/@playwright\/test@.*://' | head -n 1)" >> $GITHUB_OUTPUT
2023-03-24 18:44:14 +03:00
# Attempt to restore the correct Playwright browser binaries based on the
# currently installed version of Playwright (The browser binary versions
# may change with Playwright versions).
# Note: Playwright's cache directory is hard coded because that's what it
# says to do in the docs. There doesn't appear to be a command that prints
# it out for us.
- uses: actions/cache@v3
id: playwright-cache
if: ${{ inputs.playwright-install == 'true' }}
2023-03-24 18:44:14 +03:00
with:
path: '~/.cache/ms-playwright'
key: '${{ runner.os }}-playwright-${{ steps.playwright-version.outputs.version }}'
# As a fallback, if the Playwright version has changed, try use the
# most recently cached version. There's a good chance that at least one
# of the browser binary versions haven't been updated, so Playwright can
# skip installing that in the next step.
# Note: When falling back to an old cache, `cache-hit` (used below)
# will be `false`. This allows us to restore the potentially out of
# date cache, but still let Playwright decide if it needs to download
# new binaries or not.
restore-keys: |
${{ runner.os }}-playwright-
# If the Playwright browser binaries weren't able to be restored, we tell
# paywright to install everything for us.
- name: Install Playwright's dependencies
shell: bash
if: inputs.playwright-install == 'true' && steps.playwright-cache.outputs.cache-hit != 'true'
2023-03-24 18:44:14 +03:00
run: yarn playwright install --with-deps
2023-07-03 14:09:17 +03:00
- name: Get installed Electron version
id: electron-version
if: ${{ inputs.electron-install == 'true' }}
shell: bash
run: |
echo "version=$(yarn why --json electron | grep -h 'workspace:.' | jq --raw-output '.children[].locator' | sed -e 's/@playwright\/test@.*://' | head -n 1)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
id: electron-cache
if: ${{ inputs.electron-install == 'true' }}
with:
path: 'node_modules/.cache/electron'
key: '${{ runner.os }}-electron-${{ steps.electron-version.outputs.version }}'
restore-keys: |
${{ runner.os }}-electron-
- name: Install Electron binary
shell: bash
if: inputs.electron-install == 'true'
run: node apps/electron/node_modules/electron/install.js
env:
ELECTRON_OVERRIDE_DIST_PATH: ./node_modules/.cache/electron