Skip to content

Commit

Permalink
Merge pull request #30 from tiktok/fix-ci-checkout
Browse files Browse the repository at this point in the history
Fix ci checkout
  • Loading branch information
chengcyber authored Feb 29, 2024
2 parents f0a5e86 + 0690a22 commit dc29742
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 43 deletions.
50 changes: 50 additions & 0 deletions apps/sparo-lib/src/cli/commands/ci-checkout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { inject } from 'inversify';
import type { Argv, ArgumentsCamelCase } from 'yargs';
import { ICommand } from './base';
import { Command } from '../../decorator';
import { GitSparseCheckoutService } from '../../services/GitSparseCheckoutService';

export interface ICICheckoutCommandOptions {
to?: string[];
from?: string[];
}

@Command()
export class CICheckoutCommand implements ICommand<ICICheckoutCommandOptions> {
public cmd: string = 'checkout';
public description: string =
'Special checkout command for CI. It only accepts project selector suchs as --to and --from now.';
@inject(GitSparseCheckoutService) private _gitSparseCheckoutService!: GitSparseCheckoutService;
public builder(yargs: Argv<ICICheckoutCommandOptions>): void {
yargs
.option('to', {
type: 'array',
alias: 't',
description: 'See https://rushjs.io/pages/developer/selecting_subsets/#--to for more details.'
})
.option('from', {
type: 'array',
alias: 'f',
description: 'See https://rushjs.io/pages/developer/selecting_subsets/#--from for more details.'
})
.check((argv, options) => {
const { to, from } = argv;
const toNum: number = (to || []).length;
const fromNum: number = (from || []).length;
if (toNum === 0 && fromNum === 0) {
throw new Error('At least one of "--to" or "--from" must be specified');
}
return true;
});
}
public handler = async (args: ArgumentsCamelCase<ICICheckoutCommandOptions>): Promise<void> => {
const { to, from } = args;
await this._gitSparseCheckoutService.checkoutAsync({
to,
from
});
};
public getHelp(): string {
return 'sparse help';
}
}
41 changes: 0 additions & 41 deletions apps/sparo-lib/src/cli/commands/ci-sparse.ts

This file was deleted.

4 changes: 2 additions & 2 deletions apps/sparo-lib/src/cli/commands/cmd-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ListProfilesCommand } from './list-profiles';
import { AutoConfigCommand } from './auto-config';
import { FetchCommand } from './fetch';
import { CIHelpCommand } from './ci-help';
import { CISparseCommand } from './ci-sparse';
import { CICheckoutCommand } from './ci-checkout';
import { CICloneCommand } from './ci-clone';
import { CheckoutCommand } from './checkout';
import { GitCloneCommand } from './git-clone';
Expand Down Expand Up @@ -33,4 +33,4 @@ export const COMMAND_LIST: Constructable[] = [
GitPullCommand
];

export const CI_COMMAND_LIST: Constructable[] = [CICloneCommand, CISparseCommand, CIHelpCommand];
export const CI_COMMAND_LIST: Constructable[] = [CICloneCommand, CICheckoutCommand, CIHelpCommand];
10 changes: 10 additions & 0 deletions common/changes/sparo/fix-ci-checkout_2024-02-28-22-28.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "sparo",
"comment": "Support checkout --to or --from in sparo-ci, replacing sparo-ci sparse",
"type": "none"
}
],
"packageName": "sparo"
}

0 comments on commit dc29742

Please sign in to comment.