-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Detect from commit history which service tests to run #1936
Changes from all commits
9920e70
a1c7d64
60b0531
561206f
fc8de84
c6dfd5b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ package-lock.json | |
/.next | ||
/build | ||
/coverage | ||
**/*.md |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Automatically detect the services changed by comparing the current commit | ||
// to `master`. This approach of examining commits was taken because detecting | ||
// a pull request from CircleCI is unreliable. It allows for a nicer dev | ||
// experience because it will generally automatically detect which files have | ||
// changed. | ||
// | ||
// If for any reason the automatic service detection doesn't correctly | ||
// identify the affected services, additional services can be tagged in a commit | ||
// message, e.g. | ||
// | ||
// - [Travis] Fix timeout issues | ||
// - [Travis Sonar] Support user token authentication | ||
// - [CRAN CPAN CTAN] Add test coverage | ||
|
||
'use strict' | ||
|
||
const simpleGit = require('simple-git/promise') | ||
const { identifyServices } = require('../../services') | ||
const servicesForTitle = require('./services-for-title') | ||
|
||
async function taggedServices() { | ||
const log = await simpleGit(__dirname).log(['--first-parent', 'master..HEAD']) | ||
const commitMessages = log.all.map(l => l.message) | ||
return commitMessages.reduce( | ||
(accum, message) => accum.concat(servicesForTitle(message)), | ||
[] | ||
) | ||
} | ||
|
||
async function modifiedServices() { | ||
const diffSummary = await simpleGit(__dirname).diffSummary([ | ||
'--no-renames', | ||
'master...HEAD', | ||
]) | ||
const affectedFiles = diffSummary.files.map(f => f.file) | ||
return identifyServices(affectedFiles) | ||
} | ||
|
||
async function allAffectedServices() { | ||
return (await taggedServices()).concat(await modifiedServices()) | ||
} | ||
|
||
async function main() { | ||
const services = await allAffectedServices() | ||
if (services.length === 0) { | ||
console.error('No services found. Nothing to do.') | ||
} else { | ||
console.error( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this logged as an error? |
||
`Services: (${services.length} found) ${services.join(', ')}\n` | ||
) | ||
console.log(services.join('\n')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this similar to the previous log line? Also, we're logging about the found services in cli.js, so do we need these logs here at all? |
||
} | ||
} | ||
|
||
if (require.main === module) { | ||
;(async () => { | ||
try { | ||
await main() | ||
} catch (e) { | ||
console.error(e) | ||
process.exit(1) | ||
} | ||
})() | ||
} | ||
|
||
module.exports = { | ||
allAffectedServices, | ||
} |
This file was deleted.
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.
We should add a note to the docs here that we can also run
npm run test:services -- --all
to run the full service test suite.