Skip to content

Commit 216614a

Browse files
authored
Allow deploy v1 to remove workflows (#1457)
* add failing test * ensure v1 can remove a workflow * changeset * don't blow up on deleted workflows * version: cli@1.38.1 * remove only
1 parent 0a44f4c commit 216614a

7 files changed

Lines changed: 45 additions & 28 deletions

File tree

packages/cli/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# @openfn/cli
22

3+
## 1.38.1
4+
5+
### Patch Changes
6+
7+
- Updated dependencies [97dabc4]
8+
- @openfn/deploy@0.13.1
9+
310
## 1.38.0
411

512
### Minor Changes

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openfn/cli",
3-
"version": "1.38.0",
3+
"version": "1.38.1",
44
"description": "CLI devtools for the OpenFn toolchain",
55
"engines": {
66
"node": ">=18",

packages/deploy/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @openfn/deploy
22

3+
## 0.13.1
4+
5+
### Patch Changes
6+
7+
- 97dabc4: Ensure that workflows can be removed in v1 sync
8+
39
## 0.13.0
410

511
### Minor Changes

packages/deploy/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openfn/deploy",
3-
"version": "0.13.0",
3+
"version": "0.13.1",
44
"description": "Deploy projects to Lightning instances",
55
"type": "module",
66
"exports": {

packages/deploy/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export async function deploy(config: DeployConfig, logger: Logger) {
117117
spec.errors.forEach((e: any) => logger.warn(`${e.path} :: ${e.message}`));
118118
throw new DeployError(`${config.specPath} has errors`, 'VALIDATION_ERROR');
119119
}
120-
const nextState = mergeSpecIntoState(state, spec.doc, logger);
120+
const nextState = mergeSpecIntoState(state, spec.doc);
121121

122122
validateProjectState(nextState);
123123

packages/deploy/src/stateTransform.ts

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
assignIfTruthy,
2222
} from './utils';
2323
import { DeployError } from './deployError';
24-
import { Logger } from '@openfn/logger/dist';
2524

2625
function stringifyJobBody(body: SpecJobBody): string {
2726
if (typeof body === 'object') {
@@ -300,8 +299,7 @@ function mergeEdges(
300299
// Prepare the next state, based on the current state and the spec.
301300
export function mergeSpecIntoState(
302301
oldState: ProjectState,
303-
spec: ProjectSpec,
304-
logger?: Logger
302+
spec: ProjectSpec
305303
): ProjectState {
306304
const nextCredentials = Object.fromEntries(
307305
splitZip(oldState.project_credentials || {}, spec.credentials || {}).map(
@@ -462,14 +460,7 @@ export function mergeSpecIntoState(
462460
}
463461

464462
if (!specWorkflow && !isEmpty(stateWorkflow || {})) {
465-
logger?.error('Critical error! Cannot continue');
466-
logger?.error(
467-
'Workflow found in project state but not spec:',
468-
stateWorkflow?.name
469-
? `${stateWorkflow.name} (${stateWorkflow?.id})`
470-
: stateWorkflow?.id
471-
);
472-
process.exit(1);
463+
return [workflowKey, { id: stateWorkflow!.id, delete: true }];
473464
}
474465

475466
return [
@@ -656,16 +647,16 @@ export function toProjectPayload(state: ProjectState): ProjectPayload {
656647
// the server expects lists of jobs, triggers, and edges, so we need to
657648
// convert the keyed objects into lists.
658649

659-
const workflows: ProjectPayload['workflows'] = Object.values(
660-
state.workflows
661-
).map((workflow) => {
662-
return {
663-
...workflow,
664-
jobs: Object.values(workflow.jobs),
665-
triggers: Object.values(workflow.triggers),
666-
edges: Object.values(workflow.edges),
667-
};
668-
});
650+
const workflows: ProjectPayload['workflows'] = Object.values(state.workflows)
651+
.filter((workflow) => !workflow.delete)
652+
.map((workflow) => {
653+
return {
654+
...workflow,
655+
jobs: Object.values(workflow.jobs),
656+
triggers: Object.values(workflow.triggers),
657+
edges: Object.values(workflow.edges),
658+
};
659+
});
669660

670661
const project_credentials: ProjectPayload['project_credentials'] =
671662
Object.values(state.project_credentials);

packages/deploy/test/stateTransform.test.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,22 @@ test('toNextState removing a job and edge', (t) => {
401401
t.deepEqual(result, existingState);
402402
});
403403

404+
test('toNextState deleting a whole workflow', (t) => {
405+
let existingState = fullExampleState();
406+
let spec = fullExampleSpec();
407+
408+
delete spec.workflows['workflow-one'];
409+
410+
let result = mergeSpecIntoState(existingState, spec);
411+
412+
jp.apply(existingState, '$.workflows["workflow-one"]', (value) => ({
413+
id: value.id,
414+
delete: true,
415+
}));
416+
417+
t.deepEqual(result, existingState);
418+
});
419+
404420
test('toNextState with for kafka trigger', (t) => {
405421
const state = { workflows: {} };
406422
const spec = {
@@ -1133,10 +1149,7 @@ test('toNextState resolves channel destination_credential to id', (t) => {
11331149

11341150
const result = mergeSpecIntoState(state, spec);
11351151

1136-
t.is(
1137-
result.channels['webhook-out'].destination_credential_id,
1138-
'cred-id-123'
1139-
);
1152+
t.is(result.channels['webhook-out'].destination_credential_id, 'cred-id-123');
11401153
});
11411154

11421155
test('toNextState throws when channel references unknown credential', (t) => {

0 commit comments

Comments
 (0)