Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: allow file paths for state and data in a workflow #715

Merged
merged 5 commits into from
Jun 24, 2024

Conversation

SatyamMattoo
Copy link
Contributor

@SatyamMattoo SatyamMattoo commented Jun 13, 2024

Short Description

Allows the user to add file paths to the state and data in a workflow.

Related issue

Fixes #639

Implementation Details

I have added a function that checks if the state is a file path. If it is, the function reads the file. Additionally, if the data (or any key inside state) is a file path, it will read that file and update the key with the file's content.

For example, if we have
workflow.json:

{
    "workflow": {
        "steps": [
            {
                "id": "1",
                "adaptor": "common",
                "state": "./state.json",
                "expression": "./expression.js"
            }
        ]
    }
}

state.json:

{
    "data":"./data.json"
}

data.json:

{
    "x": 1
}

It will compile the workflow as:

{
  "workflow": {
    "steps": [
      {
        "id": "1",
        "adaptor": "@openfn/language-common",
        "state": {
          "data": {
            "x": 1
          }
        },
        "expression": "import { fn } from \"@openfn/language-common\";\nexport * from \"@openfn/language-common\";\nexport default [fn((state) => state)];"
      }
    ],
    "name": "input"
  },
  "options": {}
}

QA Notes

Added a test to verify that the file paths are identified, and the file content is successfully copied to the required key. Also tested it locally for different cases.

Checklist before requesting a review

  • I have performed a self-review of my code
  • I have added unit tests
  • Changesets have been added (if there are production code changes)

@josephjclark
Copy link
Collaborator

Thank you @SatyamMattoo - I'll take a look at this next week 🙏

@josephjclark
Copy link
Collaborator

This will also need testing and maybe implementing in the deploy command @SatyamMattoo, which is probably the hard bit

@SatyamMattoo
Copy link
Contributor Author

Okay sure, I will try doing that as well and push the changes for the review. For the testing part do you mean the integration tests or adding more tests here?

@josephjclark
Copy link
Collaborator

Actually @SatyamMattoo forget about the deploy thing - I think that's actually a separate concern. I'll merge this and raise another issue for deploy if I need to (but on reflection we may not)

@josephjclark josephjclark changed the base branch from main to release/next June 24, 2024 10:46
@josephjclark josephjclark merged commit d3def2f into OpenFn:release/next Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CLI: cannot set a file path to data in workflow.json
2 participants