universo-platform-2d

Форк
0
184 строки · 6.7 Кб
1
name: 'AFFiNE Node.js Setup'
2
description: 'Node.js setup for CI, including cache configuration'
3
inputs:
4
  extra-flags:
5
    description: 'Extra flags to pass to the yarn install.'
6
    required: false
7
    default: '--immutable --inline-builds'
8
  package-install:
9
    description: 'Run the install step.'
10
    required: false
11
    default: 'true'
12
  playwright-install:
13
    description: 'Run the install step for Playwright.'
14
    required: false
15
    default: 'false'
16
  electron-install:
17
    description: 'Download the Electron binary'
18
    required: false
19
    default: 'true'
20
  hard-link-nm:
21
    description: 'set nmMode to hardlinks-local in .yarnrc.yml'
22
    required: false
23
    default: 'true'
24
  nmHoistingLimits:
25
    description: 'Set nmHoistingLimits in .yarnrc.yml'
26
    required: false
27
  enableScripts:
28
    description: 'Set enableScripts in .yarnrc.yml'
29
    required: false
30
    default: 'true'
31
  full-cache:
32
    description: 'Full installation cache'
33
    required: false
34

35
runs:
36
  using: 'composite'
37
  steps:
38
    - name: Setup Node.js
39
      uses: actions/setup-node@v4
40
      with:
41
        node-version-file: '.nvmrc'
42
        registry-url: https://npm.pkg.github.com
43
        scope: '@toeverything'
44

45
    - name: Set nmMode
46
      if: ${{ inputs.hard-link-nm == 'false' }}
47
      shell: bash
48
      run: yarn config set nmMode classic
49

50
    - name: Set nmHoistingLimits
51
      if: ${{ inputs.nmHoistingLimits }}
52
      shell: bash
53
      run: yarn config set nmHoistingLimits ${{ inputs.nmHoistingLimits }}
54

55
    - name: Set enableScripts
56
      if: ${{ inputs.enableScripts == 'false' }}
57
      shell: bash
58
      run: yarn config set enableScripts false
59

60
    - name: Set yarn global cache path
61
      shell: bash
62
      id: yarn-cache
63
      run: 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
66
      uses: actions/cache@v4
67
      if: ${{ inputs.full-cache != 'true' && runner.os == 'Linux' }}
68
      with:
69
        path: |
70
          node_modules
71
          ${{ steps.yarn-cache.outputs.yarn_global_cache }}
72
        key: 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
78
      uses: actions/cache@v4
79
      if: ${{ inputs.full-cache != 'true' && runner.os != 'Linux' }}
80
      with:
81
        path: |
82
          ${{ steps.yarn-cache.outputs.yarn_global_cache }}
83
        key: node_modules-cache-${{ github.job }}-${{ runner.os }}
84

85
    - name: Cache full yarn cache on Linux
86
      uses: actions/cache@v4
87
      if: ${{ inputs.full-cache == 'true' && runner.os == 'Linux' }}
88
      with:
89
        path: |
90
          node_modules
91
          ${{ steps.yarn-cache.outputs.yarn_global_cache }}
92
        key: node_modules-cache-full-${{ runner.os }}
93

94
    - name: Cache full yarn cache on non-Linux
95
      uses: actions/cache@v4
96
      if: ${{ inputs.full-cache == 'true' && runner.os != 'Linux' }}
97
      with:
98
        path: |
99
          ${{ steps.yarn-cache.outputs.yarn_global_cache }}
100
        key: node_modules-cache-full-${{ runner.os }}
101

102
    - name: yarn install
103
      if: ${{ inputs.package-install == 'true' }}
104
      continue-on-error: true
105
      shell: bash
106
      run: yarn ${{ inputs.extra-flags }}
107
      env:
108
        HUSKY: '0'
109
        PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1'
110
        ELECTRON_SKIP_BINARY_DOWNLOAD: '1'
111
        SENTRYCLI_SKIP_DOWNLOAD: '1'
112
        DEBUG: '*'
113

114
    - name: yarn install (try again)
115
      if: ${{ steps.install.outcome == 'failure' }}
116
      shell: bash
117
      run: yarn ${{ inputs.extra-flags }}
118
      env:
119
        HUSKY: '0'
120
        PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1'
121
        ELECTRON_SKIP_BINARY_DOWNLOAD: '1'
122
        SENTRYCLI_SKIP_DOWNLOAD: '1'
123
        DEBUG: '*'
124

125
    - name: Get installed Playwright version
126
      id: playwright-version
127
      if: ${{ inputs.playwright-install == 'true' }}
128
      shell: bash
129
      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
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
138
      id: playwright-cache
139
      if: ${{ inputs.playwright-install == 'true' }}
140
      with:
141
        path: ${{ github.workspace }}/node_modules/.cache/ms-playwright
142
        key: '${{ 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.
151
        restore-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
157
      shell: bash
158
      if: inputs.playwright-install == 'true'
159
      run: yarn playwright install --with-deps chromium webkit
160
      env:
161
        PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/node_modules/.cache/ms-playwright
162

163
    - name: Get installed Electron version
164
      id: electron-version
165
      if: ${{ inputs.electron-install == 'true' }}
166
      shell: bash
167
      run: |
168
        echo "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
171
      id: electron-cache
172
      if: ${{ inputs.electron-install == 'true' }}
173
      with:
174
        path: 'node_modules/.cache/electron'
175
        key: '${{ runner.os }}-electron-${{ steps.electron-version.outputs.version }}'
176
        restore-keys: |
177
          ${{ runner.os }}-electron-
178

179
    - name: Install Electron binary
180
      shell: bash
181
      if: inputs.electron-install == 'true'
182
      run: node ./node_modules/electron/install.js
183
      env:
184
        electron_config_cache: ./node_modules/.cache/electron
185

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.