From b35804210c8b15c2dbe72030d8bc6a50d6663e00 Mon Sep 17 00:00:00 2001 From: Madhuri Gummalla Date: Mon, 6 Nov 2017 10:24:30 -0500 Subject: [PATCH] allow specifying external tester groups when uploading to test flight, allow passing fastlane arguments (#80) --- .../resources.resjson/en-US/resources.resjson | 4 + Tasks/app-store-release/Tests/L0.ts | 41 +++++++++ .../Tests/L0ProductionFastlaneArguments.ts | 72 +++++++++++++++ ...htDistributeToExternalTestersWithGroups.ts | 89 +++++++++++++++++++ .../Tests/L0TestFlightFastlaneArguments.ts | 72 +++++++++++++++ Tasks/app-store-release/app-store-release.ts | 7 ++ Tasks/app-store-release/task.json | 21 ++++- Tasks/app-store-release/task.loc.json | 21 ++++- app-store-vsts-extension.json | 2 +- 9 files changed, 326 insertions(+), 3 deletions(-) create mode 100644 Tasks/app-store-release/Tests/L0ProductionFastlaneArguments.ts create mode 100644 Tasks/app-store-release/Tests/L0TestFlightDistributeToExternalTestersWithGroups.ts create mode 100644 Tasks/app-store-release/Tests/L0TestFlightFastlaneArguments.ts diff --git a/Tasks/app-store-release/Strings/resources.resjson/en-US/resources.resjson b/Tasks/app-store-release/Strings/resources.resjson/en-US/resources.resjson index de97de3..a5c433c 100644 --- a/Tasks/app-store-release/Strings/resources.resjson/en-US/resources.resjson +++ b/Tasks/app-store-release/Strings/resources.resjson/en-US/resources.resjson @@ -45,6 +45,8 @@ "loc.input.help.shouldSkipSubmission": "Select to upload the IPA but not distribute it to testers.", "loc.input.label.distributedToExternalTesters": "Distribute to External Testers", "loc.input.help.distributedToExternalTesters": "Select to distribute the build to external testers (cannot be used with 'Skip Build Processing Wait' and 'Skip Submission'). Using this option requires setting release notes in 'What to Test?'", + "loc.input.label.externalTestersGroups": "Groups", + "loc.input.help.externalTestersGroups": "Optionally specify the group(s) of external testers this build should be distributed to. To specify multiple groups, separate group names by commas e.g. 'External Beta Testers,TestVendors'. If not specified the default 'External Testers' is used.", "loc.input.label.teamId": "Team ID", "loc.input.help.teamId": "The ID of your team if you are in multiple teams.", "loc.input.label.teamName": "Team Name", @@ -55,6 +57,8 @@ "loc.input.help.fastlaneToolsVersion": "Choose to install either the lastest version of fastlane or a specific version.", "loc.input.label.fastlaneToolsSpecificVersion": "fastlane Specific Version", "loc.input.help.fastlaneToolsSpecificVersion": "Provide the version of fastlane to install (e.g., 2.15.1). If a specific version of fastlane is installed, all previously installed versions will be uninstalled beforehand.", + "loc.input.label.fastlaneArguments": "Additional fastlane arguments", + "loc.input.help.fastlaneArguments": "Any additional arguments to pass to the fastlane command.", "loc.messages.DarwinOnly": "The Apple App Store Release task can only run on a Mac computer.", "loc.messages.SuccessfullyPublished": "Successfully published to %s", "loc.messages.NoIpaFilesFound": "No IPA file found using pattern: %s", diff --git a/Tasks/app-store-release/Tests/L0.ts b/Tasks/app-store-release/Tests/L0.ts index ae548ea..ac31572 100644 --- a/Tasks/app-store-release/Tests/L0.ts +++ b/Tasks/app-store-release/Tests/L0.ts @@ -312,6 +312,18 @@ describe('app-store-release L0 Suite', function () { done(); }); + it('testflight - distribute external with groups', (done:MochaDone) => { + this.timeout(1000); + + let tp = path.join(__dirname, 'L0TestFlightDistributeToExternalTestersWithGroups.js'); + let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); + + tr.run(); + assert(tr.invokedToolCount === 1, 'should have run fastlane pilot.'); + assert(tr.succeeded, 'task should have succeeded'); + done(); + }); + it('testflight - one ipa file', (done:MochaDone) => { this.timeout(1000); @@ -355,6 +367,21 @@ describe('app-store-release L0 Suite', function () { done(); }); + it('testflight - additional arguments', (done:MochaDone) => { + this.timeout(1000); + + let tp = path.join(__dirname, 'L0TestFlightFastlaneArguments.js'); + let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); + + tr.run(); + assert(tr.ran('fastlane pilot upload -u creds-username -i mypackage.ipa -args someadditioanlargs'), 'fastlane pilot upload with one ip file should have been run.'); + assert(tr.invokedToolCount === 3, 'should have run gem install, gem update and fastlane pilot.'); + assert(tr.stderr.length === 0, 'should not have written to stderr'); + assert(tr.succeeded, 'task should have succeeded'); + + done(); + }); + it('production - no bundle id', (done:MochaDone) => { this.timeout(1000); @@ -545,6 +572,20 @@ describe('app-store-release L0 Suite', function () { done(); }); + it('production - fastlane arguments', (done:MochaDone) => { + this.timeout(1000); + + let tp = path.join(__dirname, 'L0ProductionFastlaneArguments.js'); + let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); + + tr.run(); + assert(tr.invokedToolCount === 3, 'should have run gem install, gem update and fastlane deliver.'); + assert(tr.stderr.length === 0, 'should not have written to stderr'); + assert(tr.succeeded, 'task should have succeeded'); + + done(); + }); + //No tests for every combination of uploadMetadata and metadataPath (one true, one false) //No tests for every combination of uploadScreenshots and screenshotsPath (one true, one false) diff --git a/Tasks/app-store-release/Tests/L0ProductionFastlaneArguments.ts b/Tasks/app-store-release/Tests/L0ProductionFastlaneArguments.ts new file mode 100644 index 0000000..836a1f5 --- /dev/null +++ b/Tasks/app-store-release/Tests/L0ProductionFastlaneArguments.ts @@ -0,0 +1,72 @@ + /*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +'use strict'; + +import ma = require('vsts-task-lib/mock-answer'); +import tmrm = require('vsts-task-lib/mock-run'); +import path = require('path'); +import os = require('os'); + +let taskPath = path.join(__dirname, '..', 'app-store-release.js'); +let tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath); + +tmr.setInput('authType', 'UserAndPass'); +tmr.setInput('username', 'creds-username'); +tmr.setInput('password', 'creds-password'); +tmr.setInput('appIdentifier', 'com.microsoft.test.appId'); +tmr.setInput('releaseTrack', 'Production'); +tmr.setInput('installFastlane', 'true'); +tmr.setInput('fastlaneToolsVersion', 'LatestVersion'); +tmr.setInput('fastlaneArguments', '-args someadditioanlargs'); + +tmr.setInput('ipaPath', '**/*.ipa'); + +process.env['MOCK_NORMALIZE_SLASHES'] = true; +process.env['HOME'] = '/usr/bin'; +let gemCache: string = '/usr/bin/.gem-cache'; + +//construct a string that is JSON, call JSON.parse(string), send that to ma.TaskLibAnswers +let myAnswers: string = `{ + "which": { + "ruby": "/usr/bin/ruby", + "gem": "/usr/bin/gem", + "fastlane": "/usr/bin/fastlane" + }, + "checkPath" : { + "/usr/bin/ruby": true, + "/usr/bin/gem": true, + "/usr/bin/fastlane": true + }, + "glob": { + "**/*.ipa": [ + "mypackage.ipa" + ] + }, + "exec": { + "/usr/bin/gem install fastlane": { + "code": 0, + "stdout": "1 gem installed" + }, + "/usr/bin/gem update fastlane -i ${gemCache}": { + "code": 0, + "stdout": "1 gem installed" + }, + "fastlane deliver --force -u creds-username -a com.microsoft.test.appId -i mypackage.ipa --skip_metadata true --skip_screenshots true -args someadditioanlargs": { + "code": 0, + "stdout": "consider it delivered!" + } + } + }`; +let json: any = JSON.parse(myAnswers); +// Cast the json blob into a TaskLibAnswers +tmr.setAnswers(json); + +// This is how you can mock NPM packages... +os.platform = () => { + return 'darwin'; +}; +tmr.registerMock('os', os); + +tmr.run(); diff --git a/Tasks/app-store-release/Tests/L0TestFlightDistributeToExternalTestersWithGroups.ts b/Tasks/app-store-release/Tests/L0TestFlightDistributeToExternalTestersWithGroups.ts new file mode 100644 index 0000000..4800eaf --- /dev/null +++ b/Tasks/app-store-release/Tests/L0TestFlightDistributeToExternalTestersWithGroups.ts @@ -0,0 +1,89 @@ + /*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +'use strict'; + +import ma = require('vsts-task-lib/mock-answer'); +import tmrm = require('vsts-task-lib/mock-run'); +import path = require('path'); +import os = require('os'); +import fs = require('fs'); +let stats = require('fs').Stats; + +let taskPath = path.join(__dirname, '..', 'app-store-release.js'); +let tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath); + +tmr.setInput('authType', 'UserAndPass'); +tmr.setInput('username', 'creds-username'); +tmr.setInput('password', 'creds-password'); +tmr.setInput('releaseTrack', 'TestFlight'); +tmr.setInput('ipaPath', 'mypackage.ipa'); +tmr.setInput('appIdentifier', 'com.microsoft.test.appId'); +tmr.setInput('distributedToExternalTesters', 'true'); +tmr.setInput('releaseNotes', '/usr/build/releasenotes'); +tmr.setInput('externalTestersGroups', 'Group1,Group 2'); + +process.env['MOCK_NORMALIZE_SLASHES'] = true; +process.env['HOME'] = '/usr/bin'; +let gemCache: string = '/usr/bin/.gem-cache'; + +tmr.registerMock('fs', { + statSync: () => { + let stat = new stats; + stat.isFile = () => { + return true; + }; + return stat; + }, + readFileSync: () => { + return Buffer.from('Release notes for beta release.'); + }, + writeFileSync: fs.writeFileSync +}); + +//construct a string that is JSON, call JSON.parse(string), send that to ma.TaskLibAnswers +let myAnswers: string = `{ + "which": { + "ruby": "/usr/bin/ruby", + "gem": "/usr/bin/gem", + "fastlane": "/usr/bin/fastlane", + "pilot": "/usr/bin/pilot" + }, + "checkPath" : { + "/usr/bin/ruby": true, + "/usr/bin/gem": true, + "/usr/bin/fastlane": true, + "/usr/bin/pilot": true + }, + "glob": { + "mypackage.ipa": [ + "mypackage.ipa" + ] + }, + "exec": { + "/usr/bin/gem install fastlane": { + "code": 0, + "stdout": "1 gem installed" + }, + "/usr/bin/gem update fastlane -i ${gemCache}": { + "code": 0, + "stdout": "1 gem installed" + }, + "fastlane pilot upload -u creds-username -i mypackage.ipa --changelog Release notes for beta release. -a com.microsoft.test.appId --distribute_external true --groups Group1,Group 2": { + "code": 0, + "stdout": "consider it uploaded!" + } + } + }`; +let json: any = JSON.parse(myAnswers); +// Cast the json blob into a TaskLibAnswers +tmr.setAnswers(json); + +// This is how you can mock NPM packages... +os.platform = () => { + return 'darwin'; +}; +tmr.registerMock('os', os); + +tmr.run(); diff --git a/Tasks/app-store-release/Tests/L0TestFlightFastlaneArguments.ts b/Tasks/app-store-release/Tests/L0TestFlightFastlaneArguments.ts new file mode 100644 index 0000000..41056ae --- /dev/null +++ b/Tasks/app-store-release/Tests/L0TestFlightFastlaneArguments.ts @@ -0,0 +1,72 @@ + /*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +'use strict'; + +import ma = require('vsts-task-lib/mock-answer'); +import tmrm = require('vsts-task-lib/mock-run'); +import path = require('path'); +import os = require('os'); + +let taskPath = path.join(__dirname, '..', 'app-store-release.js'); +let tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath); + +tmr.setInput('authType', 'UserAndPass'); +tmr.setInput('username', 'creds-username'); +tmr.setInput('password', 'creds-password'); +tmr.setInput('releaseTrack', 'TestFlight'); +tmr.setInput('installFastlane', 'true'); +tmr.setInput('fastlaneToolsVersion', 'LatestVersion'); +tmr.setInput('fastlaneArguments', '-args someadditioanlargs'); + +// let ipaPath: string = tl.getInput('ipaPath', true); +tmr.setInput('ipaPath', '**/*.ipa'); + +process.env['MOCK_NORMALIZE_SLASHES'] = true; +process.env['HOME'] = '/usr/bin'; +let gemCache: string = '/usr/bin/.gem-cache'; + +//construct a string that is JSON, call JSON.parse(string), send that to ma.TaskLibAnswers +let myAnswers: string = `{ + "which": { + "ruby": "/usr/bin/ruby", + "gem": "/usr/bin/gem", + "fastlane": "/usr/bin/fastlane" + }, + "checkPath" : { + "/usr/bin/ruby": true, + "/usr/bin/gem": true, + "/usr/bin/fastlane": true + }, + "glob": { + "**/*.ipa": [ + "mypackage.ipa" + ] + }, + "exec": { + "/usr/bin/gem install fastlane": { + "code": 0, + "stdout": "1 gem installed" + }, + "/usr/bin/gem update fastlane -i ${gemCache}": { + "code": 0, + "stdout": "1 gem installed" + }, + "fastlane pilot upload -u creds-username -i mypackage.ipa -args someadditioanlargs": { + "code": 0, + "stdout": "consider it uploaded!" + } + } + }`; +let json: any = JSON.parse(myAnswers); +// Cast the json blob into a TaskLibAnswers +tmr.setAnswers(json); + +// This is how you can mock NPM packages... +os.platform = () => { + return 'darwin'; +}; +tmr.registerMock('os', os); + +tmr.run(); diff --git a/Tasks/app-store-release/app-store-release.ts b/Tasks/app-store-release/app-store-release.ts index 4b96cef..0d4c299 100644 --- a/Tasks/app-store-release/app-store-release.ts +++ b/Tasks/app-store-release/app-store-release.ts @@ -165,6 +165,8 @@ async function run() { tl.debug('Skipped fastlane installation.'); } + let fastlaneArguments: string = tl.getInput('fastlaneArguments'); + //gem update fastlane -i ~/.gem-cache if (releaseTrack === 'TestFlight') { // Run pilot (via fastlane) to upload to testflight @@ -191,7 +193,11 @@ async function run() { if (shouldSkipSubmission || shouldSkipWaitingForProcessing) { tl.warning(tl.loc('ExternalTestersCannotSkipWarning')); } + + let externalTestersGroups: string = tl.getInput('externalTestersGroups'); + pilotCommand.argIf(externalTestersGroups, ['--groups', externalTestersGroups]); } + pilotCommand.argIf(fastlaneArguments, fastlaneArguments); await pilotCommand.exec(); } else if (releaseTrack === 'Production') { let bundleIdentifier: string = tl.getInput('appIdentifier', true); @@ -216,6 +222,7 @@ async function run() { deliverCommand.argIf(teamName, ['-e', teamName]); deliverCommand.argIf(shouldSubmitForReview, ['--submit_for_review', 'true']); deliverCommand.argIf(shouldAutoRelease, ['--automatic_release', 'true']); + deliverCommand.argIf(fastlaneArguments, fastlaneArguments); await deliverCommand.exec(); } diff --git a/Tasks/app-store-release/task.json b/Tasks/app-store-release/task.json index 91e6810..eaf936f 100644 --- a/Tasks/app-store-release/task.json +++ b/Tasks/app-store-release/task.json @@ -13,7 +13,7 @@ "demands": [ "xcode" ], "version": { "Major": "1", - "Minor": "116", + "Minor": "126", "Patch": "0" }, "minimumAgentVersion": "1.95.3", @@ -236,6 +236,16 @@ "groupName": "releaseOptions", "visibleRule": "releaseTrack = TestFlight" }, + { + "name": "externalTestersGroups", + "type": "string", + "label": "Groups", + "required": false, + "defaultValue": "", + "helpMarkDown": "Optionally specify the group(s) of external testers this build should be distributed to. To specify multiple groups, separate group names by commas e.g. 'External Beta Testers,TestVendors'. If not specified the default 'External Testers' is used.", + "groupName": "releaseOptions", + "visibleRule": "distributedToExternalTesters = true" + }, { "name": "teamId", "type": "string", @@ -283,6 +293,15 @@ "groupName": "advanced", "helpMarkDown": "Provide the version of fastlane to install (e.g., 2.15.1). If a specific version of fastlane is installed, all previously installed versions will be uninstalled beforehand.", "visibleRule": "fastlaneToolsVersion = SpecificVersion" + }, + { + "name": "fastlaneArguments", + "type": "string", + "label": "Additional fastlane arguments", + "defaultValue": "", + "required": false, + "groupName": "advanced", + "helpMarkDown": "Any additional arguments to pass to the fastlane command." } ], "execution": { diff --git a/Tasks/app-store-release/task.loc.json b/Tasks/app-store-release/task.loc.json index 828a0f0..b05cc50 100644 --- a/Tasks/app-store-release/task.loc.json +++ b/Tasks/app-store-release/task.loc.json @@ -15,7 +15,7 @@ ], "version": { "Major": "1", - "Minor": "116", + "Minor": "126", "Patch": "0" }, "minimumAgentVersion": "1.95.3", @@ -238,6 +238,16 @@ "groupName": "releaseOptions", "visibleRule": "releaseTrack = TestFlight" }, + { + "name": "externalTestersGroups", + "type": "string", + "label": "ms-resource:loc.input.label.externalTestersGroups", + "required": false, + "defaultValue": "", + "helpMarkDown": "ms-resource:loc.input.help.externalTestersGroups", + "groupName": "releaseOptions", + "visibleRule": "distributedToExternalTesters = true" + }, { "name": "teamId", "type": "string", @@ -285,6 +295,15 @@ "groupName": "advanced", "helpMarkDown": "ms-resource:loc.input.help.fastlaneToolsSpecificVersion", "visibleRule": "fastlaneToolsVersion = SpecificVersion" + }, + { + "name": "fastlaneArguments", + "type": "string", + "label": "ms-resource:loc.input.label.fastlaneArguments", + "defaultValue": "", + "required": false, + "groupName": "advanced", + "helpMarkDown": "ms-resource:loc.input.help.fastlaneArguments" } ], "execution": { diff --git a/app-store-vsts-extension.json b/app-store-vsts-extension.json index c2931e6..27f367e 100644 --- a/app-store-vsts-extension.json +++ b/app-store-vsts-extension.json @@ -2,7 +2,7 @@ "manifestVersion": 1, "id": "app-store", "name": "Apple App Store", - "version": "1.116.0", + "version": "1.126.0", "publisher": "ms-vsclient", "description": "Provides tasks for publishing to Apple's App Store from a TFS/Team Services build or release definition", "categories": [