Skip to content

Commit a4c2f83

Browse files
committed
Validate DotSlash asset reachability and integrity before creating release commit
1 parent 88abb83 commit a4c2f83

File tree

1 file changed

+35
-13
lines changed

1 file changed

+35
-13
lines changed

scripts/releases/write-dotslash-release-asset-urls.js

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ const {
1414
dangerouslyResignGeneratedFile,
1515
processDotSlashFileInPlace,
1616
validateAndParseDotSlashFile,
17+
validateDotSlashArtifactData,
1718
} = require('./utils/dotslash-utils');
19+
const {getWithCurl} = require('./utils/curl-utils');
1820
const {REPO_ROOT} = require('../shared/consts');
1921
const {parseArgs, styleText} = require('util');
2022
const path = require('path');
@@ -63,26 +65,45 @@ async function writeReleaseAssetUrlsToDotSlashFiles(
6365
for (const filename of FIRST_PARTY_DOTSLASH_FILES) {
6466
const fullPath = path.join(REPO_ROOT, filename);
6567
console.log(`Updating ${filename}...`);
68+
const upstreamProviderValidationPromises = [];
6669
await processDotSlashFileInPlace(
6770
fullPath,
68-
(providers, suggestedFilename) => {
71+
(providers, suggestedFilename, artifactInfo) => {
72+
let upstreamHttpProvidersCount = 0;
6973
providers = providers.filter(provider => {
70-
// Remove any existing release asset URLs
71-
if (
72-
(provider.type === 'http' || provider.type == null) &&
73-
provider.url.startsWith(
74-
'https://github.com/facebook/react-native/releases/download/',
75-
)
76-
) {
77-
console.log(styleText('red', ` -${provider.url}`));
78-
return false;
74+
if (provider.type === 'http' || provider.type == null) {
75+
if (
76+
// Remove any existing release asset URLs
77+
provider.url.startsWith(
78+
'https://github.com/facebook/react-native/releases/download/',
79+
)
80+
) {
81+
console.log(styleText('red', ` -${provider.url}`));
82+
return false;
83+
}
84+
console.log(styleText('dim', ` ${provider.url}`));
85+
upstreamProviderValidationPromises.push(
86+
(async () => {
87+
console.log(
88+
`Downloading from ${provider.url} for integrity validation...`,
89+
);
90+
const {data} = await getWithCurl(provider.url);
91+
await validateDotSlashArtifactData(data, artifactInfo);
92+
})(),
93+
);
94+
++upstreamHttpProvidersCount;
95+
return true;
7996
}
80-
console.log(styleText('dim', ` ${provider.url}`));
97+
// Keep all other providers, though we can't validate them nor use them
98+
// in upload-release-assets-for-dotslash.
99+
console.log(
100+
styleText('dim', ` <provider of type: ${provider.type}>`),
101+
);
81102
return true;
82103
});
83-
if (providers.length === 0) {
104+
if (upstreamHttpProvidersCount === 0) {
84105
throw new Error(
85-
'No usable providers found for asset:',
106+
'No upstream HTTP providers found for asset:',
86107
suggestedFilename,
87108
);
88109
}
@@ -95,6 +116,7 @@ async function writeReleaseAssetUrlsToDotSlashFiles(
95116
return providers;
96117
},
97118
);
119+
await Promise.all(upstreamProviderValidationPromises);
98120
await dangerouslyResignGeneratedFile(fullPath);
99121
await validateAndParseDotSlashFile(fullPath);
100122
}

0 commit comments

Comments
 (0)