Skip to content

Commit

Permalink
Added support for artifacts download for multiple pools during a Sylp…
Browse files Browse the repository at this point in the history
…h run

Former-commit-id: 7b0d9b0
  • Loading branch information
mmcc007 committed Jun 22, 2019
1 parent 212af65 commit 233a191
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ jobs:
# publish artifacts to GitHub
before_deploy:
# bundle artifacts for publishing
- tar cvzf /tmp/sylph-artifacts.tar.gz -C /tmp sylph/artifacts
- zip -r /tmp/sylph_artifacts.zip ~/sylph_artifacts
deploy:
provider: releases
skip_cleanup: true
api_key:
secure: OCyFLrBnorKGT3g7uf0BClF85lb+d6KDcvAvZvEiAec4P1GoaYoxz7iXAYEQ7rLBp1QYu94sW6diM2vd4g9V3NAGQAMzFLdVYkIyueHXE+PW4Z4i5SFm8d8VSTck1SCN4gBtd1j3pKbFCMH8637lrZ24uz46f4Gk4qlQ1PVbfkSIFm/eKTtFzRQO4XCOiMj+sHd/M72+jhfzDhwXAi7cG6Qf+cPpvAGLK7mZvsjg6UBrYltn7sOhG6P8XO927GXz/N8VutHvz6Ip0c0yNXpjoMiNub2YMzAxNmnxurabxDhZubtEqwn5bwohOce6mxqC3z6MH5Xq8RUW7BpmpFakHw+usFp1tTQ3QSBeVblZTX++wOzEnvF9vGh0IhMDr8iJBYFGjQtpJyW2Iz0EaU5W64Qh/FxCjgpyqN2hOQY43wLxnK3vpoBiqKOV+ZscXEgyJF0pfnMbFjahU/b/mbGbu6EmQvkWFxN5xnPH0qQ0u2yIlvDydgzWmX3nEjuYTBVFn3eEfQAfjZOEP9bmo3cK4ObyQSaqQAVJPS+ZCkGRlF7WPzJtWQX6kl9wNSAG94dq6MQ8dl/7NrIr1JXNxwcTb/q8CuYEpq6ZrbMlaFCFvgdFdpKqZCoCkD284wnyUUQUDLM3O6Tr2nYNTLHVGriPhcRSjdCVvZYDWo4wx1WYbAY=
file: /tmp/sylph-artifacts.tar.gz
file: /tmp/sylph_artifacts.zip
on:
tags: true
34 changes: 19 additions & 15 deletions bin/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const kConfigFilePath = 'sylph.yaml'; // todo: allow different names
/// Uploads debug app and integration test to device farm and runs test.
main(List<String> arguments) async {
final localRunTimeout = 720; // todo: allow different timeouts
final runName = 'android run 1'; // todo: allow different names
// final runName = 'ios run 1'; // todo: allow different names
print('Starting AWS Device Farm run \'$runName\'...');
final runName = 'android and ios run 1'; // todo: allow different names
final timestamp = genTimestamp();
print('Starting AWS Device Farm run \'$runName\' at $timestamp ...');
print('Config file: $kConfigFilePath');

// Parse config file
Expand All @@ -24,7 +24,7 @@ main(List<String> arguments) async {
final projectArn =
sylph.setupProject(config['project_name'], config['default_job_timeout']);

await run(config, projectArn, runName, localRunTimeout);
await run(config, projectArn, runName, localRunTimeout, timestamp);
print('Completed AWS Device Farm run \'$runName\'.');
}

Expand All @@ -36,7 +36,8 @@ main(List<String> arguments) async {
/// 4. For each test in each testsuite
/// 1. Run tests on device pool
/// 2. Report and collect artifacts
void run(Map config, String projectArn, String runName, int runTimeout) async {
void run(Map config, String projectArn, String runName, int runTimeout,
DateTime timestamp) async {
final List testSuites = config['test_suites'];
// print('testSuites=$testSuites');
for (var testSuite in testSuites) {
Expand Down Expand Up @@ -85,9 +86,13 @@ void run(Map config, String projectArn, String runName, int runTimeout) async {
String testSpecArn =
sylph.uploadFile(projectArn, testSpecPath, 'APPIUM_PYTHON_TEST_SPEC');

// construct artifacts dir for this run
final runArtifactsDir =
'${config['artifacts_dir']}/$runName $timestamp/$poolName';

// run tests and report
runTests(runName, runTimeout, projectArn, devicePoolArn, appArn,
testPackageArn, testSpecArn, '${config['tmp_dir']}/artifacts');
testPackageArn, testSpecArn, runArtifactsDir);
}
}
}
Expand Down Expand Up @@ -118,15 +123,14 @@ Future<String> buildUploadApp(

/// Runs the test suite and downloads artifacts.
void runTests(
String runName,
int runTimeout,
String projectArn,
String devicePoolArn,
String appArn,
String testPackageArn,
String testSpecArn,
String artifactsDir,
) {
String runName,
int runTimeout,
String projectArn,
String devicePoolArn,
String appArn,
String testPackageArn,
String testSpecArn,
String artifactsDir) {
// Schedule run
print('Starting run \'$runName\' on AWS Device Farms');
String runArn = sylph.scheduleRun(
Expand Down
4 changes: 3 additions & 1 deletion example/sylph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ default_job_timeout: 7 # minutes, set at project creation

tmp_dir: /tmp/sylph

artifacts_dir: ~/sylph_artifacts

device_pools:

- pool_name: android pool 1
Expand Down Expand Up @@ -38,5 +40,5 @@ test_suites:
- test_driver/main_test.dart
device_pools:
- android pool 1
# - ios pool 1
- ios pool 1
job_timeout: 7 # minutes, set per job
12 changes: 8 additions & 4 deletions lib/sylph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,13 @@ String uploadFile(String projectArn, String filePath, String fileType) {
}

/// Downloads artifacts generated by a run.
void downloadArtifacts(String runArn, String artifactsDir) {
clearDirectory(artifactsDir);
var artifacts = deviceFarmCmd(
// todo: organize artifacts by device in each pool
void downloadArtifacts(String runArn, String runArtifactsDir) {
// runArtifactsDir = runArtifactsDir.replaceAll(' ', '_');
// create directory
clearDirectory(runArtifactsDir);

final artifacts = deviceFarmCmd(
['list-artifacts', '--arn', runArn, '--type', 'FILE'])['artifacts'];

for (final artifact in artifacts) {
Expand All @@ -238,7 +242,7 @@ void downloadArtifacts(String runArn, String artifactsDir) {
final fileUrl = artifact['url'];
final fileName =
name.replaceAll(' ', '_') + '.' + Uuid().v1() + '.' + extension;
final filePath = artifactsDir + '/' + fileName;
final filePath = runArtifactsDir + '/' + fileName;
print(filePath);
cmd('wget', ['-O', filePath, fileUrl]);
}
Expand Down
7 changes: 7 additions & 0 deletions lib/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,10 @@ Map getDevicePoolInfo(Map config, String poolName) {

/// Converts [enum] value to [String].
String enumToStr(dynamic _enum) => _enum.toString().split('.').last;

/// Generates timestamp as [DateTime]
DateTime genTimestamp() {
final timestamp = DateTime.fromMillisecondsSinceEpoch(
DateTime.now().millisecondsSinceEpoch);
return timestamp;
}
4 changes: 2 additions & 2 deletions test/sylph_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ void main() {
// get artifacts by run, by test suite, by test, etc..
// aws devicefarm list-artifacts --arn <run arn>
// download each artifact

final downloadDir = '/tmp/tmp/artifactsxxx';
DateTime timestamp = genTimestamp();
final downloadDir = '/tmp/tmp/artifacts xxx $timestamp';
final runArn =
'arn:aws:devicefarm:us-west-2:122621792560:run:fef6e39b-8ab0-44f4-b6ae-09115edbce36/42c84f3d-e061-4f23-ac7c-8d5d3a6b8f0f';
// list artifacts
Expand Down

0 comments on commit 233a191

Please sign in to comment.