Skip to content

Commit

Permalink
Merge pull request #55 from tiktok/feat-build-test-real-repo
Browse files Browse the repository at this point in the history
feat: build test for a real repo
  • Loading branch information
chengcyber authored Mar 13, 2024
2 parents 7cf0c14 + cf9b018 commit cad5ef0
Show file tree
Hide file tree
Showing 37 changed files with 1,003 additions and 204 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ jobs:
with:
fetch-depth: 2
- name: Configure Git
env:
GITHUB_TOKEN: ${{ secrets.BOT_ACCESS_TOKEN }}
run: |
git config --local user.name tiktokbot
git config --local user.email [email protected]
git config --global credential.helper '!f() { echo "protocol=https\nhost=github.com" ; echo "username=oauth_token" ; echo "password=${GITHUB_TOKEN}" ; }; f'
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ For details, consult the [Sparo documentation](./apps/sparo/README.md).
| Folder | Description |
| ------ | -----------|
| [/apps/website](./apps/website/) | The Sparo documentation website |
| [/build-tests/sparo-output-test](./build-tests/sparo-output-test/) | Building this project tests Sparo command-line outputs |
| [/build-tests/sparo-real-repo-test](./build-tests/sparo-real-repo-test/) | Building this project tests Sparo by cloning a real repository |
| [/build-tests/test-utilities](./build-tests/test-utilities/) | Code shared between the build test projects in this repository |
<!-- GENERATED PROJECT SUMMARY END -->

## Contributing
Expand Down
15 changes: 11 additions & 4 deletions apps/sparo-lib/src/cli/commands/list-profiles.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import childProcess from 'child_process';
import type { Argv, ArgumentsCamelCase } from 'yargs';
import { Sort } from '@rushstack/node-core-library';
import { inject } from 'inversify';
import { SparoProfileService } from '../../services/SparoProfileService';
import { ICommand } from './base';
import { Command } from '../../decorator';
import { inject } from 'inversify';
import { GitSparseCheckoutService } from '../../services/GitSparseCheckoutService';

import type { Argv, ArgumentsCamelCase } from 'yargs';
import type { TerminalService } from '../../services/TerminalService';
import type { SparoProfile } from '../../logic/SparoProfile';

Expand Down Expand Up @@ -47,6 +49,8 @@ export class ListProfilesCommand implements ICommand<IListProfilesCommandOptions
if (!project) {
// List all available profiles
terminalService.terminal.writeLine('All available profiles:');
// Ensure the stable order of the profiles
Sort.sortMapKeys(sparoProfiles);
terminalService.terminal.writeLine(Array.from(sparoProfiles.keys()).join('\n'));
} else {
// Query all profiles that contain the specified project
Expand All @@ -69,9 +73,12 @@ export class ListProfilesCommand implements ICommand<IListProfilesCommandOptions
}
}

