diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f5ec1ed..5f7b0ac 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -109,5 +109,12 @@ jobs: - name: 'Install programming-challenges' 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' - run: 'programming-challenges run test --affected --ci' + run: 'programming-challenges run test --affected --ci --base=${{ steps.last_successful_commit.outputs.commit_hash }}' diff --git a/cli/commands/run/test.ts b/cli/commands/run/test.ts index e73337e..e6ed993 100644 --- a/cli/commands/run/test.ts +++ b/cli/commands/run/test.ts @@ -39,12 +39,17 @@ export class RunTestCommand extends Command { 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 { console.log() try { if (this.affected) { const gitAffected = new GitAffected({ - isContinuousIntegration: this.isContinuousIntegration + isContinuousIntegration: this.isContinuousIntegration, + base: this.base }) const solutions = await gitAffected.getAffectedSolutions() for (const solution of solutions) { diff --git a/cli/services/GitAffected.ts b/cli/services/GitAffected.ts index 20d783a..cf03b93 100644 --- a/cli/services/GitAffected.ts +++ b/cli/services/GitAffected.ts @@ -9,13 +9,16 @@ const solutionsRegex = new RegExp( export interface GitAffectedOptions { isContinuousIntegration: boolean + base?: string } export class GitAffected implements GitAffectedOptions { public isContinuousIntegration: boolean + public base?: string constructor (options: GitAffectedOptions) { this.isContinuousIntegration = options.isContinuousIntegration + this.base = options.base } public parseGitOutput (output: string): string[] { @@ -57,12 +60,14 @@ export class GitAffected implements GitAffectedOptions { } public async getAffectedSolutions (): Promise { - const files = Array.from( - new Set([ - ...(await this.getUnpushedFiles()), - ...(await this.getUncommittedFiles()) - ]) - ) + let files = [ + ...(await this.getUnpushedFiles()), + ...(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) => { return solutionsRegex.test(filePath) })