Merge pull request #29353 from kurtaking/checkpoint-types

refactor: experimental checkpoint types
This commit is contained in:
Ben Lambert
2025-06-20 10:19:32 +02:00
committed by GitHub
13 changed files with 158 additions and 100 deletions
@@ -27,6 +27,31 @@ export type AutocompleteHandler = ({
}[];
}>;
// @alpha
export type CheckpointContext<T extends JsonValue | void = JsonValue> = {
key: string;
fn: () => Promise<T> | T;
};
// @alpha
export type CheckpointState = {
[key: string]: CheckpointStateValue;
};
// @alpha
export type CheckpointStateValue<T extends JsonValue = JsonValue> =
| {
status: 'failed';
reason: string;
}
| {
status: 'success';
value: T;
};
// @alpha
export type CheckpointStatus = 'failed' | 'success';
// @alpha (undocumented)
export type CreatedTemplateFilter<
TFunctionArgs extends [z.ZodTypeAny, ...z.ZodTypeAny[]],
@@ -187,6 +212,11 @@ export type TemplateGlobalFunctionExample = {
notes?: string;
};
// @alpha
export type UpdateTaskCheckpointOptions = {
key: string;
} & CheckpointStateValue;
// @alpha
export interface WorkspaceProvider {
// (undocumented)
+6 -17
View File
@@ -4,6 +4,7 @@
```ts
import { BackstageCredentials } from '@backstage/backend-plugin-api';
import { CheckpointContext } from '@backstage/plugin-scaffolder-node/alpha';
import { Expand } from '@backstage/types';
import { JsonObject } from '@backstage/types';
import { JsonValue } from '@backstage/types';
@@ -15,6 +16,7 @@ import { ScmIntegrations } from '@backstage/integration';
import { SpawnOptionsWithoutStdio } from 'child_process';
import { TaskSpec } from '@backstage/plugin-scaffolder-common';
import { TemplateInfo } from '@backstage/plugin-scaffolder-common';
import { UpdateTaskCheckpointOptions } from '@backstage/plugin-scaffolder-node/alpha';
import { UrlReaderService } from '@backstage/backend-plugin-api';
import { UserEntity } from '@backstage/catalog-model';
import { Writable } from 'stream';
@@ -30,10 +32,9 @@ export type ActionContext<
secrets?: TaskSecrets;
workspacePath: string;
input: TActionInput;
checkpoint<T extends JsonValue | void>(opts: {
key: string;
fn: () => Promise<T> | T;
}): Promise<T>;
checkpoint<T extends JsonValue | void>(
opts: CheckpointContext<T>,
): Promise<T>;
output(
name: keyof TActionOutput,
value: TActionOutput[keyof TActionOutput],
@@ -446,19 +447,7 @@ export interface TaskContext {
// (undocumented)
taskId?: string;
// (undocumented)
updateCheckpoint?(
options:
| {
key: string;
status: 'success';
value: JsonValue;
}
| {
key: string;
status: 'failed';
reason: string;
},
): Promise<void>;
updateCheckpoint?(options: UpdateTaskCheckpointOptions): Promise<void>;
}
// @public
+5 -4
View File
@@ -23,6 +23,8 @@ import {
BackstageCredentials,
LoggerService,
} from '@backstage/backend-plugin-api';
import { CheckpointContext } from '@backstage/plugin-scaffolder-node/alpha';
/**
* ActionContext is passed into scaffolder actions.
* @public
@@ -36,10 +38,9 @@ export type ActionContext<
secrets?: TaskSecrets;
workspacePath: string;
input: TActionInput;
checkpoint<T extends JsonValue | void>(opts: {
key: string;
fn: () => Promise<T> | T;
}): Promise<T>;
checkpoint<T extends JsonValue | void>(
opts: CheckpointContext<T>,
): Promise<T>;
output(
name: keyof TActionOutput,
value: TActionOutput[keyof TActionOutput],
@@ -0,0 +1,16 @@
/*
* Copyright 2025 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './types';
@@ -0,0 +1,57 @@
/*
* Copyright 2025 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { JsonValue } from '@backstage/types';
/**
* The status of a checkpoint, indicating whether it succeeded or failed.
*
* @alpha
*/
export type CheckpointStatus = 'failed' | 'success';
/**
* Represents the union of all possible checkpoint state values.
*
* @alpha
*/
export type CheckpointStateValue<T extends JsonValue = JsonValue> =
| { status: 'failed'; reason: string }
| { status: 'success'; value: T };
/**
* A map of checkpoint keys to their states.
*
* @alpha
*/
export type CheckpointState = {
[key: string]: CheckpointStateValue;
};
/**
* Context for checkpoint function invocation.
*
* @alpha
*/
export type CheckpointContext<T extends JsonValue | void = JsonValue> = {
/**
* Unique key for the checkpoint
*/
key: string;
/**
* Function to execute for the checkpoint
*/
fn: () => Promise<T> | T;
};
@@ -28,6 +28,7 @@ export * from '../tasks/alpha';
export * from './filters';
export * from './globals';
export * from './types';
export * from './checkpoints';
/**
* Extension point for managing scaffolder actions.
@@ -1,3 +1,5 @@
import { CheckpointStateValue } from '../alpha';
/*
* Copyright 2024 The Backstage Authors
*
@@ -14,3 +16,12 @@
* limitations under the License.
*/
export * from './serializer';
/**
* Options for updating a checkpoint in a task.
*
* @alpha
*/
export type UpdateTaskCheckpointOptions = {
key: string;
} & CheckpointStateValue;
+3 -14
View File
@@ -16,7 +16,8 @@
import { BackstageCredentials } from '@backstage/backend-plugin-api';
import { TaskSpec } from '@backstage/plugin-scaffolder-common';
import { JsonObject, JsonValue, Observable } from '@backstage/types';
import { JsonObject, Observable } from '@backstage/types';
import { UpdateTaskCheckpointOptions } from '@backstage/plugin-scaffolder-node/alpha';
/**
* TaskSecrets
@@ -129,19 +130,7 @@ export interface TaskContext {
| undefined
>;
updateCheckpoint?(
options:
| {
key: string;
status: 'success';
value: JsonValue;
}
| {
key: string;
status: 'failed';
reason: string;
},
): Promise<void>;
updateCheckpoint?(options: UpdateTaskCheckpointOptions): Promise<void>;
serializeWorkspace?(options: { path: string }): Promise<void>;