if (profileProjects.has(project)) {
const profilesContainProject: string[] | undefined = profileProjects.get(project);
if (profilesContainProject) {
// Ensure the stable order of the profiles
Sort.sortBy(profilesContainProject, (x) => x, Sort.compareByValue);
terminalService.terminal.writeLine(
`${project} was included in the below profiles:\n ${profileProjects.get(project)?.join('\n')}`
`${project} was included in the below profiles:\n ${profilesContainProject.join('\n')}`
);
} else {
terminalService.terminal.writeErrorLine(`${project} is not included in any pre-configured profile`);
Expand Down
12 changes: 9 additions & 3 deletions apps/sparo-lib/src/services/GitCloneService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ an empty directory.`);
terminal.writeDebugLine('full clone start...');
const cloneArgs: string[] = ['clone', repository, directory];
const result: child_process.SpawnSyncReturns<string> = this._gitService.executeGitCommand({
args: cloneArgs
args: cloneArgs,
// This is clone command, no need to find git folder
workingDirectory: process.cwd()
});
if (result?.status) {
throw new Error(`git clone failed with exit code ${result.status}`);
Expand All @@ -79,7 +81,9 @@ an empty directory.`);
directory
];
const result: child_process.SpawnSyncReturns<string> = this._gitService.executeGitCommand({
args: cloneArgs
args: cloneArgs,
// This is clone command, no need to find git folder
workingDirectory: process.cwd()
});
if (result?.status) {
throw new Error(`git clone failed with exit code ${result.status}`);
Expand All @@ -101,7 +105,9 @@ an empty directory.`);
directory
];
const result: child_process.SpawnSyncReturns<string> = this._gitService.executeGitCommand({
args: cloneArgs
args: cloneArgs,
// This is clone command, no need to find git folder
workingDirectory: process.cwd()
});
if (result?.status) {
throw new Error(`git clone failed with exit code ${result.status}`);
Expand Down
8 changes: 1 addition & 7 deletions apps/sparo/src/start-ci.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import { Sparo, type ILaunchOptions } from 'sparo-lib';
import { SparoPackage } from './SparoPackage';

process.exitCode = 1;

const launchOptions: ILaunchOptions = {
callerPackageJson: SparoPackage._sparoPackageJson
};

Sparo.launchSparoCIAsync(launchOptions)
.then(() => {
process.exitCode = 0;
})
.catch(console.error);
Sparo.launchSparoCIAsync(launchOptions).catch(console.error);
8 changes: 1 addition & 7 deletions apps/sparo/src/start.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import { Sparo, type ILaunchOptions } from 'sparo-lib';
import { SparoPackage } from './SparoPackage';

process.exitCode = 1;

const launchOptions: ILaunchOptions = {
callerPackageJson: SparoPackage._sparoPackageJson
};

Sparo.launchSparoAsync(launchOptions)
.then(() => {
process.exitCode = 0;
})
.catch(console.error);
Sparo.launchSparoAsync(launchOptions).catch(console.error);
2 changes: 1 addition & 1 deletion build-tests/sparo-output-test/etc/checkout-help.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Running "sparo checkout --help":

Sparo accelerator for Git __VERSION__ - https://tiktok.github.io/sparo/
[bold]Sparo accelerator for Git __VERSION__ -[normal][cyan] https://tiktok.github.io/sparo/[default]
Node.js version is __VERSION__ (LTS)
Git version is __VERSION__

Expand Down
2 changes: 1 addition & 1 deletion build-tests/sparo-output-test/etc/clone-help.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Running "sparo clone --help":

Sparo accelerator for Git __VERSION__ - https://tiktok.github.io/sparo/
[bold]Sparo accelerator for Git __VERSION__ -[normal][cyan] https://tiktok.github.io/sparo/[default]
Node.js version is __VERSION__ (LTS)
Git version is __VERSION__

Expand Down
2 changes: 1 addition & 1 deletion build-tests/sparo-output-test/etc/top-level-help.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Running "sparo --help":

Sparo accelerator for Git __VERSION__ - https://tiktok.github.io/sparo/
[bold]Sparo accelerator for Git __VERSION__ -[normal][cyan] https://tiktok.github.io/sparo/[default]
Node.js version is __VERSION__ (LTS)
Git version is __VERSION__

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Running "sparo nonexistent-command":

Sparo accelerator for Git __VERSION__ - https://tiktok.github.io/sparo/
[bold]Sparo accelerator for Git __VERSION__ -[normal][cyan] https://tiktok.github.io/sparo/[default]
Node.js version is __VERSION__ (LTS)
Git version is __VERSION__


--[ git nonexistent-command ]--------------------------------------------------
-------------------------------------------------------------------------------
[gray]--[[default] [bold]git nonexistent-command[normal] [gray]]--------------------------------------------------[default]
[gray]-------------------------------------------------------------------------------[default]

5 changes: 2 additions & 3 deletions build-tests/sparo-output-test/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sparo-output-test",
"description": "Building this project tests sparo command outputs",
"description": "Building this project tests Sparo command-line outputs",
"version": "1.0.0",
"private": true,
"scripts": {
Expand All @@ -9,8 +9,7 @@
},
"dependencies": {
"@rushstack/node-core-library": "~3.64.2",
"sparo": "workspace:*",
"jest-diff": "~29.7.0"
"build-test-utilities": "workspace:*"
},
"devDependencies": {
"@rushstack/heft": "0.64.3",
Expand Down
Loading

0 comments on commit cad5ef0

Please sign in to comment.