Skip to content

Commit cf18519

Browse files
authored
CI test workflow improvements (#2576)
1 parent 295a545 commit cf18519

File tree

5 files changed

+83
-51
lines changed

5 files changed

+83
-51
lines changed

.github/workflows/deploy-canary.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

.github/workflows/test-all.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,26 @@ jobs:
3636
github-token: ${{ secrets.GITHUB_TOKEN }}
3737
path-to-lcov: ./lcov-all.info
3838
continue-on-error: true
39+
deploy:
40+
name: Canary Deploy
41+
runs-on: ubuntu-latest
42+
if: github.event.pull_request.merged
43+
needs: test
44+
45+
steps:
46+
- uses: actions/checkout@v1
47+
- name: Set up Node (10)
48+
uses: actions/setup-node@v1
49+
with:
50+
node-version: 10.x
51+
registry-url: 'https://registry.npmjs.org'
52+
- name: Yarn install
53+
run: yarn
54+
- name: yarn build
55+
run: yarn build
56+
- name: Deploy canary
57+
run: |
58+
npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
59+
yarn release --canary
60+
env:
61+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Firebase Javascript SDK
22

33
<!-- BADGES -->
4-
[![Build Status](https://travis-ci.org/firebase/firebase-js-sdk.svg?branch=master)](https://travis-ci.org/firebase/firebase-js-sdk)
4+
![Build Status](https://img.shields.io/github/workflow/status/firebase/firebase-js-sdk/Run%20All%20Tests.svg)
55
[![Build Status](https://saucelabs.com/buildstatus/firebase-oss)](https://saucelabs.com/u/firebase-oss)
66
[![Version](https://img.shields.io/npm/v/firebase.svg?label=version)](https://www.npmjs.com/package/firebase)
77
[![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)

scripts/run_changed.js

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,55 @@
1717

1818
const { resolve } = require('path');
1919
const { spawn } = require('child-process-promise');
20+
const chalk = require('chalk');
2021
const simpleGit = require('simple-git/promise');
22+
2123
const root = resolve(__dirname, '..');
2224
const git = simpleGit(root);
2325

2426
/**
25-
* Runs tests on packages changed (in comparison to origin/master...HEAD)
27+
* Changes to these files warrant running all tests.
28+
*/
29+
const fullTestTriggerFiles = [
30+
// Global dependency changes.
31+
'package.json',
32+
'yarn.lock',
33+
// Test/compile/lint configs.
34+
'config/karma.base.js',
35+
'config/.eslintrc.js',
36+
'config/mocha.browser.opts',
37+
'config/mocha.node.opts',
38+
'config/tsconfig.base.json',
39+
'config/webpack.test.js',
40+
'config/firestore.rules',
41+
'config/database.rules.json'
42+
];
43+
44+
/**
45+
* Always run tests in these paths.
2646
*/
47+
const alwaysRunTestPaths = [
48+
// These tests are very fast.
49+
'integration/browserify',
50+
'integration/firebase-typings',
51+
'integration/typescript',
52+
'integration/webpack'
53+
];
2754

28-
async function runTestsOnChangedPackages() {
55+
/**
56+
* Identify modified packages that require tests.
57+
*/
58+
async function getChangedPackages() {
2959
const diff = await git.diff(['--name-only', 'origin/master...HEAD']);
3060
const changedFiles = diff.split('\n');
3161
const changedPackages = {};
3262
for (const filename of changedFiles) {
63+
if (fullTestTriggerFiles.includes(filename)) {
64+
console.log(
65+
chalk`{blue Running all tests because ${filename} was modified.}`
66+
);
67+
return { testAll: true };
68+
}
3369
const match = filename.match('^(packages/[a-zA-Z0-9-]+)/.*');
3470
if (match && match[1]) {
3571
const pkg = require(resolve(root, match[1], 'package.json'));
@@ -39,11 +75,12 @@ async function runTestsOnChangedPackages() {
3975
}
4076
}
4177
if (Object.keys(changedPackages).length > 0) {
42-
await runTests(Object.keys(changedPackages));
78+
return { testAll: false, packageDirs: Object.keys(changedPackages) };
4379
} else {
4480
console.log(
45-
'No changes detected in any package. Skipping all package-specific tests.'
81+
chalk`{green No changes detected in any package. Skipping all package-specific tests.}`
4682
);
83+
return { testAll: false, packageDirs: [] };
4784
}
4885
}
4986

@@ -64,22 +101,24 @@ async function runTests(pathList) {
64101
}
65102
}
66103

67-
/**
68-
* These are short, always run them.
69-
*/
70-
async function runIntegrationTests() {
71-
await runTests([
72-
'integration/browserify',
73-
'integration/firebase-typings',
74-
'integration/typescript',
75-
'integration/webpack'
76-
]);
77-
}
78-
79104
async function main() {
80105
try {
81-
await runIntegrationTests();
82-
await runTestsOnChangedPackages();
106+
const { testAll, packageDirs = [] } = await getChangedPackages();
107+
if (testAll) {
108+
await spawn('yarn', ['test'], {
109+
stdio: 'inherit'
110+
});
111+
} else {
112+
console.log(chalk`{blue Running tests in:}`);
113+
for (const filename of alwaysRunTestPaths) {
114+
console.log(chalk`{green ${filename} (always runs)}`);
115+
}
116+
for (const filename of packageDirs) {
117+
console.log(chalk`{yellow ${filename} (contains modified files)}`);
118+
}
119+
await runTests(alwaysRunTestPaths);
120+
await runTests(packageDirs);
121+
}
83122
} catch (e) {
84123
console.error(e);
85124
process.exit(1);

scripts/run_saucelabs.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ const testFiles = configFiles.length
4444
// Get CI build number or generate one if running locally.
4545
const buildNumber =
4646
process.env.TRAVIS_BUILD_NUMBER ||
47+
// GitHub Actions does not have a build number, but the feature has been requested.
48+
process.env.GITHUB_SHA ||
4749
`local_${process.env.USER}_${new Date().getTime()}`;
4850

4951
/**

0 commit comments

Comments
 (0)