[ci] Unfork runtime_commit_artifacts
Promotes v2 to the primary workflow file so that we don't double write to the protected branches. Note: this may break DiffTrain temporarily, I will fix forward if so ghstack-source-id: f6505a72f2edcf73aadf827d3a41e34d2a3227ba Pull Request resolved: https://github.com/facebook/react/pull/30477
Lauren Tan committed
Jul 26, 2024 at 11:24 UTC
2883d28b2d6b62f8a887364662dac35848053476
2 files changed
+36
-501
.github/workflows/runtime_commit_artifacts.yml
+36
-108
@@ -1,8 +1,11 @@
1
-name: (Runtime) Commit Artifacts for Meta WWW and fbsource
1
+name: (Runtime) Commit Artifacts for Meta WWW and fbsource V2
2
3
on:
4
- push:
5
- branches: [main, meta-www, meta-fbsource]
4
+ workflow_run:
5
+ workflows: ["(Runtime) Build and Test"]
6
+ types: [completed]
7
+ branches:
8
+ - main
9
10
env:
11
TZ: /usr/share/zoneinfo/America/Los_Angeles
@@ -49,102 +52,27 @@ jobs:
52
run: |
53
echo "www_branch_count=$(git ls-remote --heads origin "refs/heads/meta-www" | wc -l)" >> "$GITHUB_OUTPUT"
54
echo "fbsource_branch_count=$(git ls-remote --heads origin "refs/heads/meta-fbsource" | wc -l)" >> "$GITHUB_OUTPUT"
52
- - name: Download and unzip artifacts
53
- uses: actions/github-script@v6
54
- env:
55
- CIRCLECI_TOKEN: ${{secrets.CIRCLECI_TOKEN_DIFFTRAIN}}
55
+ - uses: actions/setup-node@v4
56
with:
57
- script: |
58
- // TODO: Move this to a script file.
59
- const cp = require('child_process');
60
-
61
- function sleep(ms) {
62
- return new Promise(resolve => setTimeout(resolve, ms));
63
- }
64
-
65
- function execHelper(command, options, streamStdout = false) {
66
- return new Promise((resolve, reject) => {
67
- const proc = cp.exec(
68
- command,
69
- options,
70
- (error, stdout) => (error ? reject(error) : resolve(stdout.trim())),
71
- );
72
- if (streamStdout) {
73
- proc.stdout.pipe(process.stdout);
74
- }
75
- });
76
- }
77
-
78
- let artifactsUrl = null;
79
- // This is a temporary, dirty hack to avoid needing a GitHub auth token in the circleci
80
- // workflow to notify this GitHub action. Sorry!
81
- let iter = 0;
82
- spinloop: while (iter < 15) {
83
- const res = await github.rest.repos.listCommitStatusesForRef({
84
- owner: context.repo.owner,
85
- repo: context.repo.repo,
86
- ref: context.sha
87
- });
88
- for (const status of res.data) {
89
- if (/process_artifacts_combined/.test(status.context)) {
90
- switch (status.state) {
91
- case 'pending': {
92
- console.log(`${status.context} is still pending`);
93
- break;
94
- }
95
- case 'failure':
96
- case 'error': {
97
- throw new Error(`${status.context} has failed or errored`);
98
- }
99
- case 'success': {
100
- // The status does not include a build ID, but we can extract it
101
- // from the URL. I couldn't find a better way to do this.
102
- const ciBuildId = /\/facebook\/react\/([0-9]+)/.exec(
103
- status.target_url,
104
- )[1];
105
- if (Number.parseInt(ciBuildId, 10) + '' === ciBuildId) {
106
- artifactsUrl =
107
- `https://circleci.com/api/v1.1/project/github/facebook/react/${ciBuildId}/artifacts`;
108
- console.log(`Found artifactsUrl: ${artifactsUrl}`);
109
- break spinloop;
110
- } else {
111
- throw new Error(`${ciBuildId} isn't a number`);
112
- }
113
- break;
114
- }
115
- default: {
116
- throw new Error(`Unhandled status state: ${status.state}`);
117
- break;
118
- }
119
- }
120
- }
121
- }
122
- iter++;
123
- console.log("Sleeping for 60s...");
124
- await sleep(60_000);
125
- }
126
- if (artifactsUrl != null) {
127
- const {CIRCLECI_TOKEN} = process.env;
128
- const res = await fetch(artifactsUrl, {
129
- headers: {
130
- 'Circle-Token': CIRCLECI_TOKEN
131
- }
132
- });
133
- const data = await res.json();
134
- if (!Array.isArray(data) && data.message != null) {
135
- throw `CircleCI returned: ${data.message}`;
136
- }
137
- for (const artifact of data) {
138
- if (artifact.path === 'build.tgz') {
139
- console.log(`Downloading and unzipping ${artifact.url}`);
140
- await execHelper(
141
- `curl -L ${artifact.url} -H "Circle-Token: ${CIRCLECI_TOKEN}" | tar -xvz`
142
- );
143
- }
144
- }
145
- } else {
146
- process.exitCode = 1;
147
- }
57
+ node-version: 18.20.1
58
+ cache: yarn
59
+ cache-dependency-path: yarn.lock
60
+ - name: Restore cached node_modules
61
+ uses: actions/cache@v4
62
+ id: node_modules
63
+ with:
64
+ path: "**/node_modules"
65
+ key: ${{ runner.arch }}-${{ runner.os }}-modules-${{ hashFiles('yarn.lock', 'scripts/release/yarn.lock') }}
66
+ - run: yarn install --frozen-lockfile
67
+ name: yarn install (react)
68
+ - run: yarn install --frozen-lockfile
69
+ name: yarn install (scripts/release)
70
+ working-directory: scripts/release
71
+ - name: Download artifacts for base revision
72
+ run: |
73
+ GH_TOKEN=${{ github.token }} scripts/release/download-experimental-build-ghaction.js --commit=${{ github.event.workflow_run.head_sha }}
74
+ - name: Display structure of build
75
+ run: ls -R build
76
- name: Strip @license from eslint plugin and react-refresh
77
run: |
78
sed -i -e 's/ @license React*//' \
@@ -199,9 +127,9 @@ jobs:
127
ls -R ./compiled-rn
128
- name: Add REVISION files
129
run: |
202
- echo ${{ github.sha }} >> ./compiled/facebook-www/REVISION
130
+ echo ${{ github.event.workflow_run.head_sha }} >> ./compiled/facebook-www/REVISION
131
cp ./compiled/facebook-www/REVISION ./compiled/facebook-www/REVISION_TRANSFORMS
204
- echo ${{ github.sha }} >> ./compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/REVISION
132
+ echo ${{ github.event.workflow_run.head_sha}} >> ./compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/REVISION
133
- name: "Get current version string"
134
id: get_current_version
135
run: |
@@ -298,12 +226,12 @@ jobs:
226
uses: stefanzweifel/git-auto-commit-action@v4
227
with:
228
commit_message: |
301
- ${{ github.event.head_commit.message }}
229
+ ${{ github.event.workflow_run.head_commit.message }}
230
303
- DiffTrain build for [${{ github.sha }}](https://github.com/facebook/react/commit/${{ github.sha }})
231
+ DiffTrain build for [${{ github.event.workflow_run.head_sha }}](https://github.com/facebook/react/commit/${{ github.event.workflow_run.head_sha }})
232
branch: builds/facebook-www
305
- commit_user_name: ${{ github.actor }}
306
- commit_user_email: ${{ github.actor }}@users.noreply.github.com
233
+ commit_user_name: ${{ github.event.workflow_run.actor.name }}
234
+ commit_user_email: ${{ github.event.workflow_run.actor.email || format('{0}@users.noreply.github.com', github.event.workflow_run.actor.name) }}
235
create_branch: true
236
237
commit_fbsource_artifacts:
@@ -456,10 +384,10 @@ jobs:
384
uses: stefanzweifel/git-auto-commit-action@v4
385
with:
386
commit_message: |
459
- ${{ github.event.head_commit.message }}
387
+ ${{ github.event.workflow_run.head_commit.message }}
388
461
- DiffTrain build for commit https://github.com/facebook/react/commit/${{ github.sha }}.
389
+ DiffTrain build for commit https://github.com/facebook/react/commit/${{ github.event.workflow_run.head_sha }}.
390
branch: builds/facebook-fbsource
463
- commit_user_name: ${{ github.actor }}
464
- commit_user_email: ${{ github.actor }}@users.noreply.github.com
391
+ commit_user_name: ${{ github.event.workflow_run.actor.name }}
392
+ commit_user_email: ${{ github.event.workflow_run.actor.email || format('{0}@users.noreply.github.com', github.event.workflow_run.actor.name) }}
393
create_branch: true
.github/workflows/runtime_commit_artifacts_v2.yml
deleted
-393
@@ -1,393 +0,0 @@
1
-name: (Runtime) Commit Artifacts for Meta WWW and fbsource V2
2
-
3
-on:
4
- workflow_run:
5
- workflows: ["(Runtime) Build and Test"]
6
- types: [completed]
7
- branches:
8
- - main
9
-
10
-env:
11
- TZ: /usr/share/zoneinfo/America/Los_Angeles
12
-
13
-jobs:
14
- download_artifacts:
15
- runs-on: ubuntu-latest
16
- outputs:
17
- www_branch_count: ${{ steps.check_branches.outputs.www_branch_count }}
18
- fbsource_branch_count: ${{ steps.check_branches.outputs.fbsource_branch_count }}
19
- last_version_classic: ${{ steps.get_last_version_www.outputs.last_version_classic }}
20
- last_version_modern: ${{ steps.get_last_version_www.outputs.last_version_modern }}
21
- last_version_rn: ${{ steps.get_last_version_rn.outputs.last_version_rn }}
22
- current_version_classic: ${{ steps.get_current_version.outputs.current_version_classic }}
23
- current_version_modern: ${{ steps.get_current_version.outputs.current_version_modern }}
24
- current_version_rn: ${{ steps.get_current_version.outputs.current_version_rn }}
25
- steps:
26
- - uses: actions/checkout@v4
27
- with:
28
- ref: builds/facebook-www
29
- - name: "Get last version string for www"
30
- id: get_last_version_www
31
- run: |
32
- # Empty checks only needed for backwards compatibility,can remove later.
33
- VERSION_CLASSIC=$( [ -f ./compiled/facebook-www/VERSION_CLASSIC ] && cat ./compiled/facebook-www/VERSION_CLASSIC || echo '' )
34
- VERSION_MODERN=$( [ -f ./compiled/facebook-www/VERSION_MODERN ] && cat ./compiled/facebook-www/VERSION_MODERN || echo '' )
35
- echo "Last classic version is $VERSION_CLASSIC"
36
- echo "Last modern version is $VERSION_MODERN"
37
- echo "last_version_classic=$VERSION_CLASSIC" >> "$GITHUB_OUTPUT"
38
- echo "last_version_modern=$VERSION_MODERN" >> "$GITHUB_OUTPUT"
39
- - uses: actions/checkout@v4
40
- with:
41
- ref: builds/facebook-fbsource
42
- - name: "Get last version string for rn"
43
- id: get_last_version_rn
44
- run: |
45
- # Empty checks only needed for backwards compatibility,can remove later.
46
- VERSION_NATIVE_FB=$( [ -f ./compiled-rn/VERSION_NATIVE_FB ] && cat ./compiled-rn/VERSION_NATIVE_FB || echo '' )
47
- echo "Last rn version is $VERSION_NATIVE_FB"
48
- echo "last_version_rn=$VERSION_NATIVE_FB" >> "$GITHUB_OUTPUT"
49
- - uses: actions/checkout@v4
50
- - name: "Check branches"
51
- id: check_branches
52
- run: |
53
- echo "www_branch_count=$(git ls-remote --heads origin "refs/heads/meta-www" | wc -l)" >> "$GITHUB_OUTPUT"
54
- echo "fbsource_branch_count=$(git ls-remote --heads origin "refs/heads/meta-fbsource" | wc -l)" >> "$GITHUB_OUTPUT"
55
- - uses: actions/setup-node@v4
56
- with:
57
- node-version: 18.20.1
58
- cache: yarn
59
- cache-dependency-path: yarn.lock
60
- - name: Restore cached node_modules
61
- uses: actions/cache@v4
62
- id: node_modules
63
- with:
64
- path: "**/node_modules"
65
- key: ${{ runner.arch }}-${{ runner.os }}-modules-${{ hashFiles('yarn.lock', 'scripts/release/yarn.lock') }}
66
- - run: yarn install --frozen-lockfile
67
- name: yarn install (react)
68
- - run: yarn install --frozen-lockfile
69
- name: yarn install (scripts/release)
70
- working-directory: scripts/release
71
- - name: Download artifacts for base revision
72
- run: |
73
- GH_TOKEN=${{ github.token }} scripts/release/download-experimental-build-ghaction.js --commit=${{ github.event.workflow_run.head_sha }}
74
- - name: Display structure of build
75
- run: ls -R build
76
- - name: Strip @license from eslint plugin and react-refresh
77
- run: |
78
- sed -i -e 's/ @license React*//' \
79
- build/oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js \
80
- build/oss-experimental/react-refresh/cjs/react-refresh-babel.development.js
81
- - name: Move relevant files for React in www into compiled
82
- run: |
83
- # Move the facebook-www folder into compiled
84
- mkdir ./compiled
85
- mv build/facebook-www ./compiled
86
-
87
- # Move ReactAllWarnings.js to facebook-www
88
- mkdir ./compiled/facebook-www/__test_utils__
89
- mv build/__test_utils__/ReactAllWarnings.js ./compiled/facebook-www/__test_utils__/ReactAllWarnings.js
90
-
91
- # Move eslint-plugin-react-hooks into facebook-www
92
- mv build/oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js \
93
- ./compiled/facebook-www/eslint-plugin-react-hooks.js
94
-
95
- # Move unstable_server-external-runtime.js into facebook-www
96
- mv build/oss-experimental/react-dom/unstable_server-external-runtime.js \
97
- ./compiled/facebook-www/unstable_server-external-runtime.js
98
-
99
- # Move react-refresh-babel.development.js into babel-plugin-react-refresh
100
- mkdir ./compiled/babel-plugin-react-refresh
101
- mv build/oss-experimental/react-refresh/cjs/react-refresh-babel.development.js \
102
- ./compiled/babel-plugin-react-refresh/index.js
103
-
104
- ls -R ./compiled
105
- - name: Move relevant files for React in fbsource into compiled-rn
106
- run: |
107
- BASE_FOLDER='compiled-rn/facebook-fbsource/xplat/js'
108
- mkdir -p ${BASE_FOLDER}/react-native-github/Libraries/Renderer/
109
- mkdir -p ${BASE_FOLDER}/RKJSModules/vendor/react/{scheduler,react,react-is,react-test-renderer}/
110
-
111
- # Move React Native renderer
112
- mv build/react-native/implementations/ $BASE_FOLDER/react-native-github/Libraries/Renderer/
113
- mv build/react-native/shims/ $BASE_FOLDER/react-native-github/Libraries/Renderer/
114
- mv build/facebook-react-native/scheduler/cjs/ $BASE_FOLDER/RKJSModules/vendor/react/scheduler/
115
- mv build/facebook-react-native/react/cjs/ $BASE_FOLDER/RKJSModules/vendor/react/react/
116
- mv build/facebook-react-native/react-is/cjs/ $BASE_FOLDER/RKJSModules/vendor/react/react-is/
117
- mv build/facebook-react-native/react-test-renderer/cjs/ $BASE_FOLDER/RKJSModules/vendor/react/react-test-renderer/
118
-
119
- # Delete OSS renderer. OSS renderer is synced through internal script.
120
- RENDERER_FOLDER=$BASE_FOLDER/react-native-github/Libraries/Renderer/implementations/
121
- rm $RENDERER_FOLDER/ReactFabric-{dev,prod,profiling}.js
122
- rm $RENDERER_FOLDER/ReactNativeRenderer-{dev,prod,profiling}.js
123
-
124
- # Move React Native version file
125
- mv build/facebook-react-native/VERSION_NATIVE_FB ./compiled-rn/VERSION_NATIVE_FB
126
-
127
- ls -R ./compiled-rn
128
- - name: Add REVISION files
129
- run: |
130
- echo ${{ github.event.workflow_run.head_sha }} >> ./compiled/facebook-www/REVISION
131
- cp ./compiled/facebook-www/REVISION ./compiled/facebook-www/REVISION_TRANSFORMS
132
- echo ${{ github.event.workflow_run.head_sha}} >> ./compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/REVISION
133
- - name: "Get current version string"
134
- id: get_current_version
135
- run: |
136
- VERSION_CLASSIC=$(cat ./compiled/facebook-www/VERSION_CLASSIC)
137
- VERSION_MODERN=$(cat ./compiled/facebook-www/VERSION_MODERN)
138
- VERSION_NATIVE_FB=$(cat ./compiled-rn/VERSION_NATIVE_FB)
139
- echo "Current classic version is $VERSION_CLASSIC"
140
- echo "Current modern version is $VERSION_MODERN"
141
- echo "Current rn version is $VERSION_NATIVE_FB"
142
- echo "current_version_classic=$VERSION_CLASSIC" >> "$GITHUB_OUTPUT"
143
- echo "current_version_modern=$VERSION_MODERN" >> "$GITHUB_OUTPUT"
144
- echo "current_version_rn=$VERSION_NATIVE_FB" >> "$GITHUB_OUTPUT"
145
- - uses: actions/upload-artifact@v3
146
- with:
147
- name: compiled
148
- path: compiled/
149
- - uses: actions/upload-artifact@v3
150
- with:
151
- name: compiled-rn
152
- path: compiled-rn/
153
-
154
- commit_www_artifacts:
155
- needs: download_artifacts
156
- if: ${{ (github.ref == 'refs/heads/main' && needs.download_artifacts.outputs.www_branch_count == '0') || github.ref == 'refs/heads/meta-www' }}
157
- runs-on: ubuntu-latest
158
- steps:
159
- - uses: actions/checkout@v4
160
- with:
161
- ref: builds/facebook-www
162
- - name: Ensure clean directory
163
- run: rm -rf compiled
164
- - uses: actions/download-artifact@v3
165
- with:
166
- name: compiled
167
- path: compiled/
168
- - name: Revert version changes
169
- if: needs.download_artifacts.outputs.last_version_classic != '' && needs.download_artifacts.outputs.last_version_modern != ''
170
- env:
171
- CURRENT_VERSION_CLASSIC: ${{ needs.download_artifacts.outputs.current_version_classic }}
172
- CURRENT_VERSION_MODERN: ${{ needs.download_artifacts.outputs.current_version_modern }}
173
- LAST_VERSION_CLASSIC: ${{ needs.download_artifacts.outputs.last_version_classic }}
174
- LAST_VERSION_MODERN: ${{ needs.download_artifacts.outputs.last_version_modern }}
175
- run: |
176
- echo "Reverting $CURRENT_VERSION_CLASSIC to $LAST_VERSION_CLASSIC"
177
- grep -rl "$CURRENT_VERSION_CLASSIC" ./compiled || echo "No files found with $CURRENT_VERSION_CLASSIC"
178
- grep -rl "$CURRENT_VERSION_CLASSIC" ./compiled | xargs -r sed -i -e "s/$CURRENT_VERSION_CLASSIC/$LAST_VERSION_CLASSIC/g"
179
- grep -rl "$CURRENT_VERSION_CLASSIC" ./compiled || echo "Classic version reverted"
180
- echo "===================="
181
- echo "Reverting $CURRENT_VERSION_MODERN to $LAST_VERSION_MODERN"
182
- grep -rl "$CURRENT_VERSION_MODERN" ./compiled || echo "No files found with $CURRENT_VERSION_MODERN"
183
- grep -rl "$CURRENT_VERSION_MODERN" ./compiled | xargs -r sed -i -e "s/$CURRENT_VERSION_MODERN/$LAST_VERSION_MODERN/g"
184
- grep -rl "$CURRENT_VERSION_MODERN" ./compiled || echo "Modern version reverted"
185
- - name: Check for changes
186
- id: check_should_commit
187
- run: |
188
- echo "Full git status"
189
- git add .
190
- git status
191
- echo "===================="
192
- if git status --porcelain | grep -qv '/REVISION'; then
193
- echo "Changes detected"
194
- echo "===== Changes ====="
195
- git --no-pager diff -U0 | grep '^[+-]' | head -n 50
196
- echo "==================="
197
- echo "should_commit=true" >> "$GITHUB_OUTPUT"
198
- else
199
- echo "No Changes detected"
200
- echo "should_commit=false" >> "$GITHUB_OUTPUT"
201
- fi
202
- - name: Re-apply version changes
203
- if: steps.check_should_commit.outputs.should_commit == 'true' && needs.download_artifacts.outputs.last_version_classic != '' && needs.download_artifacts.outputs.last_version_modern != ''
204
- env:
205
- CURRENT_VERSION_CLASSIC: ${{ needs.download_artifacts.outputs.current_version_classic }}
206
- CURRENT_VERSION_MODERN: ${{ needs.download_artifacts.outputs.current_version_modern }}
207
- LAST_VERSION_CLASSIC: ${{ needs.download_artifacts.outputs.last_version_classic }}
208
- LAST_VERSION_MODERN: ${{ needs.download_artifacts.outputs.last_version_modern }}
209
- run: |
210
- echo "Re-applying $LAST_VERSION_CLASSIC to $CURRENT_VERSION_CLASSIC"
211
- grep -rl "$LAST_VERSION_CLASSIC" ./compiled || echo "No files found with $LAST_VERSION_CLASSIC"
212
- grep -rl "$LAST_VERSION_CLASSIC" ./compiled | xargs -r sed -i -e "s/$LAST_VERSION_CLASSIC/$CURRENT_VERSION_CLASSIC/g"
213
- grep -rl "$LAST_VERSION_CLASSIC" ./compiled || echo "Classic version re-applied"
214
- echo "===================="
215
- echo "Re-applying $LAST_VERSION_MODERN to $CURRENT_VERSION_MODERN"
216
- grep -rl "$LAST_VERSION_MODERN" ./compiled || echo "No files found with $LAST_VERSION_MODERN"
217
- grep -rl "$LAST_VERSION_MODERN" ./compiled | xargs -r sed -i -e "s/$LAST_VERSION_MODERN/$CURRENT_VERSION_MODERN/g"
218
- grep -rl "$LAST_VERSION_MODERN" ./compiled || echo "Classic version re-applied"
219
- - name: Will commit these changes
220
- if: steps.check_should_commit.outputs.should_commit == 'true'
221
- run: |
222
- echo ":"
223
- git status -u
224
- - name: Commit changes to branch
225
- if: steps.check_should_commit.outputs.should_commit == 'true'
226
- uses: stefanzweifel/git-auto-commit-action@v4
227
- with:
228
- commit_message: |
229
- ${{ github.event.workflow_run.head_commit.message }}
230
-
231
- DiffTrain build for [${{ github.event.workflow_run.head_sha }}](https://github.com/facebook/react/commit/${{ github.event.workflow_run.head_sha }})
232
- branch: builds/facebook-www
233
- commit_user_name: ${{ github.event.workflow_run.actor.name }}
234
- commit_user_email: ${{ github.event.workflow_run.actor.email || format('{0}@users.noreply.github.com', github.event.workflow_run.actor.name) }}
235
- create_branch: true
236
-
237
- commit_fbsource_artifacts:
238
- needs: download_artifacts
239
- if: ${{ (github.ref == 'refs/heads/main' && needs.download_artifacts.outputs.fbsource_branch_count == '0') || github.ref == 'refs/heads/meta-fbsource' }}
240
- runs-on: ubuntu-latest
241
- steps:
242
- - uses: actions/checkout@v4
243
- with:
244
- ref: builds/facebook-fbsource
245
- - name: Ensure clean directory
246
- run: rm -rf compiled-rn
247
- - uses: actions/download-artifact@v3
248
- with:
249
- name: compiled-rn
250
- path: compiled-rn/
251
- - name: Revert version changes
252
- if: needs.download_artifacts.outputs.last_version_rn != ''
253
- env:
254
- CURRENT_VERSION: ${{ needs.download_artifacts.outputs.current_version_rn }}
255
- LAST_VERSION: ${{ needs.download_artifacts.outputs.last_version_rn }}
256
- run: |
257
- echo "Reverting $CURRENT_VERSION to $LAST_VERSION"
258
- grep -rl "$CURRENT_VERSION" ./compiled-rn || echo "No files found with $CURRENT_VERSION"
259
- grep -rl "$CURRENT_VERSION" ./compiled-rn | xargs -r sed -i -e "s/$CURRENT_VERSION/$LAST_VERSION/g"
260
- grep -rl "$CURRENT_VERSION" ./compiled-rn || echo "Version reverted"
261
- - name: Check for changes
262
- id: check_should_commit
263
- run: |
264
- echo "Full git status"
265
- git add .
266
- git --no-pager diff -U0 --cached | grep '^[+-]' | head -n 100
267
- echo "===================="
268
- # Ignore REVISION or lines removing @generated headers.
269
- if git diff --cached ':(exclude)*REVISION' | grep -vE "^(@@|diff|index|\-\-\-|\+\+\+|\- \* @generated SignedSource)" | grep "^[+-]" > /dev/null; then
270
- echo "Changes detected"
271
- echo "===== Changes ====="
272
- git --no-pager diff --cached ':(exclude)*REVISION' | grep -vE "^(@@|diff|index|\-\-\-|\+\+\+|\- \* @generated SignedSource)" | grep "^[+-]" | head -n 50
273
- echo "==================="
274
- echo "should_commit=true" >> "$GITHUB_OUTPUT"
275
- else
276
- echo "No Changes detected"
277
- echo "should_commit=false" >> "$GITHUB_OUTPUT"
278
- fi
279
- - name: Re-apply version changes
280
- if: steps.check_should_commit.outputs.should_commit == 'true' && needs.download_artifacts.outputs.last_version_rn != ''
281
- env:
282
- CURRENT_VERSION: ${{ needs.download_artifacts.outputs.current_version_rn }}
283
- LAST_VERSION: ${{ needs.download_artifacts.outputs.last_version_rn }}
284
- run: |
285
- echo "Re-applying $LAST_VERSION to $CURRENT_VERSION"
286
- grep -rl "$LAST_VERSION" ./compiled-rn || echo "No files found with $LAST_VERSION"
287
- grep -rl "$LAST_VERSION" ./compiled-rn | xargs -r sed -i -e "s/$LAST_VERSION/$CURRENT_VERSION/g"
288
- grep -rl "$LAST_VERSION" ./compiled-rn || echo "Version re-applied"
289
- - name: Add files for signing
290
- if: steps.check_should_commit.outputs.should_commit == 'true'
291
- run: |
292
- echo ":"
293
- git add .
294
- - name: Signing files
295
- if: steps.check_should_commit.outputs.should_commit == 'true'
296
- uses: actions/github-script@v6
297
- with:
298
- script: |
299
- // TODO: Move this to a script file.
300
- // We currently can't call scripts from the repo because
301
- // at this point in the workflow, we're on the compiled
302
- // artifact branch (so the scripts don't exist).
303
- // We can fix this with a composite action in the main repo.
304
- // This script is duplicated above.
305
- const fs = require('fs');
306
- const crypto = require('crypto');
307
- const {execSync} = require('child_process');
308
-
309
- // TODO: when we move this to a script, we can use this from npm.
310
- // Copy of signedsource since we can't install deps on this branch.
311
- const GENERATED = '@' + 'generated';
312
- const NEWTOKEN = '<<SignedSource::*O*zOeWoEQle#+L!plEphiEmie@IsG>>';
313
- const PATTERN = new RegExp(`${GENERATED} (?:SignedSource<<([a-f0-9]{32})>>)`);
314
-
315
- const TokenNotFoundError = new Error(
316
- `SignedSource.signFile(...): Cannot sign file without token: ${NEWTOKEN}`
317
- );
318
-
319
- function hash(data, encoding) {
320
- const md5sum = crypto.createHash('md5');
321
- md5sum.update(data, encoding);
322
- return md5sum.digest('hex');
323
- }
324
-
325
- const SignedSource = {
326
- getSigningToken() {
327
- return `${GENERATED} ${NEWTOKEN}`;
328
- },
329
- isSigned(data) {
330
- return PATTERN.exec(data) != null;
331
- },
332
- signFile(data) {
333
- if (!data.includes(NEWTOKEN)) {
334
- if (SignedSource.isSigned(data)) {
335
- // Signing a file that was previously signed.
336
- data = data.replace(PATTERN, SignedSource.getSigningToken());
337
- } else {
338
- throw TokenNotFoundError;
339
- }
340
- }
341
- return data.replace(NEWTOKEN, `SignedSource<<${hash(data, 'utf8')}>>`);
342
- },
343
- };
344
-
345
- const directory = './compiled-rn';
346
- console.log('Signing files in directory:', directory);
347
- try {
348
- const result = execSync(`git status --porcelain ${directory}`, {encoding: 'utf8'});
349
-
350
- // Parse the git status output to get file paths
351
- const files = result.split('\n').filter(file => file.endsWith('.js'));
352
-
353
- if (files.length === 0) {
354
- throw new Error(
355
- 'git status returned no files to sign. this job should not have run.'
356
- );
357
- } else {
358
- files.forEach(line => {
359
- const file = line.slice(3).trim();
360
- if (file) {
361
- console.log(' Signing file:', file);
362
- const originalContents = fs.readFileSync(file, 'utf8');
363
- const signedContents = SignedSource.signFile(
364
- originalContents
365
- // Need to add the header in, since it's not inserted at build time.
366
- .replace(' */\n', ` * ${SignedSource.getSigningToken()}\n */\n`)
367
- );
368
-
369
- fs.writeFileSync(file, signedContents, 'utf8');
370
- }
371
- });
372
- }
373
- } catch (e) {
374
- process.exitCode = 1;
375
- console.error('Error signing files:', e);
376
- }
377
- - name: Will commit these changes
378
- if: steps.check_should_commit.outputs.should_commit == 'true'
379
- run: |
380
- git add .
381
- git status
382
- - name: Commit changes to branch
383
- if: steps.check_should_commit.outputs.should_commit == 'true'
384
- uses: stefanzweifel/git-auto-commit-action@v4
385
- with:
386
- commit_message: |
387
- ${{ github.event.workflow_run.head_commit.message }}
388
-
389
- DiffTrain build for commit https://github.com/facebook/react/commit/${{ github.event.workflow_run.head_sha }}.
390
- branch: builds/facebook-fbsource
391
- commit_user_name: ${{ github.event.workflow_run.actor.name }}
392
- commit_user_email: ${{ github.event.workflow_run.actor.email || format('{0}@users.noreply.github.com', github.event.workflow_run.actor.name) }}
393
- create_branch: true