Update test-e2e-local to work with the new android artifacts (#45499)

Summary:
With the recent changes to the CI, we need to update the test-e2e-local to work with the new artifacts

## Changelog:
[Internal] - Update local-e2e-test to run with the new Android Artifacts

Pull Request resolved: https://github.com/facebook/react-native/pull/45499

Test Plan: Tested locally.

Reviewed By: blakef

Differential Revision: D59902087

Pulled By: cipolleschi

fbshipit-source-id: 84ef78e8dba222bf8a9e3620632fb2a9d286d42b
This commit is contained in:
Riccardo Cipolleschi 2024-07-18 05:46:49 -07:00 committed by Facebook GitHub Bot
parent 15b8ac8db2
commit 2d6d067f7a
3 changed files with 46 additions and 50 deletions

View File

@ -155,27 +155,18 @@ async function testRNTesterAndroid(
// Github Actions zips all the APKs in a single archive
console.info('Start Downloading APK');
const rntesterAPKURL =
await ciArtifacts.artifactURLForHermesRNTesterAPK(emulatorArch);
argv.hermes === true
? await ciArtifacts.artifactURLForHermesRNTesterAPK(emulatorArch)
: await ciArtifacts.artifactURLForJSCRNTesterAPK(emulatorArch);
ciArtifacts.downloadArtifact(rntesterAPKURL, downloadPath);
const unzipFolder = path.join(ciArtifacts.baseTmpPath(), 'rntester-apks');
exec(`rm -rf ${unzipFolder}`);
exec(`unzip ${downloadPath} -d ${unzipFolder}`);
let apkPath;
if (argv.hermes === true) {
apkPath = path.join(
unzipFolder,
'hermes',
'release',
`app-hermes-${emulatorArch}-release.apk`,
);
} else {
apkPath = path.join(
unzipFolder,
'jsc',
'release',
`app-jsc-${emulatorArch}-release.apk`,
);
}
let apkPath = path.join(
unzipFolder,
`app-${argv.hermes === true ? 'hermes' : 'jsc'}-${emulatorArch}-release.apk`,
);
exec(`adb install ${apkPath}`);
} else {
@ -298,14 +289,9 @@ async function testRNTestProject(
cd('RNTestProject');
// When using CircleCI artifacts, the CI will zip maven local into a
// /tmp/maven-local subfolder struct.
// When we generate the project manually, there is no such structure.
const expandedMavenLocal =
ciArtifacts == null ? mavenLocalPath : `${mavenLocalPath}/maven-local`;
// need to do this here so that Android will be properly setup either way
exec(
`echo "react.internal.mavenLocalRepo=${expandedMavenLocal}" >> android/gradle.properties`,
`echo "react.internal.mavenLocalRepo=${mavenLocalPath}" >> android/gradle.properties`,
);
// Only build the simulator architecture. CI is however generating only that one.

View File

@ -60,7 +60,7 @@ const reactNativeRepo = 'https://api.github.com/repos/facebook/react-native/';
const reactNativeActionsURL = `${reactNativeRepo}actions/runs`;
async function _getActionRunsOnBranch() /*: Promise<WorkflowRuns> */ {
const url = `${reactNativeActionsURL}?branch=${branch}`;
const url = `${reactNativeActionsURL}?branch=${branch}&per_page=100`;
const options = {
method: 'GET',
headers: ciHeaders,
@ -81,7 +81,7 @@ async function _getActionRunsOnBranch() /*: Promise<WorkflowRuns> */ {
}
async function _getArtifacts(run_id /*: number */) /*: Promise<Artifacts> */ {
const url = `${reactNativeActionsURL}/${run_id}/artifacts`;
const url = `${reactNativeActionsURL}/${run_id}/artifacts?per_page=100`;
const options = {
method: 'GET',
headers: ciHeaders,
@ -121,11 +121,26 @@ async function initialize(
'X-GitHub-Api-Version': '2022-11-28',
};
const testAllWorkflow = (await _getActionRunsOnBranch()).workflow_runs
const testAllWorkflows = (await _getActionRunsOnBranch()).workflow_runs
.filter(w => w.name === 'Test All')
.sort((a, b) => (a.created_at > b.created_at ? -1 : 1))[0];
.sort((a, b) => {
// Date.getTime is needed to make Flow happy with arithmetic
return (
new Date(b.created_at).getTime() - new Date(a.created_at).getTime()
);
});
artifacts = await _getArtifacts(testAllWorkflow.id);
if (testAllWorkflows.length === 0) {
console.error('No Test-All workflow found');
process.exit(1);
}
console.log(`\nUsing github workflow run ${testAllWorkflows[0].run_number}`);
console.log(
`https://github.com/facebook/react-native/actions/runs/${testAllWorkflows[0].id}\n`,
);
artifacts = await _getArtifacts(testAllWorkflows[0].id);
}
function downloadArtifact(
@ -146,37 +161,37 @@ function downloadArtifact(
async function artifactURLForJSCRNTesterAPK(
emulatorArch /*: string */,
) /*: Promise<string> */ {
const url = artifacts.artifacts.filter(a => a.name === 'rntester-apk')[0]
.archive_download_url;
return Promise.resolve(url);
return getArtifactURL('rntester-jsc-release');
}
async function artifactURLForHermesRNTesterAPK(
emulatorArch /*: string */,
) /*: Promise<string> */ {
const url = artifacts.artifacts.filter(a => a.name === 'rntester-apk')[0]
.archive_download_url;
return Promise.resolve(url);
return getArtifactURL('rntester-hermes-release');
}
async function artifactURLForMavenLocal() /*: Promise<string> */ {
const url = artifacts.artifacts.filter(a => a.name === 'maven-local')[0]
.archive_download_url;
return Promise.resolve(url);
return getArtifactURL('maven-local');
}
async function getArtifactURL(
artifactName /*: string */,
) /*: Promise<string> */ {
const filteredUrls = artifacts.artifacts.filter(a => a.name === artifactName);
if (filteredUrls.length === 0) {
console.error(`No artifact found with name ${artifactName}`);
process.exit(1);
}
return filteredUrls[0].archive_download_url;
}
async function artifactURLHermesDebug() /*: Promise<string> */ {
const url = artifacts.artifacts.filter(
a => a.name === 'hermes-darwin-bin-Debug',
)[0].archive_download_url;
return Promise.resolve(url);
return getArtifactURL('hermes-darwin-bin-Debug');
}
async function artifactURLForReactNative() /*: Promise<string> */ {
const url = artifacts.artifacts.filter(
a => a.name === 'react-native-package',
)[0].archive_download_url;
return Promise.resolve(url);
return getArtifactURL('react-native-package');
}
function baseTmpPath() /*: string */ {

View File

@ -230,11 +230,6 @@ async function downloadArtifacts(
console.info(`Unzipping into ${mavenLocalPath}`);
exec(`unzip -oq ${mavenLocalZipPath} -d ${mavenLocalPath}`);
// Github Actions are zipping a zip. Needs to move it to the right place and unzip it again
exec(`rm -rf ${mavenLocalZipPath}`);
exec(`mv ${mavenLocalPath}/maven-local.zip ${mavenLocalZipPath}`);
exec(`unzip -oq ${mavenLocalZipPath} -d ${mavenLocalPath}`);
console.info('\n[Download] Hermes');
ciArtifacts.downloadArtifact(hermesURLZip, hermesPathZip);
exec(`unzip ${hermesPathZip} -d ${ciArtifacts.baseTmpPath()}/hermes`);