-
Notifications
You must be signed in to change notification settings - Fork 24.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Download artifacts from CI to speed up testing (#37971) #38612
Merged
cipolleschi
merged 1 commit into
0.71-stable
from
cipolleschi/port-circleci-artifacts-download-071
Jul 25, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -807,6 +807,10 @@ jobs: | |
- report_bundle_size: | ||
platform: android | ||
|
||
- store_artifacts: | ||
path: ~/react-native/packages/rn-tester/android/app/build/outputs/apk/ | ||
destination: rntester-apk | ||
|
||
# Optionally, run disabled tests | ||
- when: | ||
condition: << parameters.run_disabled_tests >> | ||
|
@@ -1053,7 +1057,10 @@ jobs: | |
|
||
- run: | ||
name: Display Environment info | ||
command: npx envinfo@latest | ||
command: | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix windows CI |
||
npm install -g envinfo | ||
envinfo -v | ||
envinfo | ||
|
||
- restore_cache: | ||
keys: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
#!/usr/bin/env node | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const {exec} = require('shelljs'); | ||
|
||
const util = require('util'); | ||
const asyncRequest = require('request'); | ||
const request = util.promisify(asyncRequest); | ||
|
||
let circleCIHeaders; | ||
let jobs; | ||
let baseTemporaryPath; | ||
|
||
async function initialize(circleCIToken, baseTempPath, branchName) { | ||
console.info('Getting CircleCI information'); | ||
circleCIHeaders = {'Circle-Token': circleCIToken}; | ||
baseTemporaryPath = baseTempPath; | ||
exec(`mkdir -p ${baseTemporaryPath}`); | ||
const pipeline = await _getLastCircleCIPipelineID(branchName); | ||
const packageAndReleaseWorkflow = await _getPackageAndReleaseWorkflow( | ||
pipeline.id, | ||
); | ||
const testsWorkflow = await _getTestsWorkflow(pipeline.id); | ||
const jobsPromises = [ | ||
_getCircleCIJobs(packageAndReleaseWorkflow.id), | ||
_getCircleCIJobs(testsWorkflow.id), | ||
]; | ||
|
||
const jobsResults = await Promise.all(jobsPromises); | ||
|
||
jobs = jobsResults.flatMap(j => j); | ||
} | ||
|
||
function baseTmpPath() { | ||
return baseTemporaryPath; | ||
} | ||
|
||
async function _getLastCircleCIPipelineID(branchName) { | ||
const options = { | ||
method: 'GET', | ||
url: 'https://circleci.com/api/v2/project/gh/facebook/react-native/pipeline', | ||
qs: { | ||
branch: branchName, | ||
}, | ||
headers: circleCIHeaders, | ||
}; | ||
|
||
const response = await request(options); | ||
if (response.error) { | ||
throw new Error(error); | ||
} | ||
|
||
const items = JSON.parse(response.body).items; | ||
|
||
if (!items || items.length === 0) { | ||
throw new Error( | ||
'No pipelines found on this branch. Make sure that the CI has run at least once, successfully', | ||
); | ||
} | ||
|
||
const lastPipeline = items[0]; | ||
return {id: lastPipeline.id, number: lastPipeline.number}; | ||
} | ||
|
||
async function _getSpecificWorkflow(pipelineId, workflowName) { | ||
const options = { | ||
method: 'GET', | ||
url: `https://circleci.com/api/v2/pipeline/${pipelineId}/workflow`, | ||
headers: circleCIHeaders, | ||
}; | ||
const response = await request(options); | ||
if (response.error) { | ||
throw new Error(error); | ||
} | ||
|
||
const body = JSON.parse(response.body); | ||
let workflow = body.items.find(w => w.name === workflowName); | ||
_throwIfWorkflowNotFound(workflow, workflowName); | ||
return workflow; | ||
} | ||
|
||
function _throwIfWorkflowNotFound(workflow, name) { | ||
if (!workflow) { | ||
throw new Error( | ||
`Can't find a workflow named ${name}. Please check whether that workflow has started.`, | ||
); | ||
} | ||
} | ||
|
||
async function _getPackageAndReleaseWorkflow(pipelineId) { | ||
return _getSpecificWorkflow(pipelineId, 'package_and_publish_release_dryrun'); | ||
} | ||
|
||
async function _getTestsWorkflow(pipelineId) { | ||
return _getSpecificWorkflow(pipelineId, 'tests'); | ||
} | ||
|
||
async function _getCircleCIJobs(workflowId) { | ||
const options = { | ||
method: 'GET', | ||
url: `https://circleci.com/api/v2/workflow/${workflowId}/job`, | ||
headers: circleCIHeaders, | ||
}; | ||
const response = await request(options); | ||
if (response.error) { | ||
throw new Error(error); | ||
} | ||
|
||
const body = JSON.parse(response.body); | ||
return body.items; | ||
} | ||
|
||
async function _getJobsArtifacts(jobNumber) { | ||
const options = { | ||
method: 'GET', | ||
url: `https://circleci.com/api/v2/project/gh/facebook/react-native/${jobNumber}/artifacts`, | ||
headers: circleCIHeaders, | ||
}; | ||
const response = await request(options); | ||
if (response.error) { | ||
throw new Error(error); | ||
} | ||
|
||
const body = JSON.parse(response.body); | ||
return body.items; | ||
} | ||
|
||
async function _findUrlForJob(jobName, artifactPath) { | ||
const job = jobs.find(j => j.name === jobName); | ||
_throwIfJobIsNull(job); | ||
_throwIfJobIsUnsuccessful(job); | ||
|
||
const artifacts = await _getJobsArtifacts(job.job_number); | ||
return artifacts.find(artifact => artifact.path.indexOf(artifactPath) > -1) | ||
.url; | ||
} | ||
|
||
function _throwIfJobIsNull(job) { | ||
if (!job) { | ||
throw new Error( | ||
`Can't find a job with name ${job.name}. Please verify that it has been executed and that all its dependencies completed successfully.`, | ||
); | ||
} | ||
} | ||
|
||
function _throwIfJobIsUnsuccessful(job) { | ||
if (job.status !== 'success') { | ||
throw new Error( | ||
`The job ${job.name} status is ${job.status}. We need a 'success' status to proceed with the testing.`, | ||
); | ||
} | ||
} | ||
|
||
async function artifactURLHermesDebug() { | ||
return _findUrlForJob('build_hermes_macos-Debug', 'hermes-ios-debug.tar.gz'); | ||
} | ||
|
||
async function artifactURLForMavenLocal() { | ||
return _findUrlForJob('build_and_publish_npm_package-2', 'maven-local.zip'); | ||
} | ||
|
||
async function artifactURLForHermesRNTesterAPK(emulatorArch) { | ||
return _findUrlForJob( | ||
'test_android', | ||
`rntester-apk/hermes/debug/app-hermes-${emulatorArch}-debug.apk`, | ||
); | ||
} | ||
|
||
async function artifactURLForJSCRNTesterAPK(emulatorArch) { | ||
return _findUrlForJob( | ||
'test_android', | ||
`rntester-apk/jsc/debug/app-jsc-${emulatorArch}-debug.apk`, | ||
); | ||
} | ||
|
||
function downloadArtifact(artifactURL, destination) { | ||
exec(`rm -rf ${destination}`); | ||
exec(`curl ${artifactURL} -Lo ${destination}`); | ||
} | ||
|
||
module.exports = { | ||
initialize, | ||
downloadArtifact, | ||
artifactURLForJSCRNTesterAPK, | ||
artifactURLForHermesRNTesterAPK, | ||
artifactURLForMavenLocal, | ||
artifactURLHermesDebug, | ||
baseTmpPath, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/** | ||
* `package` is an object form of package.json | ||
* `dependencies` is a map of dependency to version string | ||
* | ||
* This replaces both dependencies and devDependencies in package.json | ||
*/ | ||
function applyPackageVersions(originalPackageJson, packageVersions) { | ||
const packageJson = {...originalPackageJson}; | ||
|
||
for (const name of Object.keys(packageVersions)) { | ||
if ( | ||
packageJson.dependencies != null && | ||
packageJson.dependencies[name] != null | ||
) { | ||
packageJson.dependencies[name] = packageVersions[name]; | ||
} | ||
|
||
if ( | ||
packageJson.devDependencies != null && | ||
packageJson.devDependencies[name] != null | ||
) { | ||
packageJson.devDependencies[name] = packageVersions[name]; | ||
} | ||
} | ||
return packageJson; | ||
} | ||
|
||
module.exports = { | ||
applyPackageVersions, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In 0.71, we were not storing the APKs in CI. Now we do.