Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ci]: @ember/test-helpers partner test #19728

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,36 @@ jobs:
- name: test
run: yarn ember test -c testem.ci-browsers.js

external-partners:
needs: [basic-test, lint, browserstack-test, production-test, production-debug-render-test, extend-prototypes-test, node-test, blueprint-test, browser-test]
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
partner:
[
ember-test-helpers,
ember-legacy-built-in-components,
]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 12.x
cache: yarn
- name: Install dependencies
run: yarn install --frozen-lockfile --non-interactive
- uses: actions/[email protected]
with:
name: dist
path: dist
- name: Run Tests
run: yarn test-external:${{ matrix.partner }}

deploy-tag:
name: Deploy tags to npm
runs-on: ubuntu-latest
needs: [basic-test, lint, browserstack-test, production-test, production-debug-render-test, extend-prototypes-test, node-test, blueprint-test, browser-test]
needs: [basic-test, lint, browserstack-test, production-test, production-debug-render-test, extend-prototypes-test, node-test, blueprint-test, browser-test, external-partners]
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v2
Expand All @@ -234,7 +260,7 @@ jobs:
publish:
name: Publish channel to s3
runs-on: ubuntu-latest
needs: [basic-test, lint, browserstack-test, production-test, production-debug-render-test, extend-prototypes-test, node-test, blueprint-test, browser-test]
needs: [basic-test, lint, browserstack-test, production-test, production-debug-render-test, extend-prototypes-test, node-test, blueprint-test, browser-test, external-partners]
# Only run on pushes to branches that are not from the cron workflow
if: github.event_name == 'push' && contains(github.ref, 'cron') != true
steps:
Expand All @@ -257,7 +283,7 @@ jobs:
publish-alpha:
name: Publish alpha from default branch
runs-on: ubuntu-latest
needs: [basic-test, lint, browserstack-test, production-test, production-debug-render-test, extend-prototypes-test, node-test, blueprint-test, browser-test]
needs: [basic-test, lint, browserstack-test, production-test, production-debug-render-test, extend-prototypes-test, node-test, blueprint-test, browser-test, external-partners]
# Only run on pushes to master
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
Expand Down
165 changes: 165 additions & 0 deletions bin/test-external-partner-project.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
'use strict';

const fs = require('fs');
const path = require('path');

const execa = require('execa');
/* eslint-disable-next-line node/no-extraneous-require */
const debug = require('debug')('test-external');
const rimraf = require('rimraf');
const chalk = require('chalk');
const cliArgs = require('command-line-args');
const root = path.resolve(__dirname, '../');

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;

const cachePath = '../__emberjs-test-cache';
const tempDir = path.join(root, cachePath);
const projectTempDir = path.join(tempDir, externalProjectName);

console.log(
`Preparing to test external project ${externalProjectName} located at ${gitUrl} against this ember.js commit.`
);

function execWithLog(command, force) {
debug(chalk.cyan('Executing: ') + chalk.yellow(command));

if (force) {
return execa.sync(command, { stdio: [0, 1, 2], shell: true });
}

return execa.sync(command, { shell: true }).stdout;
}

function execCommand(command, force) {
command = `cd ${projectTempDir} && ${command}`;
return execWithLog(command, force);
}

if (!fs.existsSync(tempDir)) {
debug(`Ensuring Cache Root at: ${tempDir}`);
fs.mkdirSync(tempDir);
} else {
debug(`Cache Root Exists at: ${tempDir}`);
}

if (fs.existsSync(projectTempDir)) {
debug(`Cleaning Cache at: ${projectTempDir}`);
rimraf.sync(projectTempDir);
} else {
debug(`No cache present at: ${projectTempDir}`);
}

// install the project
try {
execWithLog(`git clone --depth=1 ${gitUrl} ${projectTempDir}`);
} catch (e) {
debug(e);
throw new Error(
`Install of ${gitUrl} in ${projectTempDir} for external project ${externalProjectName} testing failed.`
);
}

const useYarn = fs.existsSync(path.join(projectTempDir, 'yarn.lock'));
const packageJsonLocation = path.join(projectTempDir, 'package.json');

let smokeTestPassed = true;
let commitTestPassed = true;

/**
* -----------------
* SMOKE TESTS FIRST
* -----------------
*/
try {
debug('Running Smoke Test');
try {
execCommand(`${useYarn ? 'yarn install' : 'npm install'}`);
} catch (e) {
debug(e);
throw new Error(`Unable to complete install of dependencies for ${externalProjectName}`);
}
execCommand('./node_modules/.bin/ember test', true);
} catch (e) {
console.log(e);
smokeTestPassed = false;
}

