universo-platform-2d
184 строки · 6.7 Кб
1name: 'AFFiNE Node.js Setup'
2description: 'Node.js setup for CI, including cache configuration'
3inputs:
4extra-flags:
5description: 'Extra flags to pass to the yarn install.'
6required: false
7default: '--immutable --inline-builds'
8package-install:
9description: 'Run the install step.'
10required: false
11default: 'true'
12playwright-install:
13description: 'Run the install step for Playwright.'
14required: false
15default: 'false'
16electron-install:
17description: 'Download the Electron binary'
18required: false
19default: 'true'
20hard-link-nm:
21description: 'set nmMode to hardlinks-local in .yarnrc.yml'
22required: false
23default: 'true'
24nmHoistingLimits:
25description: 'Set nmHoistingLimits in .yarnrc.yml'
26required: false
27enableScripts:
28description: 'Set enableScripts in .yarnrc.yml'
29required: false
30default: 'true'
31full-cache:
32description: 'Full installation cache'
33required: false
34
35runs:
36using: 'composite'
37steps:
38- name: Setup Node.js
39uses: actions/setup-node@v4
40with:
41node-version-file: '.nvmrc'
42registry-url: https://npm.pkg.github.com
43scope: '@toeverything'
44
45- name: Set nmMode
46if: ${{ inputs.hard-link-nm == 'false' }}
47shell: bash
48run: yarn config set nmMode classic
49
50- name: Set nmHoistingLimits
51if: ${{ inputs.nmHoistingLimits }}
52shell: bash
53run: yarn config set nmHoistingLimits ${{ inputs.nmHoistingLimits }}
54
55- name: Set enableScripts
56if: ${{ inputs.enableScripts == 'false' }}
57shell: bash
58run: yarn config set enableScripts false
59
60- name: Set yarn global cache path
61shell: bash
62id: yarn-cache
63run: node -e "const p = $(yarn config cacheFolder --json).effective; console.log('yarn_global_cache=' + p)" >> $GITHUB_OUTPUT
64
65- name: Cache non-full yarn cache on Linux
66uses: actions/cache@v4
67if: ${{ inputs.full-cache != 'true' && runner.os == 'Linux' }}
68with:
69path: |
70node_modules
71${{ steps.yarn-cache.outputs.yarn_global_cache }}
72key: node_modules-cache-${{ github.job }}-${{ runner.os }}
73
74# The network performance on macOS is very poor
75# and the decompression performance on Windows is very terrible
76# so we reduce the number of cached files on non-Linux systems by remove node_modules from cache path.
77- name: Cache non-full yarn cache on non-Linux
78uses: actions/cache@v4
79if: ${{ inputs.full-cache != 'true' && runner.os != 'Linux' }}
80with:
81path: |
82${{ steps.yarn-cache.outputs.yarn_global_cache }}
83key: node_modules-cache-${{ github.job }}-${{ runner.os }}
84
85- name: Cache full yarn cache on Linux
86uses: actions/cache@v4
87if: ${{ inputs.full-cache == 'true' && runner.os == 'Linux' }}
88with:
89path: |
90node_modules
91${{ steps.yarn-cache.outputs.yarn_global_cache }}
92key: node_modules-cache-full-${{ runner.os }}
93
94- name: Cache full yarn cache on non-Linux
95uses: actions/cache@v4
96if: ${{ inputs.full-cache == 'true' && runner.os != 'Linux' }}
97with:
98path: |
99${{ steps.yarn-cache.outputs.yarn_global_cache }}
100key: node_modules-cache-full-${{ runner.os }}
101
102- name: yarn install
103if: ${{ inputs.package-install == 'true' }}
104continue-on-error: true
105shell: bash
106run: yarn ${{ inputs.extra-flags }}
107env:
108HUSKY: '0'
109PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1'
110ELECTRON_SKIP_BINARY_DOWNLOAD: '1'
111SENTRYCLI_SKIP_DOWNLOAD: '1'
112DEBUG: '*'
113
114- name: yarn install (try again)
115if: ${{ steps.install.outcome == 'failure' }}
116shell: bash
117run: yarn ${{ inputs.extra-flags }}
118env:
119HUSKY: '0'
120PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1'
121ELECTRON_SKIP_BINARY_DOWNLOAD: '1'
122SENTRYCLI_SKIP_DOWNLOAD: '1'
123DEBUG: '*'
124
125- name: Get installed Playwright version
126id: playwright-version
127if: ${{ inputs.playwright-install == 'true' }}
128shell: bash
129run: 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
130
131# Attempt to restore the correct Playwright browser binaries based on the
132# currently installed version of Playwright (The browser binary versions
133# may change with Playwright versions).
134# Note: Playwright's cache directory is hard coded because that's what it
135# says to do in the docs. There doesn't appear to be a command that prints
136# it out for us.
137- uses: actions/cache@v4
138id: playwright-cache
139if: ${{ inputs.playwright-install == 'true' }}
140with:
141path: ${{ github.workspace }}/node_modules/.cache/ms-playwright
142key: '${{ runner.os }}-playwright-${{ steps.playwright-version.outputs.version }}'
143# As a fallback, if the Playwright version has changed, try use the
144# most recently cached version. There's a good chance that at least one
145# of the browser binary versions haven't been updated, so Playwright can
146# skip installing that in the next step.
147# Note: When falling back to an old cache, `cache-hit` (used below)
148# will be `false`. This allows us to restore the potentially out of
149# date cache, but still let Playwright decide if it needs to download
150# new binaries or not.
151restore-keys: |
152${{ runner.os }}-playwright-
153
154# If the Playwright browser binaries weren't able to be restored, we tell
155# playwright to install everything for us.
156- name: Install Playwright's dependencies
157shell: bash
158if: inputs.playwright-install == 'true'
159run: yarn playwright install --with-deps chromium webkit
160env:
161PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/node_modules/.cache/ms-playwright
162
163- name: Get installed Electron version
164id: electron-version
165if: ${{ inputs.electron-install == 'true' }}
166shell: bash
167run: |
168echo "version=$(yarn why --json electron | grep -h 'workspace:.' | jq --raw-output '.children[].locator' | sed -e 's/@playwright\/test@.*://' | head -n 1)" >> $GITHUB_OUTPUT
169
170- uses: actions/cache@v4
171id: electron-cache
172if: ${{ inputs.electron-install == 'true' }}
173with:
174path: 'node_modules/.cache/electron'
175key: '${{ runner.os }}-electron-${{ steps.electron-version.outputs.version }}'
176restore-keys: |
177${{ runner.os }}-electron-
178
179- name: Install Electron binary
180shell: bash
181if: inputs.electron-install == 'true'
182run: node ./node_modules/electron/install.js
183env:
184electron_config_cache: ./node_modules/.cache/electron
185