Skip to content
This repository has been archived by the owner on Aug 14, 2020. It is now read-only.

Commit

Permalink
Add support for Code Path to SPM projects
Browse files Browse the repository at this point in the history
Clean also scope temporary folder
  • Loading branch information
Ignacio Bonafonte committed Dec 18, 2019
1 parent b2264e2 commit 2dab0c0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 28 deletions.
30 changes: 16 additions & 14 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '\"';
Expand All @@ -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);
}
}

Expand All @@ -179,6 +179,7 @@ async function run() {
if (testError) {
core.setFailed(testError.message);
}

} catch (error) {
core.setFailed(error.message);
}
Expand Down Expand Up @@ -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
})
Expand Down
30 changes: 16 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '\"';
Expand All @@ -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);
}
}

Expand All @@ -131,6 +131,7 @@ async function run() {
if (testError) {
core.setFailed(testError.message);
}

} catch (error) {
core.setFailed(error.message);
}
Expand Down Expand Up @@ -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
})
Expand Down

0 comments on commit 2dab0c0

Please sign in to comment.