-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
278 lines (258 loc) · 11 KB
/
setup-node-modules.yml
File metadata and controls
278 lines (258 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# Reusable workflow for setting up node_modules
# This workflow installs dependencies and runs the project setup, then uploads
# the prepared node_modules as an artifact for consumption by other workflows.
#
# Use cases:
# - EAS update: platform='', use-tarball=false, one ubuntu-latest runner.
# - Build: platform=ios|android, use-tarball=true, build_name set; runs on
# platform-specific runner (macOS for iOS, Ubuntu for Android) and uploads
# a tarball to preserve symlinks.
name: Setup Node Modules
on:
workflow_call:
inputs:
ref:
description: 'Git ref to checkout (e.g., refs/pull/123/head or branch name)'
required: false
type: string
default: ''
fetch-depth:
description: 'Number of commits to fetch (0 for all history)'
required: false
type: number
default: 1
checkout-submodules:
description: 'Checkout with submodules recursive (required for build)'
required: false
type: boolean
default: false
platform:
description: "Platform for native setup: '' (generic/ubuntu), 'ios', or 'android'. When set, runs on platform-specific runner and uses platform-specific setup."
required: false
type: string
default: ''
build_name:
description: 'Build config name (e.g. main-prod). When set, applies build config before setup so METAMASK_BUILD_TYPE is correct for InpageBridgeWeb3.js.'
required: false
type: string
default: ''
use-tarball:
description: 'Upload a tar.gz artifact (preserves symlinks). Use for build.yml so the build job can extract on the same OS.'
required: false
type: boolean
default: false
upload-artifact:
description: 'Whether to upload node_modules as an artifact'
required: false
type: boolean
default: true
artifact-name:
description: 'Name of the artifact to upload. When platform is set, used as-is; otherwise suffix with node version and OS.'
required: false
type: string
default: 'node-modules'
use-exact-artifact-name:
description: 'When true, use artifact-name exactly (no node/os suffix for generic platform).'
required: false
type: boolean
default: false
artifact-retention-days:
description: 'Number of days to retain the artifact'
required: false
type: number
default: 1
setup-command:
description: "Optional setup command override for generic platform (platform=''). If empty, defaults to 'yarn setup:github-ci'."
required: false
type: string
default: ''
include-yarn-install-state:
description: 'Include .yarn/install-state.gz in zip artifact payload.'
required: false
type: boolean
default: false
include-inpage-bridge-artifacts:
description: 'Include InpageBridgeWeb3.js and scripts/inpage-bridge/dist in zip artifact payload.'
required: false
type: boolean
default: true
runner_provider:
description: Runner provider forwarded from the caller
required: false
type: string
default: current
outputs:
artifact-name:
description: 'The actual artifact name used'
value: ${{ jobs.setup.outputs.artifact-name }}
permissions:
contents: read
id-token: write
jobs:
setup:
name: Setup Node Modules ${{ inputs.platform && format('({0})', inputs.platform) || '' }}
# Platform-specific runner to match consumer (build needs same OS for native deps/symlinks)
runs-on: ${{ inputs.runner_provider == 'namespace' && (inputs.platform == 'ios' && 'namespace-profile-metamask-ios-build' || (inputs.platform == 'android' && 'namespace-profile-metamask-android-build' || 'namespace-profile-metamask-ci-linux')) || (inputs.platform == 'ios' && 'ghcr.io/cirruslabs/macos-runner:tahoe-xl' || (inputs.platform == 'android' && 'ghcr.io/cirruslabs/ubuntu-runner-amd64:24.04-lg' || 'ubuntu-latest')) }}
permissions:
contents: read
id-token: write
outputs:
artifact-name: ${{ steps.set-artifact-name.outputs.artifact-name }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
fetch-depth: ${{ inputs.fetch-depth }}
submodules: ${{ inputs.checkout-submodules && 'recursive' || false }}
- name: Configure Namespace cache
if: ${{ inputs.runner_provider == 'namespace' }}
uses: namespacelabs/nscloud-cache-action@15799a6b54e5765f85b2aac25b3f0df43ed571c0 # v1
with:
path: |
~/.cache/yarn
.metamask
node_modules
.yarn/cache
# iOS: Only Node + Ruby needed (setup runs gem/bundle install, no pods/Xcode). Full iOS env is in build job.
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: ${{ inputs.runner_provider == 'namespace' && '' || (inputs.platform == 'android' && 'yarn' || (inputs.platform == 'ios' && 'yarn') || '') }}
- name: Setup Ruby (iOS)
if: inputs.platform == 'ios'
uses: ruby/setup-ruby@44511735964dcb71245e7e55f72539531f7bc0eb #v1
with:
ruby-version: '3.2.9'
working-directory: ios
bundler-cache: true
- name: Set artifact name
id: set-artifact-name
run: |
if [ -n "${{ inputs.platform }}" ] || [ "${{ inputs.use-exact-artifact-name }}" = "true" ]; then
echo "artifact-name=${{ inputs.artifact-name }}" >> "$GITHUB_OUTPUT"
echo "📦 Artifact name: ${{ inputs.artifact-name }}"
else
NODE_VERSION=$(node --version | sed 's/v//')
OS_NAME=$(echo "$RUNNER_OS" | tr '[:upper:]' '[:lower:]')
ARTIFACT_NAME="${{ inputs.artifact-name }}-node${NODE_VERSION}-${OS_NAME}"
echo "artifact-name=$ARTIFACT_NAME" >> "$GITHUB_OUTPUT"
echo "📦 Artifact name: $ARTIFACT_NAME"
fi
- name: Install dependencies
run: |
echo "📦 Installing dependencies..."
yarn install --immutable
- name: Apply build config (for setup)
if: inputs.build_name != ''
run: |
node scripts/apply-build-config.js ${{ inputs.build_name }} --export-github-env >> "$GITHUB_ENV"
- name: Restore .metamask folder
id: restore-metamask
if: ${{ inputs.runner_provider != 'namespace' && inputs.platform != '' }}
uses: actions/cache@v4
with:
path: .metamask
key: .metamask-${{ hashFiles('package.json', 'yarn.lock') }}
- name: Install Foundry if cache missed
if: ${{ inputs.platform != '' && (inputs.runner_provider == 'namespace' || steps.restore-metamask.outputs.cache-hit != 'true') }}
run: yarn install:foundryup
- name: Setup project
uses: nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 #v3.0.2
if: inputs.platform != ''
with:
timeout_minutes: 10
max_attempts: 3
retry_wait_seconds: 30
command: |
echo "🔧 Running setup for ${{ inputs.platform }}..."
if [ "${{ inputs.platform }}" = "ios" ]; then
yarn setup:github-ci --build-ios --no-build-android --no-install-pods
else
yarn setup:github-ci --no-build-ios
fi
- name: Setup project (generic)
if: inputs.platform == ''
run: |
echo "🔧 Running setup for GitHub CI..."
if [ -n "${{ inputs.setup-command }}" ]; then
echo "Using setup override: ${{ inputs.setup-command }}"
${{ inputs.setup-command }}
else
yarn setup:github-ci
fi
- name: Verify setup completed
run: |
echo "✅ Verifying setup artifacts..."
if [ ! -d "node_modules" ]; then
echo "❌ node_modules directory not found"
exit 1
fi
if [ ! -f "app/util/termsOfUse/termsOfUseContent.ts" ]; then
echo "❌ Terms of Use content not generated"
exit 1
fi
if [ ! -f "app/core/InpageBridgeWeb3.js" ]; then
echo "❌ InpageBridgeWeb3.js not generated"
exit 1
fi
echo "🔍 Checking yarn setup..."
echo " Node version: $(node --version)"
echo " Yarn version: $(yarn --version)"
echo " Corepack version: $(corepack --version)"
echo "✅ Setup verification passed"
- name: Debug - List .yarn contents
if: inputs.platform == ''
run: |
echo "📂 Contents of .yarn directory:"
ls -la .yarn/ || echo "No .yarn directory"
echo "📊 .yarn size: $(du -sh .yarn 2>/dev/null || echo 'N/A')"
echo "📄 install-state.gz exists: $(test -f .yarn/install-state.gz && echo 'yes' || echo 'no')"
echo "📁 cache dir exists: $(test -d .yarn/cache && echo 'yes' || echo 'no')"
- name: Create tarball (preserves symlinks)
if: inputs.upload-artifact && inputs.use-tarball
run: |
echo "📦 Creating tarball to preserve symlinks..."
tar -czf node-modules-${{ inputs.platform }}.tar.gz \
node_modules \
app/util/termsOfUse/termsOfUseContent.ts \
app/core/InpageBridgeWeb3.js \
scripts/inpage-bridge/dist
echo "✅ Tarball created: $(du -h node-modules-${{ inputs.platform }}.tar.gz)"
- name: Upload node_modules tarball
if: inputs.upload-artifact && inputs.use-tarball
uses: actions/upload-artifact@v4
with:
name: ${{ steps.set-artifact-name.outputs.artifact-name }}
path: node-modules-${{ inputs.platform }}.tar.gz
retention-days: ${{ inputs.artifact-retention-days }}
compression-level: 0
if-no-files-found: error
- name: Build zip artifact path list
id: build-zip-paths
if: inputs.upload-artifact && !inputs.use-tarball
shell: bash
run: |
paths=$'node_modules\napp/util/termsOfUse/termsOfUseContent.ts'
if [ "${{ inputs.include-yarn-install-state }}" = "true" ]; then
paths+=$'\n.yarn/install-state.gz'
fi
if [ "${{ inputs.include-inpage-bridge-artifacts }}" = "true" ]; then
paths+=$'\napp/core/InpageBridgeWeb3.js\nscripts/inpage-bridge/dist'
fi
{
echo "paths<<EOF"
printf "%s\n" "$paths"
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Upload node_modules artifact (zip)
if: inputs.upload-artifact && !inputs.use-tarball
uses: actions/upload-artifact@v4.5.0
with:
name: ${{ steps.set-artifact-name.outputs.artifact-name }}
path: ${{ steps.build-zip-paths.outputs.paths }}
retention-days: ${{ inputs.artifact-retention-days }}
compression-level: 1
if-no-files-found: warn
include-hidden-files: true