Skip to content

Commit

Permalink
Added downloading and publishing artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcc007 committed Mar 17, 2019
1 parent c050fc7 commit 870658c
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 34 deletions.
30 changes: 12 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,16 @@ jobs:

script:
- cd example; sylph
# bundle artifacts for later deploy
- tar cvzf /tmp/sylph-artifacts.tar.gz /tmp/sylph/artifacts

# # copy artifacts to cache for later deploy
# - tar cvzf $HOME/screenshots/screenshots.tar.gz ios/fastlane/screenshots android/fastlane/metadata/android/*/images
# - zip -r $HOME/screenshots/screenshots.zip ios/fastlane/screenshots android/fastlane/metadata/android/*/images
# # save artifacts for later deploy of second artifact
# cache:
# directories:
# - $HOME/screenshots
#
# # deploy artifacts
# deploy:
# provider: releases
# draft: false
# skip_cleanup: true
# api_key:
# secure: wyPNNbjTFChWOGc/JiTpGhN490dRzz/qhU2T3CddZALjy4VN3LywennK3xnTOAq+FEYE9H/quP/SxkUX154al/lxeL6QuN5D0Ev2bL3lS9jyaoe0NOKx5GnNTzfv84taZPi768UF4rgYqzzdF8WJTCe0dlvDH7qKgH+dHIZGoB1dM/hhWMEXUv0uAZuFDkepxWHOLHsIABunkz428MEsSRCTdEWOsgdFiEl+DOC5ErmorgHazUWPpSwenz13kCLhU+wT2Fsek5tGBO6GT1Mvw8qrht3LUZBaBQJfx4yhdXQKtq0Dr+gI9a3sbF/3TKV0nRvDVA+KGmMLHT+fkRrz1xkGvrLnCDfkylDZlmn/IoQUkv4JwI+lJIXfUp40pMmSlFH1WKToWSjMsPSxv02fVYzxNZoxlno+qyKk4lfdROOSSYS5LjmMd+Lrvhmx7vNMCHl57fdXdKwgyJllxT/khMZTJv5IPQih1yi3m/hDw0s59IHYd22QHFoodcdAPy2xxeVh8VhzhucpesWAvoFZfgdTmPZXAzpMR4kEaeBb5f3Z/Eg3AypDPXg67kXwFqTRL+ZqDzOFynZYJML8RbsZd/nqU5TYc0Ocmh0YMA3v0Z43wuZMshXOXujl8z3zmnwzV/QmFP0U/phOGa9SmvKtRyGQoTGtIXoPWdXrRpgm3F4=
# file: $HOME/sylph/sylph.tar.gz
# on:
# tags: true
# deploy artifacts
deploy:
provider: releases
draft: false
skip_cleanup: true
api_key:
secure: wyPNNbjTFChWOGc/JiTpGhN490dRzz/qhU2T3CddZALjy4VN3LywennK3xnTOAq+FEYE9H/quP/SxkUX154al/lxeL6QuN5D0Ev2bL3lS9jyaoe0NOKx5GnNTzfv84taZPi768UF4rgYqzzdF8WJTCe0dlvDH7qKgH+dHIZGoB1dM/hhWMEXUv0uAZuFDkepxWHOLHsIABunkz428MEsSRCTdEWOsgdFiEl+DOC5ErmorgHazUWPpSwenz13kCLhU+wT2Fsek5tGBO6GT1Mvw8qrht3LUZBaBQJfx4yhdXQKtq0Dr+gI9a3sbF/3TKV0nRvDVA+KGmMLHT+fkRrz1xkGvrLnCDfkylDZlmn/IoQUkv4JwI+lJIXfUp40pMmSlFH1WKToWSjMsPSxv02fVYzxNZoxlno+qyKk4lfdROOSSYS5LjmMd+Lrvhmx7vNMCHl57fdXdKwgyJllxT/khMZTJv5IPQih1yi3m/hDw0s59IHYd22QHFoodcdAPy2xxeVh8VhzhucpesWAvoFZfgdTmPZXAzpMR4kEaeBb5f3Z/Eg3AypDPXg67kXwFqTRL+ZqDzOFynZYJML8RbsZd/nqU5TYc0Ocmh0YMA3v0Z43wuZMshXOXujl8z3zmnwzV/QmFP0U/phOGa9SmvKtRyGQoTGtIXoPWdXrRpgm3F4=
file: /tmp/sylph-artifacts.tar.gz
on:
tags: true
28 changes: 12 additions & 16 deletions bin/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,8 @@ void run(Map config, String projectArn, String runName, int runTimeout) async {
sylph.uploadFile(projectArn, testSpecPath, 'APPIUM_PYTHON_TEST_SPEC');

// run tests and report
runTests(
runName,
runTimeout,
projectArn,
devicePoolArn,
appArn,
testPackageArn,
testSpecArn,
);
runTests(runName, runTimeout, projectArn, devicePoolArn, appArn,
testPackageArn, testSpecArn, '${config['tmp_dir']}/artifacts');
}
}

