diff --git a/.github/workflows/cross-browser-test.yml b/.github/workflows/cross-browser-test.yml index 3f01ec436d5..8f9eb6a9db3 100644 --- a/.github/workflows/cross-browser-test.yml +++ b/.github/workflows/cross-browser-test.yml @@ -1,11 +1,17 @@ name: Cross-Browser Test Flow -on: push +on: + pull_request: + branches: + - master + types: + - closed jobs: cross-browser-test: name: Cross-Browser (Saucelabs) Tests runs-on: ubuntu-latest + if: github.event.pull_request.merged env: SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }} SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }} diff --git a/.github/workflows/node-chrome-test.yml b/.github/workflows/test-all.yml similarity index 84% rename from .github/workflows/node-chrome-test.yml rename to .github/workflows/test-all.yml index a7832c1c2ff..50c654444cc 100644 --- a/.github/workflows/node-chrome-test.yml +++ b/.github/workflows/test-all.yml @@ -1,6 +1,13 @@ -name: Main Test Flow +name: Run All Tests -on: [push, pull_request] +on: + pull_request: + branches: + - master + types: + - closed + schedule: + - cron: '0 6,18 * * *' jobs: test: diff --git a/.github/workflows/test-changed.yml b/.github/workflows/test-changed.yml new file mode 100644 index 00000000000..94458506548 --- /dev/null +++ b/.github/workflows/test-changed.yml @@ -0,0 +1,23 @@ +name: Push/PR + +on: [push, pull_request] + +jobs: + test: + name: Test Packages With Changed Files + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + - name: Set up Node (10) + uses: actions/setup-node@v1 + with: + node-version: 10.x + - name: Test setup and yarn install + run: | + cp config/ci.config.json config/project.json + yarn + - name: yarn build + run: yarn build + - name: Run tests on changed packages + run: xvfb-run yarn test:changed diff --git a/package.json b/package.json index 549201e9f83..3c6f9ca4cd6 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "pretest:coverage": "mkdirp coverage", "ci:coverage": "lcov-result-merger 'packages/**/lcov.info' 'lcov-all.info'", "test:coverage": "lcov-result-merger 'packages/**/lcov.info' | coveralls", + "test:changed": "node scripts/run_changed.js", "test:setup": "node tools/config.js", "test:saucelabs": "node scripts/run_saucelabs.js", "test:saucelabs:single": "karma start config/karma.saucelabs.js --single-run", diff --git a/scripts/run_changed.js b/scripts/run_changed.js new file mode 100644 index 00000000000..19233cec97d --- /dev/null +++ b/scripts/run_changed.js @@ -0,0 +1,89 @@ +/** + * @license + * Copyright 2020 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const { resolve } = require('path'); +const { spawn } = require('child-process-promise'); +const simpleGit = require('simple-git/promise'); +const root = resolve(__dirname, '..'); +const git = simpleGit(root); + +/** + * Runs tests on packages changed (in comparison to origin/master...HEAD) + */ + +async function runTestsOnChangedPackages() { + const diff = await git.diff(['--name-only', 'origin/master...HEAD']); + const changedFiles = diff.split('\n'); + const changedPackages = {}; + for (const filename of changedFiles) { + const match = filename.match('^(packages/[a-zA-Z0-9-]+)/.*'); + if (match && match[1]) { + const pkg = require(resolve(root, match[1], 'package.json')); + if (pkg && pkg.scripts.test) { + changedPackages[match[1]] = true; + } + } + } + if (changedPackages.size > 0) { + await runTests(Object.keys(changedPackages)); + } else { + console.log( + 'No changes detected in any package. Skipping all package-specific tests.' + ); + } +} + +/** + * Runs `yarn test` in all dirs in pathList. + * @param {Array} pathList + */ +async function runTests(pathList) { + if (!pathList) return; + for (const testPath of pathList) { + try { + await spawn('yarn', ['--cwd', testPath, 'test'], { + stdio: 'inherit' + }); + } catch (e) { + throw new Error(`Error running tests in ${testPath}.`); + } + } +} + +/** + * These are short, always run them. + */ +async function runIntegrationTests() { + await runTests([ + 'integration/browserify', + 'integration/firebase-typings', + 'integration/typescript', + 'integration/webpack' + ]); +} + +async function main() { + try { + await runIntegrationTests(); + await runTestsOnChangedPackages(); + } catch (e) { + console.error(e); + process.exit(1); + } +} + +main(); diff --git a/tools/gitHooks/license.js b/tools/gitHooks/license.js index 4bc64e01983..8f2c0fcdc44 100644 --- a/tools/gitHooks/license.js +++ b/tools/gitHooks/license.js @@ -11,7 +11,7 @@ const root = resolve(__dirname, '../..'); const git = simpleGit(root); const licenseHeader = `/** * @license - * Copyright 2019 Google Inc. + * Copyright 2020 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.