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
7 changes: 7 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @openfn/cli

## 1.38.1

### Patch Changes

- Updated dependencies [97dabc4]
- @openfn/[email protected]

## 1.38.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/cli",
"version": "1.38.0",
"version": "1.38.1",
"description": "CLI devtools for the OpenFn toolchain",
"engines": {
"node": ">=18",
Expand Down
6 changes: 6 additions & 0 deletions packages/deploy/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @openfn/deploy

## 0.13.1

### Patch Changes

- 97dabc4: Ensure that workflows can be removed in v1 sync

## 0.13.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/deploy/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/deploy",
"version": "0.13.0",
"version": "0.13.1",
"description": "Deploy projects to Lightning instances",
"type": "module",
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion packages/deploy/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export async function deploy(config: DeployConfig, logger: Logger) {
spec.errors.forEach((e: any) => logger.warn(`${e.path} :: ${e.message}`));
throw new DeployError(`${config.specPath} has errors`, 'VALIDATION_ERROR');
}
const nextState = mergeSpecIntoState(state, spec.doc, logger);
const nextState = mergeSpecIntoState(state, spec.doc);

validateProjectState(nextState);

Expand Down
33 changes: 12 additions & 21 deletions packages/deploy/src/stateTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
assignIfTruthy,
} from './utils';
import { DeployError } from './deployError';
import { Logger } from '@openfn/logger/dist';

function stringifyJobBody(body: SpecJobBody): string {
if (typeof body === 'object') {
Expand Down Expand Up @@ -300,8 +299,7 @@ function mergeEdges(
// Prepare the next state, based on the current state and the spec.
export function mergeSpecIntoState(
oldState: ProjectState,
spec: ProjectSpec,
logger?: Logger
spec: ProjectSpec
): ProjectState {
const nextCredentials = Object.fromEntries(
splitZip(oldState.project_credentials || {}, spec.credentials || {}).map(
Expand Down Expand Up @@ -462,14 +460,7 @@ export function mergeSpecIntoState(
}

if (!specWorkflow && !isEmpty(stateWorkflow || {})) {
logger?.error('Critical error! Cannot continue');
logger?.error(
'Workflow found in project state but not spec:',
stateWorkflow?.name
? `${stateWorkflow.name} (${stateWorkflow?.id})`
: stateWorkflow?.id
);
process.exit(1);
return [workflowKey, { id: stateWorkflow!.id, delete: true }];
}

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

const workflows: ProjectPayload['workflows'] = Object.values(
state.workflows
).map((workflow) => {
return {
...workflow,
jobs: Object.values(workflow.jobs),
triggers: Object.values(workflow.triggers),
edges: Object.values(workflow.edges),
};
});
const workflows: ProjectPayload['workflows'] = Object.values(state.workflows)
.filter((workflow) => !workflow.delete)
.map((workflow) => {
return {
...workflow,
jobs: Object.values(workflow.jobs),
triggers: Object.values(workflow.triggers),
edges: Object.values(workflow.edges),
};
});

const project_credentials: ProjectPayload['project_credentials'] =
Object.values(state.project_credentials);
Expand Down
21 changes: 17 additions & 4 deletions packages/deploy/test/stateTransform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,22 @@ test('toNextState removing a job and edge', (t) => {
t.deepEqual(result, existingState);
});

test('toNextState deleting a whole workflow', (t) => {
let existingState = fullExampleState();
let spec = fullExampleSpec();

delete spec.workflows['workflow-one'];

let result = mergeSpecIntoState(existingState, spec);

jp.apply(existingState, '$.workflows["workflow-one"]', (value) => ({
id: value.id,
delete: true,
}));

t.deepEqual(result, existingState);
});

test('toNextState with for kafka trigger', (t) => {
const state = { workflows: {} };
const spec = {
Expand Down Expand Up @@ -1133,10 +1149,7 @@ test('toNextState resolves channel destination_credential to id', (t) => {

const result = mergeSpecIntoState(state, spec);

t.is(
result.channels['webhook-out'].destination_credential_id,
'cred-id-123'
);
t.is(result.channels['webhook-out'].destination_credential_id, 'cred-id-123');
});

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