-
Notifications
You must be signed in to change notification settings - Fork 942
Run tests only on changed packages on PR/push #2565
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7fc2507
add commit to test
hsubox76 104f265
add analytics test commit
hsubox76 03744a1
add remote-config change for testing
hsubox76 df2ae48
Remove package changes for testing
hsubox76 d7bf6f6
Set up config
hsubox76 52da8de
Revise names
hsubox76 9f52d00
[AUTOMATED]: Prettier Code Styling
hsubox76 d308bab
[AUTOMATED]: License Headers
hsubox76 06acd8f
Address PR comments
hsubox76 6d28a60
[AUTOMATED]: Prettier Code Styling
hsubox76 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 9 additions & 2 deletions
11
.github/workflows/node-chrome-test.yml → .github/workflows/test-all.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string>} 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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be log this case:
No changes detected in any package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, added it to
runTestsOnChangedPackages
since this function is also used to run the integration tests.