Skip to content

Commit 5f265bb

Browse files
authored
Track workflow renames (#1596)
* deprecate the id field being written to workflow.yaml * track workflow uuid in checkout.yaml * track workflow UUIDs when loading from fs * add helper to match workflows on merge * hookup workflow tracking to deploy * impove diff for users upon a workflow rename * clarifying comments on test files * couple of tests * add more basic sync tests * new tests * restructure sync integration tests * add step rename tests * cli: use env var to skip no confirm * refactor tests for cleaner commands# * enable workflow tracking on rename * new test
1 parent aaaed2e commit 5f265bb

41 files changed

Lines changed: 1744 additions & 116 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@openfn/project': patch
3+
---
4+
5+
Track workflow uuids in the checkout file, and load them onto workflows
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@openfn/cli': patch
3+
'@openfn/project': patch
4+
---
5+
6+
Fix deploying an edit to a renamed workflow deleting it from Lightning
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@openfn/cli': patch
3+
'@openfn/project': patch
4+
---
5+
6+
Show a renamed workflow as changed, not added and removed, in project diffs
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@openfn/project': patch
3+
---
4+
5+
Match workflows by uuid, then id, then name when merging projects

‎.changeset/shaggy-bears-clean.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@openfn/cli': patch
3+
---
4+
5+
Add OPENFN_NO_CONFIRM env var

‎.changeset/workflow-yaml-no-id.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@openfn/project': patch
3+
---
4+
5+
Workflow ids in workflow.yaml files are now ignored on load: the file name is used instead

‎integration-tests/cli/src/run.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ import * as path from 'node:path';
33

44
const isProd = process.env.NODE_ENV === 'production';
55

6-
const getOptions = () => ({
6+
const getOptions = (env = {}) => ({
77
env: {
8+
// there's nobody to answer a prompt (a test can override this)
9+
OPENFN_NO_CONFIRM: 'true',
810
...process.env,
11+
...env,
912
OPENFN_REPO_DIR: path.resolve('repo'),
1013
// workspaces live inside the kit git repo: don't pick up its branch
1114
OPENFN_BRANCH: 'false',
@@ -23,10 +26,12 @@ const mapOpenFnPath = (cmd) => {
2326
};
2427

2528
const run = async (
26-
cmd: string
29+
cmd: string,
30+
// extra environment variables for this command only
31+
env?: Record<string, string>
2732
): Promise<{ stdout: string; stderr?: string; err?: any }> => {
2833
return new Promise((resolve) => {
29-
exec(mapOpenFnPath(cmd), getOptions(), (err, stdout, stderr) => {
34+
exec(mapOpenFnPath(cmd), getOptions(env), (err, stdout, stderr) => {
3035
resolve({ err, stdout, stderr });
3136
});
3237
});

‎integration-tests/cli/test/deploy.test.ts‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Tests legacy `openfn deploy` and `openfn pull` commands against a mock Lightning
2+
13
import test from 'ava';
24
import path from 'node:path';
35
import fs, { rm } from 'node:fs/promises';
@@ -157,7 +159,6 @@ test.serial('deploy a local project', async (t) => {
157159
`openfn deploy \
158160
--project-path ${tmpDir}/project.yaml \
159161
--state-path ${tmpDir}/.state.json \
160-
--no-confirm \
161162
--log-json \
162163
-l debug`
163164
);
@@ -188,7 +189,6 @@ test.serial('Update a project', async (t) => {
188189
const deployCmd = `openfn deploy \
189190
--project-path ${projectPath} \
190191
--state-path ${statePath} \
191-
--no-confirm \
192192
--log-json -l debug`;
193193
const first = await run(deployCmd);
194194
t.falsy(first.stderr);
@@ -230,7 +230,6 @@ test.serial('pull a project', async (t) => {
230230
const deployCmd = `openfn deploy \
231231
--project-path ${projectPath} \
232232
--state-path ${statePath} \
233-
--no-confirm \
234233
--log-json -l debug`;
235234

236235
await run(deployCmd);
@@ -323,7 +322,7 @@ test.serial('redirect to v2 protocol if openfn.yaml is present', async (t) => {
323322

324323
// v1 deploy -> should redirect to v2
325324
const { stdout, stderr } = await run(
326-
`openfn deploy --workspace ${tmpDir} --no-confirm --log-json -l debug`
325+
`openfn deploy --workspace ${tmpDir} --log-json -l debug`
327326
);
328327
t.falsy(stderr);
329328
assertLog(t, extractLogs(stdout), /Detected openfn.yaml file/i);
@@ -364,7 +363,6 @@ workflows:
364363
`openfn deploy \
365364
--project-path ${tmpDir}/project.yaml \
366365
--state-path ${tmpDir}/.state.json \
367-
--no-confirm \
368366
--log-json \
369367
-l debug`
370368
);
@@ -397,7 +395,6 @@ test.serial('deploy then pull, changes one workflow, deploy', async (t) => {
397395
const deployCmd = `openfn deploy \
398396
--project-path ${projectPath} \
399397
--state-path ${statePath} \
400-
--no-confirm \
401398
--log debug \
402399
--log-json`;
403400
await run(deployCmd);
@@ -451,7 +448,6 @@ test.serial('deploy a v2 project.yaml', async (t) => {
451448
`openfn deploy \
452449
--project-path ${tmpDir}/project.yaml \
453450
--state-path ${tmpDir}/.state.json \
454-
--no-confirm \
455451
--log-json \
456452
-l debug`
457453
);
@@ -481,7 +477,6 @@ test.serial('deploy a new v2 project.yaml with credentials', async (t) => {
481477
const { stdout, stderr } = await run(
482478
`openfn deploy \
483479
--project-path ${tmpDir}/project.yaml \
484-
--no-confirm \
485480
--log-json \
486481
-l debug`
487482
);
@@ -526,7 +521,6 @@ collections:
526521
const deployCmd = `openfn deploy \
527522
--project-path ${projectPath} \
528523
--state-path ${statePath} \
529-
--no-confirm \
530524
--log-json -l debug`;
531525

532526
// first deploy - no collections yet
@@ -573,7 +567,6 @@ ${collectionsWorkflow}
573567
const deployCmd = `openfn deploy \
574568
--project-path ${projectPath} \
575569
--state-path ${statePath} \
576-
--no-confirm \
577570
--log-json -l debug`;
578571

579572
// first deploy - creates the collection

‎integration-tests/cli/test/deploy.v2.test.ts‎

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Tests v2 `openfn project pull` and `openfn project deploy` loop against a mock Lightning
2+
13
import test from 'ava';
24
import path from 'node:path';
35
import fs from 'node:fs/promises';
@@ -71,7 +73,7 @@ test.serial('pull, change and re-deploy', async (t) => {
7173

7274
// deploy
7375
const { stdout, stderr } = await run(
74-
`openfn project deploy --no-confirm --log-json -l debug`
76+
`openfn project deploy --log-json -l debug`
7577
);
7678
t.falsy(stderr);
7779

@@ -99,9 +101,7 @@ test.serial('pull, change and re-deploy twice', async (t) => {
99101

100102
// first deploy
101103
await fs.writeFile(exprPath, 'fn(s => ({ ...s, v: 1 }))');
102-
const first = await run(
103-
`openfn project deploy --no-confirm --log-json -l debug`
104-
);
104+
const first = await run(`openfn project deploy --log-json -l debug`);
105105
t.falsy(first.stderr);
106106
assertLog(t, extractLogs(first.stdout), /Updated project/);
107107

@@ -112,7 +112,7 @@ test.serial('pull, change and re-deploy twice', async (t) => {
112112
// second deploy after another update
113113
await fs.writeFile(exprPath, 'fn(s => ({ ...s, v: 2 }))');
114114
const { stdout, stderr } = await run(
115-
`openfn project deploy --no-confirm --log-json -l debug`
115+
`openfn project deploy --log-json -l debug`
116116
);
117117
t.falsy(stderr);
118118
const logs = extractLogs(stdout);
@@ -140,9 +140,7 @@ test.serial('deploy and pull to check version history', async (t) => {
140140
await fs.writeFile(exprPath, 'fn(s => ({ ...s, v: 1 }))');
141141

142142
// deploy then pull
143-
const { stderr } = await run(
144-
`openfn project deploy --no-confirm --log-json -l debug`
145-
);
143+
const { stderr } = await run(`openfn project deploy --log-json -l debug`);
146144
t.falsy(stderr);
147145
await run(`openfn project pull ${projectId} --log-json -l debug`);
148146

@@ -174,7 +172,7 @@ test.serial('deploy then pull, change one workflow, deploy', async (t) => {
174172

175173
// deploy
176174
const { stdout, stderr } = await run(
177-
`openfn project deploy --no-confirm --log-json -l debug`
175+
`openfn project deploy --log-json -l debug`
178176
);
179177
t.falsy(stderr);
180178
const logs = extractLogs(stdout);
@@ -215,7 +213,7 @@ test.serial('Remove a whole workflow', async (t) => {
215213

216214
// deploy
217215
const { stdout, stderr } = await run(
218-
`openfn project deploy --no-confirm --log-json -l debug`
216+
`openfn project deploy --log-json -l debug`
219217
);
220218
t.falsy(stderr);
221219

@@ -262,7 +260,7 @@ steps:
262260
await rimraf(path.join(tmpDir, 'workflows/my-workflow/my-job.js'));
263261

264262
const { stdout, stderr } = await run(
265-
`openfn project deploy --no-confirm --log-json -l debug`
263+
`openfn project deploy --log-json -l debug`
266264
);
267265
t.falsy(stderr);
268266

@@ -317,7 +315,7 @@ steps:
317315
);
318316

319317
const { stdout, stderr } = await run(
320-
`openfn project deploy --no-confirm --log-json -l debug`
318+
`openfn project deploy --log-json -l debug`
321319
);
322320
t.falsy(stderr);
323321

@@ -372,9 +370,7 @@ test.serial.skip(
372370
await fs.writeFile(exprPath, "post('http://success.org')");
373371

374372
// deploy
375-
const { stdout, stderr } = await run(
376-
`openfn project deploy --no-confirm -l debug`
377-
);
373+
const { stdout, stderr } = await run(`openfn project deploy -l debug`);
378374
console.log(stdout);
379375
t.falsy(stderr);
380376
const logs = extractLogs(stdout);
@@ -400,9 +396,7 @@ test.serial('warn when local and remote workflows have diverged', async (t) => {
400396
// base
401397
await run(`openfn project pull ${projectId} --log-json -l debug`);
402398
await fs.writeFile(exprPath, 'fn(s => ({ ...s, v: 1 }))');
403-
const firstDeploy = await run(
404-
`openfn project deploy --no-confirm --log-json -l debug`
405-
);
399+
const firstDeploy = await run(`openfn project deploy --log-json -l debug`);
406400
assertLog(t, extractLogs(firstDeploy.stdout), /Updated project/);
407401

408402
// remote changed from base
@@ -424,7 +418,7 @@ test.serial('warn when local and remote workflows have diverged', async (t) => {
424418

425419
// deploy with divergence
426420
const { stdout, err } = await run(
427-
`openfn project deploy --no-confirm --log-json -l debug`
421+
`openfn project deploy --log-json -l debug`
428422
);
429423
t.truthy(err);
430424
const logs = extractLogs(stdout);
@@ -448,7 +442,7 @@ test.serial('deploy a pulled v2 state file as a new project', async (t) => {
448442

449443
// deploy that exact file back as a duplicate
450444
const { stdout, stderr } = await run(
451-
`openfn project deploy ${pulledPath} --new --name my-duplicate --no-confirm --log-json -l debug`
445+
`openfn project deploy ${pulledPath} --new --name my-duplicate --log-json -l debug`
452446
);
453447
t.falsy(stderr);
454448

@@ -506,7 +500,7 @@ test.serial(
506500

507501
// deploy main's pulled file, but target staging instead of main
508502
const { stdout, stderr } = await run(
509-
`openfn project deploy ${mainPath} staging --no-confirm --log-json -l debug`
503+
`openfn project deploy ${mainPath} staging --log-json -l debug`
510504
);
511505
t.falsy(stderr);
512506
assertLog(t, extractLogs(stdout), /Updated project/);
@@ -553,7 +547,7 @@ test.serial(
553547
await fs.writeFile(resourcesPath, jsonToYaml(before));
554548

555549
const { stdout, stderr } = await run(
556-
`openfn project deploy --no-confirm --log-json -l debug`
550+
`openfn project deploy --log-json -l debug`
557551
);
558552
t.falsy(stderr);
559553

@@ -596,7 +590,7 @@ workflows:
596590
await fs.writeFile(exportedPath, specYaml);
597591

598592
const { stdout, stderr } = await run(
599-
`openfn project deploy ${exportedPath} --name my-duplicate --no-confirm --log-json -l debug`
593+
`openfn project deploy ${exportedPath} --name my-duplicate --log-json -l debug`
600594
);
601595
t.falsy(stderr);
602596

@@ -659,7 +653,7 @@ test.serial(
659653
await fs.writeFile(resourcesPath, jsonToYaml(before));
660654

661655
const { stdout, stderr } = await run(
662-
`openfn project deploy --no-confirm --log-json -l debug`
656+
`openfn project deploy --log-json -l debug`
663657
);
664658
t.falsy(stderr);
665659

‎integration-tests/cli/test/project-v1.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Tests offline `openfn checkout`, `merge` and `projects` on static legacy v1 project yaml files
2+
// (no Lightning); see project-v2 for the same commands on v2 files
3+
14
import test from 'ava';
25
import { rm, mkdir, writeFile, readFile } from 'node:fs/promises';
36
import path from 'node:path';

0 commit comments

Comments
 (0)