/**
* -----------------
* INSTALL latest ember.js in external package
* -----------------
*/
const currentSha = execWithLog(`git rev-parse HEAD`);
const cacheDir = path.join(root, `../__tarball-cache`);
const tarballDir = path.join(cacheDir, currentSha);

if (!fs.existsSync(cacheDir)) {
debug(`Ensuring Cache Root at: ${cacheDir}`);
fs.mkdirSync(cacheDir);
} else {
debug(`Cache Root Exists at: ${cacheDir}`);
}

if (!fs.existsSync(tarballDir)) {
debug(`Ensuring Tarball Cache for SHA ${currentSha} at: ${tarballDir}`);
fs.mkdirSync(tarballDir);
} else {
debug(`Tarball Cache Exists for SHA ${currentSha} at: ${tarballDir}`);
}

function generateTarball() {
execWithLog(`cd ${tarballDir}; yarn build ${root}; npm pack ${root};`);

debug(`npm pack successful at: ${tarballDir}`);
const pkgPath = path.join(root, 'package.json');
const pkg = require(pkgPath);

return path.join(tarballDir, `${pkg.name}-${pkg.version}.tgz`);
}

function insertTarballsToPackageJson(fileLocation) {
const location = require.resolve(fileLocation);
const pkgInfo = JSON.parse(fs.readFileSync(location, 'utf8'));

const thisPkgTarballPath = generateTarball();
pkgInfo.devDependencies['ember-source'] = thisPkgTarballPath;

fs.writeFileSync(location, JSON.stringify(pkgInfo, null, 2));
}

try {
debug('Preparing Package To Run Tests Against Latest ember.js Commit');
insertTarballsToPackageJson(packageJsonLocation);

// clear node_modules installed for the smoke-test
execCommand(`rm -rf node_modules`);

execCommand(`${useYarn ? 'yarn install' : 'npm install'}`);
} catch (e) {
console.log(`Unable to npm install tarballs for ${externalProjectName}. Original error below:`);

throw e;
}

try {
debug('Running tests against ember.js commit');
execCommand('./node_modules/.bin/ember build', true);
execCommand('./node_modules/.bin/ember test --path="./dist"', true);
} catch (e) {
console.error(e);
commitTestPassed = false;
}

