@samitouri / QOS-React-1 / commits / 4708fb92c2

Fix runtime_commit_artifacts workflow

I messed up the yml syntax and also realized that our script doesn't currently handle renames or deletes, so I fixed that ghstack-source-id: 7d481a951abaabd1a2985c8959d8acb7103ed12e Pull Request resolved: https://github.com/facebook/react/pull/31028

Lauren Tan committed Sep 23, 2024 at 17:36 UTC 4708fb92c24bbc769acbc075de6105590fd29edc
1 file changed +22 -14
.github/workflows/runtime_commit_artifacts.yml
+22 -14
@@ -171,7 +171,7 @@ jobs:
171
172 commit_www_artifacts:
173 needs: download_artifacts
174 - if: ${{ (github.ref == 'refs/heads/main' && needs.download_artifacts.outputs.www_branch_count == '0') || github.ref == 'refs/heads/meta-www' }}
174 + if: inputs.force == true || (github.ref == 'refs/heads/main' && needs.download_artifacts.outputs.www_branch_count == '0')
175 runs-on: ubuntu-latest
176 steps:
177 - uses: actions/checkout@v4
@@ -201,7 +201,7 @@ jobs:
201 grep -rl "$CURRENT_VERSION_MODERN" ./compiled | xargs -r sed -i -e "s/$CURRENT_VERSION_MODERN/$LAST_VERSION_MODERN/g"
202 grep -rl "$CURRENT_VERSION_MODERN" ./compiled || echo "Modern version reverted"
203 - name: Check for changes
204 - if: !inputs.force
204 + if: inputs.force != true
205 id: check_should_commit
206 run: |
207 echo "Full git status"
@@ -219,7 +219,7 @@ jobs:
219 echo "should_commit=false" >> "$GITHUB_OUTPUT"
220 fi
221 - name: Re-apply version changes
222 - if: inputs.force || (steps.check_should_commit.outputs.should_commit == 'true' && needs.download_artifacts.outputs.last_version_classic != '' && needs.download_artifacts.outputs.last_version_modern != '')
222 + if: inputs.force == true || (steps.check_should_commit.outputs.should_commit == 'true' && needs.download_artifacts.outputs.last_version_classic != '' && needs.download_artifacts.outputs.last_version_modern != '')
223 env:
224 CURRENT_VERSION_CLASSIC: ${{ needs.download_artifacts.outputs.current_version_classic }}
225 CURRENT_VERSION_MODERN: ${{ needs.download_artifacts.outputs.current_version_modern }}
@@ -236,12 +236,12 @@ jobs:
236 grep -rl "$LAST_VERSION_MODERN" ./compiled | xargs -r sed -i -e "s/$LAST_VERSION_MODERN/$CURRENT_VERSION_MODERN/g"
237 grep -rl "$LAST_VERSION_MODERN" ./compiled || echo "Classic version re-applied"
238 - name: Will commit these changes
239 - if: inputs.force || steps.check_should_commit.outputs.should_commit == 'true'
239 + if: inputs.force == true || steps.check_should_commit.outputs.should_commit == 'true'
240 run: |
241 echo ":"
242 git status -u
243 - name: Commit changes to branch
244 - if: inputs.force || steps.check_should_commit.outputs.should_commit == 'true'
244 + if: inputs.force == true || steps.check_should_commit.outputs.should_commit == 'true'
245 uses: stefanzweifel/git-auto-commit-action@v4
246 with:
247 commit_message: |
@@ -255,7 +255,7 @@ jobs:
255
256 commit_fbsource_artifacts:
257 needs: download_artifacts
258 - if: ${{ (github.ref == 'refs/heads/main' && needs.download_artifacts.outputs.fbsource_branch_count == '0') || github.ref == 'refs/heads/meta-fbsource' }}
258 + if: inputs.force == true || (github.ref == 'refs/heads/main' && needs.download_artifacts.outputs.fbsource_branch_count == '0')
259 runs-on: ubuntu-latest
260 steps:
261 - uses: actions/checkout@v4
@@ -278,7 +278,7 @@ jobs:
278 grep -rl "$CURRENT_VERSION" ./compiled-rn | xargs -r sed -i -e "s/$CURRENT_VERSION/$LAST_VERSION/g"
279 grep -rl "$CURRENT_VERSION" ./compiled-rn || echo "Version reverted"
280 - name: Check for changes
281 - if: !inputs.force
281 + if: inputs.force != 'true'
282 id: check_should_commit
283 run: |
284 echo "Full git status"
@@ -297,7 +297,7 @@ jobs:
297 echo "should_commit=false" >> "$GITHUB_OUTPUT"
298 fi
299 - name: Re-apply version changes
300 - if: inputs.force || (steps.check_should_commit.outputs.should_commit == 'true' && needs.download_artifacts.outputs.last_version_rn != '')
300 + if: inputs.force == true || (steps.check_should_commit.outputs.should_commit == 'true' && needs.download_artifacts.outputs.last_version_rn != '')
301 env:
302 CURRENT_VERSION: ${{ needs.download_artifacts.outputs.current_version_rn }}
303 LAST_VERSION: ${{ needs.download_artifacts.outputs.last_version_rn }}
@@ -307,12 +307,12 @@ jobs:
307 grep -rl "$LAST_VERSION" ./compiled-rn | xargs -r sed -i -e "s/$LAST_VERSION/$CURRENT_VERSION/g"
308 grep -rl "$LAST_VERSION" ./compiled-rn || echo "Version re-applied"
309 - name: Add files for signing
310 - if: inputs.force || steps.check_should_commit.outputs.should_commit == 'true'
310 + if: inputs.force == true || steps.check_should_commit.outputs.should_commit == 'true'
311 run: |
312 echo ":"
313 git add .
314 - name: Signing files
315 - if: inputs.force || steps.check_should_commit.outputs.should_commit == 'true'
315 + if: inputs.force == true || steps.check_should_commit.outputs.should_commit == 'true'
316 uses: actions/github-script@v7
317 with:
318 script: |
@@ -366,8 +366,9 @@ jobs:
366 console.log('Signing files in directory:', directory);
367 try {
368 const result = execSync(`git status --porcelain ${directory}`, {encoding: 'utf8'});
369 + console.log(result);
370
370 - // Parse the git status output to get file paths
371 + // Parse the git status output to get file paths!
372 const files = result.split('\n').filter(file => file.endsWith('.js'));
373
374 if (files.length === 0) {
@@ -376,7 +377,14 @@ jobs:
377 );
378 } else {
379 files.forEach(line => {
379 - const file = line.slice(3).trim();
380 + let file = null;
381 + if (line.startsWith('D ')) {
382 + return;
383 + } else if (line.startsWith('R ')) {
384 + file = line.slice(line.indexOf('->') + 3);
385 + } else {
386 + file = line.slice(3).trim();
387 + }
388 if (file) {
389 console.log(' Signing file:', file);
390 const originalContents = fs.readFileSync(file, 'utf8');
@@ -395,12 +403,12 @@ jobs:
403 console.error('Error signing files:', e);
404 }
405 - name: Will commit these changes
398 - if: inputs.force || steps.check_should_commit.outputs.should_commit == 'true'
406 + if: inputs.force == true || steps.check_should_commit.outputs.should_commit == 'true'
407 run: |
408 git add .
409 git status
410 - name: Commit changes to branch
403 - if: inputs.force || steps.check_should_commit.outputs.should_commit == 'true'
411 + if: inputs.force == true || steps.check_should_commit.outputs.should_commit == 'true'
412 uses: stefanzweifel/git-auto-commit-action@v4
413 with:
414 commit_message: |