Expand All @@ -115,13 +108,15 @@ void run(Map config, String projectArn, String runName, int runTimeout) async {
}

void runTests(
String runName,
int runTimeout,
String projectArn,
String devicePoolArn,
String appArn,
String testPackageArn,
String testSpecArn) {
String runName,
int runTimeout,
String projectArn,
String devicePoolArn,
String appArn,
String testPackageArn,
String testSpecArn,
String downloadDir,
) {
// Set job timeout ???

// Schedule run
Expand All @@ -135,6 +130,7 @@ void runTests(
sylph.runReport(result);

// Download artifacts
sylph.downloadArtifacts(runArn, downloadDir);
}

String upLoadBuild(String projectArn, sylph.DeviceType deviceType) {
Expand Down
24 changes: 24 additions & 0 deletions lib/sylph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:io';
import 'dart:convert';
import 'package:sylph/utils.dart';
import 'package:path/path.dart' as p;
import 'package:uuid/uuid.dart';
import 'package:yaml/yaml.dart';

enum DeviceType { ios, android }
Expand Down Expand Up @@ -243,3 +244,26 @@ Future bundleFlutterTests(Map config) async {
// bundle the scripts
cmd('zip', ['-r', testBundlePath, '$appName/script'], '$tmpDir');
}

/// Downloads artifacts generated by a run.
void downloadArtifacts(String runArn, String downloadDir) {
clearDirectory(downloadDir);
var raw = cmd('aws',
['devicefarm', 'list-artifacts', '--arn', runArn, '--type', 'FILE']);
// print('raw=$raw');
var artifacts = jsonDecode(raw)['artifacts'];

for (var artifact in artifacts) {
// print('artifact=$artifact');
final name = artifact['name'];
final extension = artifact['extension'];
// final type = artifact['type'];
final fileUrl = artifact['url'];

final fileName =
name.replaceAll(' ', '_') + '.' + Uuid().v1() + '.' + extension;
final filePath = downloadDir + '/' + fileName;
print(filePath);
cmd('wget', ['-O', filePath, fileUrl]);
}
}
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ dependencies:
args: ^1.5.1
yaml: ^2.1.15
resource: ^2.1.5
uuid: ^2.0.0
queries: ^0.1.10

dev_dependencies:
test: ^1.0.0
Expand Down
16 changes: 16 additions & 0 deletions test/sylph_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,20 @@ void main() {

expect(devicePoolInfo['pool_type'], enumToStr(DeviceType.android));
});

test('download artifacts', () {
// get project arn
// aws devicefarm list-projects
// get project runs
// aws devicefarm list-runs --arn <project arn>
// 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';
final runArn =
'arn:aws:devicefarm:us-west-2:122621792560:run:fef6e39b-8ab0-44f4-b6ae-09115edbce36/42c84f3d-e061-4f23-ac7c-8d5d3a6b8f0f';
// list artifacts
downloadArtifacts(runArn, downloadDir);
});
}

0 comments on commit 870658c

Please sign in to comment.