if (commitTestPassed && smokeTestPassed) {
console.log(`${externalProjectName} tests passed`);
} else {
throw new Error(`Tests failed. smoke: ${smokeTestPassed}, commit: ${commitTestPassed}`);
}
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@
"test": "node bin/run-tests.js",
"test:blueprints": "mocha node-tests/blueprints/**/*-test.js",
"test:node": "qunit tests/node/**/*-test.js",
"test:browserstack": "node bin/run-browserstack-tests.js"
"test:browserstack": "node bin/run-browserstack-tests.js",
"test-external:ember-test-helpers": "node ./bin/test-external-partner-project.js ember-test-helpers https://github.com/emberjs/ember-test-helpers",
"test-external:ember-string": "node ./bin/test-external-partner-project.js ember-string https://github.com/emberjs/ember-string",
"test-external:ember-legacy-built-in-components": "node ./bin/test-external-partner-project.js ember-legacy-built-in-components https://github.com/emberjs/ember-legacy-built-in-components"
},
"dependencies": {
"@babel/helper-module-imports": "^7.16.7",
Expand Down Expand Up @@ -103,6 +106,7 @@
"broccoli-string-replace": "^0.1.2",
"broccoli-typescript-compiler": "^7.0.0",
"broccoli-uglify-sourcemap": "^4.0.0",
"command-line-args": "^5.2.0",
"common-tags": "^1.8.2",
"core-js": "^2.6.5",
"dag-map": "^2.0.2",
Expand Down Expand Up @@ -137,6 +141,7 @@
"prettier": "^2.1.2",
"puppeteer": "^3.0.4",
"qunit": "^2.14.0",
"rimraf": "^3.0.2",
"rollup-plugin-commonjs": "^9.3.4",
"rollup-plugin-node-resolve": "^4.2.4",
"route-recognizer": "^0.3.4",
Expand Down
32 changes: 32 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3212,6 +3212,11 @@ arr-union@^3.1.0:
resolved "https://registry.yarnpkg.com/arr-union/-/arr-union-3.1.0.tgz#e39b09aea9def866a8f206e288af63919bae39c4"
integrity "sha1-45sJrqne+Gao8gbiiK9jkZuuOcQ= sha512-sKpyeERZ02v1FeCZT8lrfJq5u6goHCtpTAzPwJYe7c8SPFOboNjNg1vz2L4VTn9T4PQxEx13TbXLmYUcS6Ug7Q=="

array-back@^3.0.1, array-back@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/array-back/-/array-back-3.1.0.tgz#b8859d7a508871c9a7b2cf42f99428f65e96bfb0"
integrity sha512-TkuxA4UCOvxuDK6NZYXCalszEzj+TLszyASooky+i742l9TqsOdYCMJJupxRic61hwquNtppB3hgcuq9SVSH1Q==

array-equal@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/array-equal/-/array-equal-1.0.0.tgz#8c2a5ef2472fd9ea742b04c77a75093ba2757c93"
Expand Down Expand Up @@ -4730,6 +4735,16 @@ combined-stream@~0.0.4:
dependencies:
delayed-stream "0.0.5"

command-line-args@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/command-line-args/-/command-line-args-5.2.0.tgz#087b02748272169741f1fd7c785b295df079b9be"
integrity sha512-4zqtU1hYsSJzcJBOcNZIbW5Fbk9BkjCp1pZVhQKoRaWL5J7N4XphDLwo8aWwdQpTugxwu+jf9u2ZhkXiqp5Z6A==
dependencies:
array-back "^3.1.0"
find-replace "^3.0.0"
lodash.camelcase "^4.3.0"
typical "^4.0.0"

[email protected]:
version "2.8.1"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.8.1.tgz#06be367febfda0c330aa1e2a072d3dc9762425d4"
Expand Down Expand Up @@ -6569,6 +6584,13 @@ find-index@^1.1.0:
resolved "https://registry.yarnpkg.com/find-index/-/find-index-1.1.0.tgz#53007c79cd30040d6816d79458e8837d5c5705ef"
integrity sha1-UwB8ec0wBA1oFteUWOiDfVxXBe8=

find-replace@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/find-replace/-/find-replace-3.0.0.tgz#3e7e23d3b05167a76f770c9fbd5258b0def68c38"
integrity sha512-6Tb2myMioCAgv5kfvP5/PkZZ/ntTpVK39fHY7WkWBgvbeE+VHd/tZuZ4mrC+bxh4cfOZeYKVPaJIZtZXV7GNCQ==
dependencies:
array-back "^3.0.1"

[email protected], find-up@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/find-up/-/find-up-3.0.0.tgz#49169f1d7993430646da61ecc5ae355c21c97b73"
Expand Down Expand Up @@ -8566,6 +8588,11 @@ lodash.bind@~2.3.0:
lodash._renative "~2.3.0"
lodash._slice "~2.3.0"

lodash.camelcase@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz#b28aa6288a2b9fc651035c7711f65ab6190331a6"
integrity sha1-soqmKIorn8ZRA1x3EfZathkDMaY=

lodash.castarray@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/lodash.castarray/-/lodash.castarray-4.4.0.tgz#c02513515e309daddd4c24c60cfddcf5976d9115"
Expand Down Expand Up @@ -11921,6 +11948,11 @@ typescript@~4.0.3:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.3.tgz#153bbd468ef07725c1df9c77e8b453f8d36abba5"
integrity "sha1-FTu9Ro7wdyXB35x36LRT+NNqu6U= sha512-tEu6DGxGgRJPb/mVPIZ48e69xCn2yRmCgYmDugAVwmJ6o+0u1RI18eO7E7WBTLYLaEVVOhwQmcdhQHweux/WPg=="

typical@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/typical/-/typical-4.0.0.tgz#cbeaff3b9d7ae1e2bbfaf5a4e6f11eccfde94fc4"
integrity sha512-VAH4IvQ7BDFYglMd7BPRDfLgxZZX4O4TFcRDA6EN5X7erNJJq+McIEp8np9aVtxrCJ6qx4GTYVfOWNjcqwZgRw==

uc.micro@^1.0.0, uc.micro@^1.0.1, uc.micro@^1.0.5:
version "1.0.6"
resolved "https://registry.yarnpkg.com/uc.micro/-/uc.micro-1.0.6.tgz#9c411a802a409a91fc6cf74081baba34b24499ac"
Expand Down