Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions components/legacy/scope/lanes/lanes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ export default class Lanes {
return lane;
}

/**
* remove the hidden `lane.updateDependents` entries, the dependents Ripple CI cascaded onto the lane.
* this is the one implementation of the removal: the cloud UI and "bit lane updates --undo" reach it
* through the graphql resolver, a file-system remote through `Fs`.
* only OMITTING `ids` removes all of them. an empty array removes nothing - it comes from a caller that
* resolved zero entries, and must not be read as "remove everything".
* returns true if the lane has changed.
*/
async removeUpdateDependents(laneId: LaneId, ids?: ComponentID[]): Promise<boolean> {
const lane = await this.loadLane(laneId);
if (!lane) throw new LaneNotFound(laneId.scope, laneId.toString());
if (ids) lane.removeComponentsFromUpdateDependents(ids);
else lane.removeAllUpdateDependents();
if (!lane.hasChanged) return false;
await this.saveLane(lane, { laneHistoryMsg: 'remove update-dependents' });
return true;
}

async getOrCreateLaneHistory(laneObject: Lane): Promise<LaneHistory> {
const emptyLaneHistory = LaneHistory.fromLaneObject(laneObject);
const existingLaneHistory = (await this.objects.load(emptyLaneHistory.hash(), false)) as LaneHistory;
Expand Down
3 changes: 3 additions & 0 deletions components/scope/remotes/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ export class Remote {
listLanes(name?: string, mergeData?: boolean): Promise<LaneData[]> {
return this.connect().then((network) => network.listLanes(name, mergeData));
}
removeLaneUpdateDependents(laneId: string, ids?: string[]): Promise<boolean> {
return this.connect().then((network) => network.removeLaneUpdateDependents(laneId, ids));
}
async hasObjects(hashes: string[]): Promise<string[]> {
return this.connect().then((network) => network.hasObjects(hashes));
}
Expand Down
14 changes: 14 additions & 0 deletions contrib/claude-skill-bit-cli/CLI_REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,13 @@ revert to a previous history of the current lane. see also "bit lane checkout"
revert is similar to "lane checkout", but it keeps the versions and only changes the files. choose one or the other based on your needs. if you want to continue working on this lane and need the changes from the history to be the head, then use "lane revert". if you want to fork the lane from a certain point in history, use "lane checkout" and create a new lane from it.
Flags: --skip-dependency-installation, --restore-deleted-components, --json

## bit lane updates [lane-name]

show the dependents Ripple CI cascaded onto a lane, default to the current lane

after a lane is exported, Ripple CI may snap the dependents of the lane components against the new heads and add them to the lane as hidden "update" entries. they are part of the lane graph (Ripple CI builds them, merge refreshes them) but stay hidden from the workspace ("bit status", .bitmap). the entries are read from the remote lane. the local lane object is used only when the remote is unavailable. use --undo to remove them from the lane, on the remote and locally, e.g. when the cascade is not wanted.
Flags: --undo, --json

## bit lane merge-move <new-lane-name>

EXPERIMENT. move the current merge state into a new lane. the current lane will be reset
Expand Down Expand Up @@ -798,6 +805,13 @@ Flags: --lane <lane>, --json
stop a running Ripple CI job (auto-detects current lane when no job-id given)
Flags: --lane <lane>, --json

## bit ripple simulate

start a Ripple CI simulation for a lane to reveal which dependents break (auto-detects current lane)

a simulation builds the dependents of the lane components against the lane heads on bit.cloud, without merging or publishing anything. it's the way to get dependent coverage for a change before the lane is merged. the simulation runs against the lane as it exists on bit.cloud, so export the lane first. simulations are heavy jobs and are billed as such. run them at review time, not on every change. dependents are searched in the lane's own scope by default. widen or narrow the search with --scopes, --owners and --exclude-scopes. follow the job with "bit ripple log". once it finishes, "bit ripple errors" shows what broke. both take the job id printed when the simulation starts.
Flags: --lane <lane>, --scopes <scopes>, --owners <owners>, --exclude-scopes <scopes>, --json

## bit run [app-name]

start an application component locally
Expand Down
4 changes: 2 additions & 2 deletions contrib/claude-skill-bit-cli/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ Collaboration & Remote
remote - manage remote scopes for self-hosted environments
Subcommands: add, del, list
ripple <sub-command> - manage Ripple CI jobs on bit.cloud
Subcommands: list, log, errors, retry, stop
Subcommands: list, log, errors, retry, stop, simulate
deprecate <component-pattern> - mark components as deprecated to discourage their use
undeprecate <component-pattern> - remove the deprecation status from components
import [component-patterns...] - bring components from remote scopes into your workspace
delete <component-pattern> - soft-delete components from remote scopes
recover <component-pattern> - restore soft-deleted components
export [component-patterns...] - upload components to remote scopes
lane [sub-command] - manage lanes for parallel development
Subcommands: list, show, create, remove, change-scope, alias, rename, remove-readme, import, remove-comp, fetch, eject, current, history, history-diff, checkout, revert, merge-move
Subcommands: list, show, create, remove, change-scope, alias, rename, remove-readme, import, remove-comp, fetch, eject, current, history, history-diff, checkout, revert, updates, merge-move
ci <sub-command> - continuous integration commands for automated workflows
Subcommands: verify, pr, merge, sync
fork <pattern> [target-component-name] - create a new component by copying from an existing one
Expand Down
139 changes: 137 additions & 2 deletions scopes/cloud/ripple/ripple.cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import type { Command, CommandOptions } from '@teambit/cli';
import chalk from 'chalk';
import Table from 'cli-table';
import type { LastExportData } from '@teambit/export';
import type { RippleMain, RippleJob, CiGraphNode } from './ripple.main.runtime';
import { formatSuccessSummary, formatItem, formatHint, joinSections } from '@teambit/cli';
import { BitError } from '@teambit/bit-error';
import { LaneId, DEFAULT_LANE } from '@teambit/lane-id';
import type { RippleMain, RippleJob, CiGraphNode, SimulateNetwork } from './ripple.main.runtime';
import { colorPhase, isFailedPhase, stripAnsi, resolveJobId, formatAge } from './ripple-utils';

/**
Expand Down Expand Up @@ -120,7 +123,7 @@ export class RippleListCmd implements Command {
for (const job of jobs) {
table.push([
job.id,
truncate(job.name || '-', 40),
truncate(job.name || '-', 40) + (job.simulation ? formatHint(' (simulation)') : ''),
getScopeFromLaneId(job.laneId),
colorPhase(job.status?.phase),
job.user?.username || '-',
Expand Down Expand Up @@ -666,3 +669,135 @@ function truncate(str: string, max: number): string {
if (str.length <= max) return str;
return `${str.substring(0, max - 1)}…`;
}

type SimulateFlags = {
lane?: string;
scopes?: string;
owners?: string;
excludeScopes?: string;
};

function splitList(value?: string): string[] | undefined {
if (!value) return undefined;
const items = value
.split(',')
.map((item) => item.trim())
.filter(Boolean);
return items.length ? items : undefined;
}

function describeNetwork(network: SimulateNetwork): string {
const parts = [
network.scopeIds?.length ? `scopes ${network.scopeIds.join(', ')}` : '',
network.ownerIds?.length ? `owners ${network.ownerIds.join(', ')}` : '',
network.excludeScopeIds?.length ? `excluding scopes ${network.excludeScopeIds.join(', ')}` : '',
].filter(Boolean);
return parts.join('; ');
}

type SimulateResult = {
laneId: string;
job: RippleJob;
network: SimulateNetwork;
/** no network flag was given, so the search was limited to the lane's own scope */
defaultedToLaneScope: boolean;
};

export class RippleSimulateCmd implements Command {
name = 'simulate';
description = 'start a Ripple CI simulation for a lane to reveal which dependents break (auto-detects current lane)';
extendedDescription = `a simulation builds the dependents of the lane components against the lane heads on bit.cloud,
without merging or publishing anything. it's the way to get dependent coverage for a change before the lane is merged.
the simulation runs against the lane as it exists on bit.cloud, so export the lane first.
simulations are heavy jobs and are billed as such. run them at review time, not on every change.
dependents are searched in the lane's own scope by default. widen or narrow the search with --scopes, --owners and
--exclude-scopes.
follow the job with "bit ripple log". once it finishes, "bit ripple errors" shows what broke. both take the job id
printed when the simulation starts.`;
skipWorkspace = true;
remoteOp = true;
alias = '';

options: CommandOptions = [
['', 'lane <lane>', 'lane ID to simulate, e.g. "scope/lane-name" (default: detected from .bitmap)'],
['', 'scopes <scopes>', 'comma-separated scopes to search for dependents in (default: the lane scope)'],
['', 'owners <owners>', 'comma-separated owners (organizations) to search for dependents in'],
['', 'exclude-scopes <scopes>', 'comma-separated scopes to exclude from the dependents search'],
['j', 'json', 'return the output as JSON'],
];

constructor(private ripple: RippleMain) {}

async report(_args: [], flags: SimulateFlags) {
const { laneId, job, network, defaultedToLaneScope } = await this.simulate(flags);
const networkNote = defaultedToLaneScope ? ' (default: the lane scope. use --scopes/--owners to widen)' : '';
const lines = [
formatSuccessSummary(`started a Ripple CI simulation for lane "${laneId}".`),
formatItem(`job id: ${job.id || '(not assigned yet)'}`),
job.status?.phase ? formatItem(`status: ${colorPhase(job.status.phase)}`) : '',
formatItem(`network: ${describeNetwork(network)}${networkNote}`),
formatItem(`url: ${this.ripple.getJobUrl(job)}`),
].filter(Boolean);
const hint = job.id
? formatHint(
`follow the job with "bit ripple log ${job.id}". once it finishes, run "bit ripple errors ${job.id}" to see what broke.`
)
: formatHint(
`run "bit ripple list --lane ${laneId}" to get the job id, then "bit ripple log <job-id>" to follow it.`
);
return joinSections([lines.join('\n'), hint]);
}

async json(_args: [], flags: SimulateFlags) {
const { laneId, job, network } = await this.simulate(flags);
return { laneId, job, network, url: this.ripple.getJobUrl(job) };
}

/**
* the lane to simulate: `--lane` when given (validated and normalized), otherwise the current lane.
*/
private resolveLaneId(flags: SimulateFlags): { laneId: string; isCurrentLane: boolean } {
const currentLaneId = this.ripple.getCurrentLaneId();
if (!flags.lane) {
if (!currentLaneId) {
throw new BitError('a simulation requires a lane. switch to a lane or pass --lane <scope/lane-name>');
}
return { laneId: currentLaneId, isCurrentLane: true };
}
if (flags.lane === DEFAULT_LANE) throw new BitError(defaultLaneError(flags.lane));
let parsed: LaneId;
try {
parsed = LaneId.parse(flags.lane);
} catch (err: any) {
throw new BitError(`invalid --lane "${flags.lane}", expected "scope/lane-name". ${err.message}`);
}
if (parsed.isDefault()) throw new BitError(defaultLaneError(flags.lane));
const laneId = parsed.toString();
return { laneId, isCurrentLane: laneId === currentLaneId };
}

private async simulate(flags: SimulateFlags): Promise<SimulateResult> {
const { laneId, isCurrentLane } = this.resolveLaneId(flags);
if (isCurrentLane && this.ripple.isCurrentLaneExported() === false) {
throw new BitError(
`lane "${laneId}" was never exported. a simulation runs against the lane on bit.cloud, run "bit export" first`
);
}
const network: SimulateNetwork = {
scopeIds: splitList(flags.scopes),
ownerIds: splitList(flags.owners),
excludeScopeIds: splitList(flags.excludeScopes),
};
// Ripple CI can't resolve the dependents graph without a positive search base (scopes or owners),
// so search the lane's own scope by default. exclusions alone only narrow, they don't provide a base.
const defaultedToLaneScope = !network.scopeIds?.length && !network.ownerIds?.length;
if (defaultedToLaneScope) network.scopeIds = [LaneId.parse(laneId).scope];
const job = await this.ripple.simulateLane(laneId, network);
if (!job) throw new BitError(`failed to start a simulation for lane "${laneId}"`);
return { laneId, job, network, defaultedToLaneScope };
}
}

function defaultLaneError(lane: string): string {
return `"${lane}" is the default lane. a simulation needs a lane whose changes are tested against their dependents on main`;
}
Loading
Loading