From ab6035173665464eacc2b44fc502668c05a12c3d Mon Sep 17 00:00:00 2001 From: Jan Kassens Date: Mon, 6 Mar 2023 11:50:01 -0500 Subject: [PATCH 1/3] Use content hash for facebook-www builds --- .github/workflows/commit_artifacts.yml | 4 --- scripts/rollup/build-all-release-channels.js | 30 ++++++++++++++------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.github/workflows/commit_artifacts.yml b/.github/workflows/commit_artifacts.yml index 2c32bef7cb3a0..1099fbfb6f894 100644 --- a/.github/workflows/commit_artifacts.yml +++ b/.github/workflows/commit_artifacts.yml @@ -123,10 +123,6 @@ jobs: ./compiled/babel-plugin-react-refresh/index.js ls -R ./compiled - - name: Add REVISION files - run: | - echo ${{ github.sha }} >> ./compiled/facebook-www/REVISION - cp ./compiled/facebook-www/REVISION ./compiled/facebook-www/REVISION_TRANSFORMS - uses: actions/upload-artifact@v3 with: name: compiled diff --git a/scripts/rollup/build-all-release-channels.js b/scripts/rollup/build-all-release-channels.js index 992caf742ddd0..957bfb842cb55 100644 --- a/scripts/rollup/build-all-release-channels.js +++ b/scripts/rollup/build-all-release-channels.js @@ -2,6 +2,7 @@ /* eslint-disable no-for-of-loops/no-for-of-loops */ +const crypto = require('node:crypto'); const fs = require('fs'); const fse = require('fs-extra'); const {spawnSync} = require('child_process'); @@ -40,10 +41,7 @@ if (dateString.startsWith("'")) { // Build the artifacts using a placeholder React version. We'll then do a string // replace to swap it with the correct version per release channel. -// -// The placeholder version is the same format that the "next" channel uses -const PLACEHOLDER_REACT_VERSION = - ReactVersion + '-' + nextChannelLabel + '-' + sha + '-' + dateString; +const PLACEHOLDER_REACT_VERSION = ReactVersion + '-PLACEHOLDER'; // TODO: We should inject the React version using a build-time parameter // instead of overwriting the source files. @@ -164,19 +162,27 @@ function processStable(buildDir) { } if (fs.existsSync(buildDir + '/facebook-www')) { - for (const fileName of fs.readdirSync(buildDir + '/facebook-www')) { + const hash = crypto.createHash('sha1'); + for (const fileName of fs.readdirSync(buildDir + '/facebook-www').sort()) { const filePath = buildDir + '/facebook-www/' + fileName; const stats = fs.statSync(filePath); if (!stats.isDirectory()) { + hash.update(fs.readFileSync(filePath)); fs.renameSync(filePath, filePath.replace('.js', '.classic.js')); } } updatePlaceholderReactVersionInCompiledArtifacts( buildDir + '/facebook-www', - ReactVersion + '-www-classic-' + sha + '-' + dateString + ReactVersion + '-www-classic-' + hash.digest('hex').substr(0, 8) ); } + // Update remaining placeholders with next channel version + updatePlaceholderReactVersionInCompiledArtifacts( + buildDir, + ReactVersion + '-' + nextChannelLabel + '-' + sha + '-' + dateString + ); + if (fs.existsSync(buildDir + '/sizes')) { fs.renameSync(buildDir + '/sizes', buildDir + '/sizes-stable'); } @@ -210,19 +216,27 @@ function processExperimental(buildDir, version) { } if (fs.existsSync(buildDir + '/facebook-www')) { - for (const fileName of fs.readdirSync(buildDir + '/facebook-www')) { + const hash = crypto.createHash('sha1'); + for (const fileName of fs.readdirSync(buildDir + '/facebook-www').sort()) { const filePath = buildDir + '/facebook-www/' + fileName; const stats = fs.statSync(filePath); if (!stats.isDirectory()) { + hash.update(fs.readFileSync(filePath)); fs.renameSync(filePath, filePath.replace('.js', '.modern.js')); } } updatePlaceholderReactVersionInCompiledArtifacts( buildDir + '/facebook-www', - ReactVersion + '-www-modern-' + sha + '-' + dateString + ReactVersion + '-www-modern-' + hash.digest('hex').substr(0, 8) ); } + // Update remaining placeholders with next channel version + updatePlaceholderReactVersionInCompiledArtifacts( + buildDir, + ReactVersion + '-' + nextChannelLabel + '-' + sha + '-' + dateString + ); + if (fs.existsSync(buildDir + '/sizes')) { fs.renameSync(buildDir + '/sizes', buildDir + '/sizes-experimental'); } From 4b2743653c7b071e95df82fc3e16850c725c5450 Mon Sep 17 00:00:00 2001 From: Jan Kassens Date: Mon, 6 Mar 2023 16:29:31 -0500 Subject: [PATCH 2/3] Keep REVISION file --- .github/workflows/commit_artifacts.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/commit_artifacts.yml b/.github/workflows/commit_artifacts.yml index 1099fbfb6f894..7cd25cc0dc590 100644 --- a/.github/workflows/commit_artifacts.yml +++ b/.github/workflows/commit_artifacts.yml @@ -123,6 +123,9 @@ jobs: ./compiled/babel-plugin-react-refresh/index.js ls -R ./compiled + - name: Add REVISION file + run: | + echo ${{ github.sha }} >> ./compiled/facebook-www/REVISION - uses: actions/upload-artifact@v3 with: name: compiled @@ -142,6 +145,12 @@ jobs: name: compiled path: compiled/ - run: git status -u + - name: Abort if only REVISION file changed + run: | + if [[ $(git status -u --porcelain | wc -l) -eq 1 && $(git status -u --porcelain | grep REVISION) ]]; then + echo "Only REVISION file changed. Aborting." + circleci-agent step halt + fi - name: Commit changes to branch uses: stefanzweifel/git-auto-commit-action@v4 with: From e171514c8c8cef62b816a3b871120591633729e8 Mon Sep 17 00:00:00 2001 From: Jan Kassens Date: Mon, 6 Mar 2023 16:50:30 -0500 Subject: [PATCH 3/3] actually use GitHub Actions... --- .github/workflows/commit_artifacts.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/commit_artifacts.yml b/.github/workflows/commit_artifacts.yml index 7cd25cc0dc590..7ad7e5a8641db 100644 --- a/.github/workflows/commit_artifacts.yml +++ b/.github/workflows/commit_artifacts.yml @@ -145,13 +145,16 @@ jobs: name: compiled path: compiled/ - run: git status -u - - name: Abort if only REVISION file changed + - name: Check if only the REVISION file has changed + id: check_should_commit run: | - if [[ $(git status -u --porcelain | wc -l) -eq 1 && $(git status -u --porcelain | grep REVISION) ]]; then - echo "Only REVISION file changed. Aborting." - circleci-agent step halt + if git status --porcelain | grep -qv '/REVISION$'; then + echo "should_commit=true" >> "$GITHUB_OUTPUT" + else + echo "should_commit=false" >> "$GITHUB_OUTPUT" fi - name: Commit changes to branch + if: steps.check_should_commit.outputs.should_commit == 'true' uses: stefanzweifel/git-auto-commit-action@v4 with: commit_message: |