mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2024-12-08 00:45:29 +01:00
fix(cli): add --base
option to run test
command
This commit is contained in:
parent
ede3e7526b
commit
996dcd89c3
9
.github/workflows/ci.yml
vendored
9
.github/workflows/ci.yml
vendored
@ -109,5 +109,12 @@ jobs:
|
|||||||
- name: 'Install programming-challenges'
|
- name: 'Install programming-challenges'
|
||||||
run: 'npm install --global'
|
run: 'npm install --global'
|
||||||
|
|
||||||
|
- uses: 'nrwl/last-successful-commit-action@v1'
|
||||||
|
id: 'last_successful_commit'
|
||||||
|
with:
|
||||||
|
branch: 'master'
|
||||||
|
workflow_id: 'ci.yml'
|
||||||
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: 'Test'
|
- name: 'Test'
|
||||||
run: 'programming-challenges run test --affected --ci'
|
run: 'programming-challenges run test --affected --ci --base=${{ steps.last_successful_commit.outputs.commit_hash }}'
|
||||||
|
@ -39,12 +39,17 @@ export class RunTestCommand extends Command {
|
|||||||
description: 'Run the tests for the Continuous Integration (CI).'
|
description: 'Run the tests for the Continuous Integration (CI).'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
public base = Option.String('--base', {
|
||||||
|
description: 'Base of the current branch (usually master)'
|
||||||
|
})
|
||||||
|
|
||||||
async execute (): Promise<number> {
|
async execute (): Promise<number> {
|
||||||
console.log()
|
console.log()
|
||||||
try {
|
try {
|
||||||
if (this.affected) {
|
if (this.affected) {
|
||||||
const gitAffected = new GitAffected({
|
const gitAffected = new GitAffected({
|
||||||
isContinuousIntegration: this.isContinuousIntegration
|
isContinuousIntegration: this.isContinuousIntegration,
|
||||||
|
base: this.base
|
||||||
})
|
})
|
||||||
const solutions = await gitAffected.getAffectedSolutions()
|
const solutions = await gitAffected.getAffectedSolutions()
|
||||||
for (const solution of solutions) {
|
for (const solution of solutions) {
|
||||||
|
@ -9,13 +9,16 @@ const solutionsRegex = new RegExp(
|
|||||||
|
|
||||||
export interface GitAffectedOptions {
|
export interface GitAffectedOptions {
|
||||||
isContinuousIntegration: boolean
|
isContinuousIntegration: boolean
|
||||||
|
base?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GitAffected implements GitAffectedOptions {
|
export class GitAffected implements GitAffectedOptions {
|
||||||
public isContinuousIntegration: boolean
|
public isContinuousIntegration: boolean
|
||||||
|
public base?: string
|
||||||
|
|
||||||
constructor (options: GitAffectedOptions) {
|
constructor (options: GitAffectedOptions) {
|
||||||
this.isContinuousIntegration = options.isContinuousIntegration
|
this.isContinuousIntegration = options.isContinuousIntegration
|
||||||
|
this.base = options.base
|
||||||
}
|
}
|
||||||
|
|
||||||
public parseGitOutput (output: string): string[] {
|
public parseGitOutput (output: string): string[] {
|
||||||
@ -57,12 +60,14 @@ export class GitAffected implements GitAffectedOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async getAffectedSolutions (): Promise<Solution[]> {
|
public async getAffectedSolutions (): Promise<Solution[]> {
|
||||||
const files = Array.from(
|
let files = [
|
||||||
new Set([
|
...(await this.getUnpushedFiles()),
|
||||||
...(await this.getUnpushedFiles()),
|
...(await this.getUncommittedFiles())
|
||||||
...(await this.getUncommittedFiles())
|
]
|
||||||
])
|
if (this.base != null) {
|
||||||
)
|
files.push(...(await this.getFilesUsingBaseAndHead(this.base, '.')))
|
||||||
|
}
|
||||||
|
files = Array.from(new Set(files))
|
||||||
const affectedSolutionsPaths = files.filter((filePath) => {
|
const affectedSolutionsPaths = files.filter((filePath) => {
|
||||||
return solutionsRegex.test(filePath)
|
return solutionsRegex.test(filePath)
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user