diff --git a/bin/-tarball-info.js b/bin/-tarball-info.js index bfd14c2e0f4..776f5351eec 100644 --- a/bin/-tarball-info.js +++ b/bin/-tarball-info.js @@ -166,7 +166,13 @@ function generatePackageReference(version, tarballName) { } function insertTarballsToPackageJson(fileLocation, options = {}) { - const pkgInfo = require(fileLocation); + // in some flows we have the potential to have previously written + // to the package.json already prior to calling this method. + // reading it in this way this ensures we get the latest and not + // a stale module from require + const location = require.resolve(fileLocation); + const pkgInfo = JSON.parse(fs.readFileSync(location, 'utf8')); + if (options.isRelativeTarball) { pkgInfo.version = `${pkgInfo.version}-sha.${CurrentSha}`; } @@ -182,11 +188,11 @@ function insertTarballsToPackageJson(fileLocation, options = {}) { if (!options.isRelativeTarball) { const resolutions = (pkgInfo.resolutions = pkgInfo.resolutions || {}); - resolutions[packageName] = pkg.tarballLocation; + resolutions[packageName] = pkg.reference; } }); - fs.writeFileSync(fileLocation, JSON.stringify(pkgInfo, null, 2)); + fs.writeFileSync(location, JSON.stringify(pkgInfo, null, 2)); } module.exports = { diff --git a/bin/test-external-partner-project.js b/bin/test-external-partner-project.js index e7debce767e..51317cd4d59 100755 --- a/bin/test-external-partner-project.js +++ b/bin/test-external-partner-project.js @@ -9,15 +9,26 @@ const execa = require('execa'); const debug = require('debug')('test-external'); const rimraf = require('rimraf'); const chalk = require('chalk'); - +const cliArgs = require('command-line-args'); const projectRoot = path.resolve(__dirname, '../'); -const externalProjectName = process.argv[2]; -const gitUrl = process.argv[3]; -const skipSmokeTest = - (process.argv[4] && process.argv[4] === '--skip-smoke-test') || - (process.argv[5] && process.argv[5] === '--skip-smoke-test'); -const skipClone = - (process.argv[4] && process.argv[4] === '--skip-clone') || (process.argv[5] && process.argv[5] === '--skip-clone'); + +let cliOptionsDef = [{ name: 'projectName', defaultOption: true }]; +let cliOptions = cliArgs(cliOptionsDef, { stopAtFirstUnknown: true }); +const externalProjectName = cliOptions.projectName; +let argv = cliOptions._unknown || []; +cliOptionsDef = [{ name: 'gitUrl', defaultOption: true }]; +cliOptions = cliArgs(cliOptionsDef, { stopAtFirstUnknown: true, argv }); +const gitUrl = cliOptions.gitUrl; +argv = cliOptions._unknown || []; +cliOptionsDef = [ + { name: 'skipSmokeTest', type: Boolean, defaultValue: false }, + { name: 'skipClone', type: Boolean, defaultValue: false }, + { name: 'skipTest', type: Boolean, defaultValue: false }, +]; +cliOptions = cliArgs(cliOptionsDef, { argv }); + +const { skipSmokeTest, skipClone, skipTest } = cliOptions; + // we share this for the build const cachePath = '../__external-test-cache'; const tempDir = path.join(projectRoot, cachePath); @@ -109,34 +120,43 @@ try { try { debug('Preparing Package To Run Tests Against Commit'); insertTarballsToPackageJson(packageJsonLocation); - // we must use npm because yarn fails to install - // the nested tarballs correctly (just as it fails to pack them correctly) - // we rimraf node_modules first because it was previously - // installed using yarn's resolution algorithm - if (!skipSmokeTest) { - execExternal(`rm -rf node_modules`); - } - execExternal(`npm install`); + + // clear node_modules installed for the smoke-test + execExternal(`rm -rf node_modules`); + // we are forced to use yarn so that our resolutions will be respected + // in addition to the version file link we insert otherwise nested deps + // may bring their own ember-data + // + // For this reason we don't trust the lock file + // we also can't trust the cache + execExternal(`yarn install --no-lockfile --cache-folder=tmp/yarn-cache`); } catch (e) { - debug(e); - throw new Error(`Unable to npm install tarballs for ember-data\` for ${externalProjectName}`); + console.log(`Unable to npm install tarballs for ember-data\` for ${externalProjectName}. Original error below:`); + + throw e; } -try { - debug('Running tests against EmberData commit'); - execExternal(`ember test`, true); -} catch (e) { - commitTestPassed = false; +if (!skipTest) { + try { + debug('Running tests against EmberData commit'); + execExternal(`ember test`, true); + } catch (e) { + commitTestPassed = false; + } } -if (skipSmokeTest && !commitTestPassed) { - throw new Error('Commit may result in a regression, but the smoke test was skipped.'); -} else if (!smokeTestPassed && !commitTestPassed) { - throw new Error(`Commit may result in a regression, but the smoke test for ${externalProjectName} also failed.`); -} else if (smokeTestPassed && !commitTestPassed) { - throw new Error(`Commit results in a regression in ${externalProjectName}`); -} else if (!smokeTestPassed) { - console.log(`Commit may resolve issues present in the smoke test for ${externalProjectName}`); +if (skipTest) { + console.log(`Skipped Tests: Commit viability unknown`); } else { - console.log(`Commit does not regress ${externalProjectName}`); + if (skipSmokeTest && !commitTestPassed) { + throw new Error('Commit may result in a regression, but the smoke test was skipped.'); + } else if (!smokeTestPassed && !commitTestPassed) { + throw new Error(`Commit may result in a regression, but the smoke test for ${externalProjectName} also failed.`); + } else if (smokeTestPassed && !commitTestPassed) { + throw new Error(`Commit results in a regression in ${externalProjectName}`); + } else if (!smokeTestPassed) { + console.log(`Commit may resolve issues present in the smoke test for ${externalProjectName}`); + } else { + console.log(`Commit does not regress ${externalProjectName}`); + } } diff --git a/package.json b/package.json index 74ccdb99d40..dae04d90f9e 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "test-external:travis-web": "./bin/test-external-partner-project.js travis-web https://github.com/travis-ci/travis-web.git", "test-external:storefront": "./bin/test-external-partner-project.js storefront https://github.com/embermap/ember-data-storefront.git", "test-external:factory-guy": "./bin/test-external-partner-project.js factory-guy https://github.com/danielspaniel/ember-data-factory-guy.git", - "test-external:ilios-frontend": "./bin/test-external-partner-project.js ilios-frontend https://github.com/ilios/frontend.git --skip-smoke-test", + "test-external:ilios-frontend": "./bin/test-external-partner-project.js ilios-frontend https://github.com/ilios/frontend.git --skipSmokeTest", "test-external:ember-resource-metadata": "./bin/test-external-partner-project.js ember-resource-metadata https://github.com/ef4/ember-resource-metadata.git", "test-external:ember-data-relationship-tracker": "./bin/test-external-partner-project.js ember-data-relationship-tracker https://github.com/ef4/ember-data-relationship-tracker.git" },