From 2dab0c03dd93709c29dc776588c472b4b1d00f5b Mon Sep 17 00:00:00 2001 From: Ignacio Bonafonte Date: Wed, 18 Dec 2019 18:09:12 +0100 Subject: [PATCH] Add support for Code Path to SPM projects Clean also scope temporary folder --- dist/index.js | 30 ++++++++++++++++-------------- index.js | 30 ++++++++++++++++-------------- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/dist/index.js b/dist/index.js index 8735aa4..166e6ca 100644 --- a/dist/index.js +++ b/dist/index.js @@ -131,19 +131,19 @@ async function run() { const testTargets = JSON.parse(jsonString); for( const target of Object.keys(testTargets) ) { - if( target.charAt(0) !== '_' ) { - if( target['TestingEnvironmentVariables']) { - await insertEnvVariables(testRun, target, dsn) - } else if ( target === 'TestConfigurations') { - let configurationNumber = 0; - for( const configuration of testTargets['TestConfigurations'] ) { - let testNumber = 0; - for( const test of configuration['TestTargets'] ) { - await insertEnvVariables(testRun, target + '.' + configurationNumber + '.' + 'TestTargets' + '.' + testNumber, dsn) - } - } - } + if( target.charAt(0) !== '_' ) { + if( testTargets[target].TestingEnvironmentVariables ) { + await insertEnvVariables(testRun, target, dsn) + } else if ( target === 'TestConfigurations') { + let configurationNumber = 0; + for (const configuration of testTargets['TestConfigurations']) { + let testNumber = 0; + for (const test of configuration['TestTargets']) { + await insertEnvVariables(testRun, target + '.' + configurationNumber + '.' + 'TestTargets' + '.' + testNumber, dsn) + } + } } + } } //run tests let testCommand = 'xcodebuild test-without-building -enableCodeCoverage YES -xctestrun ' + testRun + ' -destination \"' + destination + '\"'; @@ -168,7 +168,7 @@ async function run() { const settingsArray = JSON.parse(auxOutput); for( const settings of settingsArray ) { if (settings.buildSettings['PACKAGE_TYPE'] !== 'com.apple.package-type.bundle.unit-test') { - await runScopeCoverageWithSettings(settings.buildSettings, dsn); + await runScopeCoverageWithSettings(settings.buildSettings, dsn, isSPM); } } @@ -179,6 +179,7 @@ async function run() { if (testError) { core.setFailed(testError.message); } + } catch (error) { core.setFailed(error.message); } @@ -344,13 +345,14 @@ async function getXCTestRuns() { return testRuns } -async function runScopeCoverageWithSettings(buildSettings, dsn) { +async function runScopeCoverageWithSettings(buildSettings, dsn, isSPM) { let runScriptCommand = 'sh -c ' + scopeDir + '/scopeAgent/ScopeAgent.framework/scope-coverage'; await exec.exec(runScriptCommand, null, { env: { ...buildSettings, SCOPE_DSN: dsn, TMPDIR: os.tmpdir() + '/', + PRODUCT_BUNDLE_IDENTIFIER: isSPM ? '' : buildSettings.PRODUCT_BUNDLE_IDENTIFIER }, ignoreReturnCode: true }) diff --git a/index.js b/index.js index 11cb16d..a0236e7 100644 --- a/index.js +++ b/index.js @@ -83,19 +83,19 @@ async function run() { const testTargets = JSON.parse(jsonString); for( const target of Object.keys(testTargets) ) { - if( target.charAt(0) !== '_' ) { - if( target['TestingEnvironmentVariables']) { - await insertEnvVariables(testRun, target, dsn) - } else if ( target === 'TestConfigurations') { - let configurationNumber = 0; - for( const configuration of testTargets['TestConfigurations'] ) { - let testNumber = 0; - for( const test of configuration['TestTargets'] ) { - await insertEnvVariables(testRun, target + '.' + configurationNumber + '.' + 'TestTargets' + '.' + testNumber, dsn) - } - } - } + if( target.charAt(0) !== '_' ) { + if( testTargets[target].TestingEnvironmentVariables ) { + await insertEnvVariables(testRun, target, dsn) + } else if ( target === 'TestConfigurations') { + let configurationNumber = 0; + for (const configuration of testTargets['TestConfigurations']) { + let testNumber = 0; + for (const test of configuration['TestTargets']) { + await insertEnvVariables(testRun, target + '.' + configurationNumber + '.' + 'TestTargets' + '.' + testNumber, dsn) + } + } } + } } //run tests let testCommand = 'xcodebuild test-without-building -enableCodeCoverage YES -xctestrun ' + testRun + ' -destination \"' + destination + '\"'; @@ -120,7 +120,7 @@ async function run() { const settingsArray = JSON.parse(auxOutput); for( const settings of settingsArray ) { if (settings.buildSettings['PACKAGE_TYPE'] !== 'com.apple.package-type.bundle.unit-test') { - await runScopeCoverageWithSettings(settings.buildSettings, dsn); + await runScopeCoverageWithSettings(settings.buildSettings, dsn, isSPM); } } @@ -131,6 +131,7 @@ async function run() { if (testError) { core.setFailed(testError.message); } + } catch (error) { core.setFailed(error.message); } @@ -296,13 +297,14 @@ async function getXCTestRuns() { return testRuns } -async function runScopeCoverageWithSettings(buildSettings, dsn) { +async function runScopeCoverageWithSettings(buildSettings, dsn, isSPM) { let runScriptCommand = 'sh -c ' + scopeDir + '/scopeAgent/ScopeAgent.framework/scope-coverage'; await exec.exec(runScriptCommand, null, { env: { ...buildSettings, SCOPE_DSN: dsn, TMPDIR: os.tmpdir() + '/', + PRODUCT_BUNDLE_IDENTIFIER: isSPM ? '' : buildSettings.PRODUCT_BUNDLE_IDENTIFIER }, ignoreReturnCode: true })