Skip to content

CI test workflow improvements #2576

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

Merged
merged 10 commits into from
Jan 29, 2020
Merged
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: 0 additions & 32 deletions .github/workflows/deploy-canary.yml

This file was deleted.

23 changes: 23 additions & 0 deletions .github/workflows/test-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,26 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./lcov-all.info
continue-on-error: true
deploy:
name: Canary Deploy
runs-on: ubuntu-latest
if: github.event.pull_request.merged
needs: test

steps:
- uses: actions/checkout@v1
- name: Set up Node (10)
uses: actions/setup-node@v1
with:
node-version: 10.x
registry-url: 'https://registry.npmjs.org'
- name: Yarn install
run: yarn
- name: yarn build
run: yarn build
- name: Deploy canary
run: |
npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
yarn release --canary
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Firebase Javascript SDK

<!-- BADGES -->
[![Build Status](https://travis-ci.org/firebase/firebase-js-sdk.svg?branch=master)](https://travis-ci.org/firebase/firebase-js-sdk)
![Build Status](https://img.shields.io/github/workflow/status/firebase/firebase-js-sdk/Run%20All%20Tests.svg)
[![Build Status](https://saucelabs.com/buildstatus/firebase-oss)](https://saucelabs.com/u/firebase-oss)
[![Version](https://img.shields.io/npm/v/firebase.svg?label=version)](https://www.npmjs.com/package/firebase)
[![Coverage Status](https://coveralls.io/repos/github/firebase/firebase-js-sdk/badge.svg?branch=master)](https://coveralls.io/github/firebase/firebase-js-sdk?branch=master)
Expand Down
75 changes: 57 additions & 18 deletions scripts/run_changed.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,55 @@

const { resolve } = require('path');
const { spawn } = require('child-process-promise');
const chalk = require('chalk');
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)
* Changes to these files warrant running all tests.
*/
const fullTestTriggerFiles = [
// Global dependency changes.
'package.json',
'yarn.lock',
// Test/compile/lint configs.
'config/karma.base.js',
'config/.eslintrc.js',
'config/mocha.browser.opts',
'config/mocha.node.opts',
'config/tsconfig.base.json',
'config/webpack.test.js',
'config/firestore.rules',
'config/database.rules.json'
];

/**
* Always run tests in these paths.
*/
const alwaysRunTestPaths = [
// These tests are very fast.
'integration/browserify',
'integration/firebase-typings',
'integration/typescript',
'integration/webpack'
];

async function runTestsOnChangedPackages() {
/**
* Identify modified packages that require tests.
*/
async function getChangedPackages() {
const diff = await git.diff(['--name-only', 'origin/master...HEAD']);
const changedFiles = diff.split('\n');
const changedPackages = {};
for (const filename of changedFiles) {
if (fullTestTriggerFiles.includes(filename)) {
console.log(
chalk`{blue Running all tests because ${filename} was modified.}`
);
return { testAll: true };
}
const match = filename.match('^(packages/[a-zA-Z0-9-]+)/.*');
if (match && match[1]) {
const pkg = require(resolve(root, match[1], 'package.json'));
Expand All @@ -39,11 +75,12 @@ async function runTestsOnChangedPackages() {
}
}
if (Object.keys(changedPackages).length > 0) {
await runTests(Object.keys(changedPackages));
return { testAll: false, packageDirs: Object.keys(changedPackages) };
} else {
console.log(
'No changes detected in any package. Skipping all package-specific tests.'
chalk`{green No changes detected in any package. Skipping all package-specific tests.}`
);
return { testAll: false, packageDirs: [] };
}
}

Expand All @@ -64,22 +101,24 @@ async function runTests(pathList) {
}
}

/**
* 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();
const { testAll, packageDirs = [] } = await getChangedPackages();
if (testAll) {
await spawn('yarn', ['test'], {
stdio: 'inherit'
});
} else {
console.log(chalk`{blue Running tests in:}`);
for (const filename of alwaysRunTestPaths) {
console.log(chalk`{green ${filename} (always runs)}`);
}
for (const filename of packageDirs) {
console.log(chalk`{yellow ${filename} (contains modified files)}`);
}
await runTests(alwaysRunTestPaths);
await runTests(packageDirs);
}
} catch (e) {
console.error(e);
process.exit(1);
Expand Down
2 changes: 2 additions & 0 deletions scripts/run_saucelabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const testFiles = configFiles.length
// Get CI build number or generate one if running locally.
const buildNumber =
process.env.TRAVIS_BUILD_NUMBER ||
// GitHub Actions does not have a build number, but the feature has been requested.
process.env.GITHUB_SHA ||
`local_${process.env.USER}_${new Date().getTime()}`;

/**
Expand Down