Skip to content

Commit

Permalink
[FIX] improve tarball insertion (#6808)
Browse files Browse the repository at this point in the history
* improve packaging

* add log to figure out CI and update ilios

* make extra sure we aren't trolling ourselves

* cleanup

* improve read-file
  • Loading branch information
runspired authored Nov 26, 2019
1 parent de8f4ff commit 72dd585
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 36 deletions.
12 changes: 9 additions & 3 deletions bin/-tarball-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}
Expand All @@ -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 = {
Expand Down
84 changes: 52 additions & 32 deletions bin/test-external-partner-project.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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}`);
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down

0 comments on commit 72dd585

Please sign in to comment.