@devries-cameron20 / composio Mirror · read-only
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 03:37 UTC

next
ts 116 lines 6.37 KB
Raw
1 import { Match, Schema } from 'effect';
2
3 /** The three workflow triggers a release passes through, in order. */
4 export const Stage = Schema.Literals(['request', 'review', 'publish']);
5 export type Stage = typeof Stage.Type;
6
7 const Url = Schema.String.check(Schema.isPattern(/^https:\/\//));
8 const Version = Schema.Struct({ name: Schema.String, version: Schema.String });
9
10 /**
11 * Every state a release can be in, derived each run from what GitHub and the registries hold.
12 * Nothing stores it; the request issue only displays the latest one.
13 */
14 export const ReleaseState = Schema.Union([
15 /** A member's request could not be read. */
16 Schema.TaggedStruct('NeedsInput', { reason: Schema.String }),
17 /** Another release PR is open. */
18 Schema.TaggedStruct('Waiting', { pull: Url }),
19 /** `next` carries a merged release plan that was never tagged. */
20 Schema.TaggedStruct('Blocked', { release: Schema.String }),
21 /** No pending changesets for the selected languages. */
22 Schema.TaggedStruct('Empty', {}),
23 /** The release PR is open for review. */
24 Schema.TaggedStruct('InReview', { pull: Url }),
25 /** The release PR closed without merging. */
26 Schema.TaggedStruct('Abandoned', { pull: Url }),
27 /** The release PR merged but failed the release gate, so nothing was tagged. */
28 Schema.TaggedStruct('Refused', { pull: Url, reason: Schema.String }),
29 /** The reviewed head is tagged; the tag run publishes it. */
30 Schema.TaggedStruct('Tagged', { tag: Schema.String }),
31 /** Every planned package is served by its registry. */
32 Schema.TaggedStruct('Published', { versions: Schema.Array(Version) }),
33 /** A job failed or was cancelled; re-running the failed jobs resumes the stage. */
34 Schema.TaggedStruct('Failed', {
35 stage: Stage,
36 jobs: Schema.Array(Schema.String),
37 run: Url,
38 }),
39 ]);
40 export type ReleaseState = typeof ReleaseState.Type;
41 export type StateName = ReleaseState['_tag'];
42
43 /**
44 * Each stage is one workflow run. It starts from the state the previous stage ended in, and ends
45 * in exactly one of `to`. A failed stage resumes from the same `from` when its jobs re-run.
46 */
47 export const STAGES = {
48 request: { from: 'Requested', to: ['NeedsInput', 'Waiting', 'Blocked', 'Empty', 'InReview'] },
49 review: { from: 'InReview', to: ['Abandoned', 'Refused', 'Tagged'] },
50 publish: { from: 'Tagged', to: ['Published'] },
51 } as const satisfies Record<
52 Stage,
53 { readonly from: StateName | 'Requested'; readonly to: ReadonlyArray<StateName> }
54 >;
55
56 /** Whether `state` is a legal end for `stage`. `Failed` ends any stage. */
57 export const endsStage = (stage: Stage, state: ReleaseState) =>
58 state._tag === 'Failed' || (STAGES[stage].to as ReadonlyArray<StateName>).includes(state._tag);
59
60 /**
61 * How each state shows on the request issue: one exclusive label, and whether the issue closes.
62 * `InReview`, `Tagged` and `Failed` keep the issue open because the release can still advance.
63 */
64 export const DISPLAY = {
65 NeedsInput: { label: 'sdk-release:needs-input', close: 'not_planned' },
66 Waiting: { label: 'sdk-release:waiting', close: 'not_planned' },
67 Blocked: { label: 'sdk-release:blocked', close: 'not_planned' },
68 Empty: { label: 'sdk-release:empty', close: 'not_planned' },
69 InReview: { label: 'sdk-release:in-review', close: null },
70 Abandoned: { label: 'sdk-release:abandoned', close: 'not_planned' },
71 Refused: { label: 'sdk-release:refused', close: 'not_planned' },
72 Tagged: { label: 'sdk-release:publishing', close: null },
73 Published: { label: 'sdk-release:published', close: 'completed' },
74 Failed: { label: 'sdk-release:failed', close: null },
75 } as const satisfies Record<
76 StateName,
77 { readonly label: string; readonly close: 'completed' | 'not_planned' | null }
78 >;
79
80 export const STATUS_LABELS: ReadonlyArray<string> = Object.values(DISPLAY).map(
81 display => display.label
82 );
83
84 export const RECOVERY_RUNBOOK =
85 'https://github.com/ComposioHQ/composio/blob/next/ts/docs/internal/release.md#recover-a-failed-release';
86
87 /** How to resume a failed stage. */
88 const RECOVERY: Record<Stage, string> = {
89 request: 'Open the run and choose "Re-run failed jobs", or request the release again.',
90 review: `If GitHub failed, open the run and choose "Re-run failed jobs"; creating the tag is safe to repeat. A re-run uses the gate as it was before the merge, so if the gate itself is wrong, fix it on \`next\` and dispatch **SDK release** with action \`regate\`: ${RECOVERY_RUNBOOK}`,
91 publish:
92 'Open the run and choose "Re-run failed jobs"; a re-run uploads only the files the registries are missing. If the approved candidates expired or a registry serves different bytes, add changesets and request a new release.',
93 };
94
95 /** The status comment text for a state. */
96 export const describe = (state: ReleaseState) =>
97 Match.valueTags(state, {
98 NeedsInput: ({ reason }) =>
99 `The request could not be read: ${reason}\n\nOpen a new request with the SDK release issue form.`,
100 Waiting: ({ pull }) =>
101 `Another SDK release is in progress: ${pull}. Request this release again after it finishes.`,
102 Blocked: ({ release }) =>
103 `The release planned in run ${release} merged into \`next\` but was never tagged. If a gate bug refused it and the fix is on \`next\`, dispatch **SDK release** with action \`regate\`; otherwise revert its release PR on \`next\`. Then request this release again. See ${RECOVERY_RUNBOOK}`,
104 Empty: () => 'Nothing to release: no pending changesets for the selected languages.',
105 InReview: ({ pull }) =>
106 `Release PR: ${pull}\n\nA repository writer approves it. The requester may approve only with repository admin permission. Merging it tags and publishes the release.`,
107 Abandoned: ({ pull }) =>
108 `${pull} closed without merging, so nothing was tagged or published. Request a new release when ready.`,
109 Refused: ({ pull, reason }) =>
110 `${pull} merged, but it failed the release gate, so nothing was tagged or published.\n\nReason: ${reason}\n\nRevert the release PR on \`next\`, then request the release again. If the gate itself was wrong, fix it on \`next\` and dispatch **SDK release** with action \`regate\` instead: ${RECOVERY_RUNBOOK}`,
111 Tagged: ({ tag }) => `Tagged \`${tag}\`. The tag run publishes the reviewed files.`,
112 Published: ({ versions }) =>
113 ['Published:', '', ...versions.map(({ name, version }) => `- ${name} ${version}`)].join('\n'),
114 Failed: ({ stage, jobs, run }) =>
115 `The ${stage} stage failed in: ${jobs.join(', ')}.\n\n${run}\n\n${RECOVERY[stage]}`,
116 });