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

Adds workflow:validate command #2650

Merged
merged 3 commits into from
Nov 7, 2024

Conversation

jonsamp
Copy link
Member

@jonsamp jonsamp commented Oct 24, 2024

Why

This adds a command to validate YAML in workflow configuration files.

Screenshots

Valid YAML output

Screenshot 2024-10-24 at 12 04 22 AM

Invalid YAML output

Screenshot 2024-10-24 at 12 04 28 AM

Test Plan

Create a .yml file and test it with eas workflow:validate path/to/file.yml. You should see output like the screenshots above.

  • Make sure non existent files result in an error
  • Make sure non .yml/.yaml files result in an error
  • Make sure bad YAML results in an error
  • Make sure good YAML results in no error

Copy link

linear bot commented Oct 24, 2024

@jonsamp jonsamp force-pushed the jon/eng-13772-create-workflows-eas-cli-command branch from dbbf05e to 1706240 Compare October 24, 2024 05:31
Copy link

github-actions bot commented Oct 24, 2024

Size Change: +156 kB (+0.3%)

Total Size: 52.9 MB

Filename Size Change
./packages/eas-cli/dist/eas-linux-x64.tar.gz 52.9 MB +156 kB (+0.3%)

compressed-size-action

Copy link

codecov bot commented Oct 24, 2024

Codecov Report

Attention: Patch coverage is 88.67925% with 6 lines in your changes missing coverage. Please review.

Project coverage is 52.95%. Comparing base (7c9970d) to head (645eb35).
Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
packages/eas-cli/src/commands/workflow/validate.ts 88.68% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2650      +/-   ##
==========================================
+ Coverage   52.92%   52.95%   +0.04%     
==========================================
  Files         570      572       +2     
  Lines       21834    21951     +117     
  Branches     4297     4329      +32     
==========================================
+ Hits        11554    11623      +69     
- Misses      10246    10294      +48     
  Partials       34       34              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jonsamp jonsamp force-pushed the jon/eng-13772-create-workflows-eas-cli-command branch from 5633e1e to 91fc501 Compare November 4, 2024 23:19
@jonsamp jonsamp added the no changelog PR that doesn't require a changelog entry label Nov 4, 2024
@jonsamp jonsamp marked this pull request as ready for review November 4, 2024 23:22
@jonsamp jonsamp requested review from byCedric and sjchmiela November 4, 2024 23:22
Copy link

github-actions bot commented Nov 4, 2024

Subscribed to pull request

File Patterns Mentions
**/* @szdziedzic, @khamilowicz, @sjchmiela

Generated by CodeMention

Copy link
Contributor

@sjchmiela sjchmiela left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • package manager discrepancy to fix
  • YAML parser discrepancy to comment on or fix
  • spinner to reconsider?

packages/eas-cli/package.json Outdated Show resolved Hide resolved

try {
const fileContents = await fs.readFile(filePath, 'utf8');
const parsedYaml = yaml.load(fileContents);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be much better if the command could also validate the schema, currently only in www. I think this is a sensible reason to move the workflow schema to eas-build-job later…

Another viable approach would be to use createWorkflowRun with some dry = true flag, or something. It would not create a workflow run or a workflow revision, only parse and validate with www.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I guess that schema validation would have the biggest benefit for a user here, it would catch all of the typos and so on. Let's move the schema definition to eas-build-job and validate against it here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how to move this to eas-build-job (not familiar with where that code is or what change to make there). Could we either pair or could one of you help me?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, ideally we'd write a JSON schema that we can validate against, and not only check that the YAML is valid. Adding that where the workflow runs would be great, then exporting it to here would be nice, to validate on the server and on the client, and have the same set of rules.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how to move this to eas-build-job (not familiar with where that code is or what change to make there). Could we either pair or could one of you help me?

Don't worry about it @jonsamp, this doesn't need to be a part of this PR and we can do it because we are familiar why how things work there 🙌

Also, ideally we'd write a JSON schema that we can validate against, and not only check that the YAML is valid. Adding that where the workflow runs would be great, then exporting it here would be nice, to validate on the server and on the client, and have the same set of rules.

I believe this is what @sjchmiela meant, we have this JSON schema validation implemented using Zod ready and working on both worker-level and WWW-level. We need to move it to eas-build-job which is a common lib for such definitions, that is shared between here, WWW, and other places 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how to move this to eas-build-job (not familiar with where that code is or what change to make there). Could we either pair or could one of you help me?

Will do. In the meantime, I think this is good to go. It's not a blocker.

ideally we'd write a JSON schema that we can validate against

I agree. I started looking into it a while back, but it wasn't too easy. Let me explain.

Exporting JSON schema from Zod schema (or writing it) for the "general" structure of the workflow YAML is easy. Validation of the actual jobs is where it becomes kinda difficult, because we either:

  • export Zod directly — then interpolations will be "error", because platform: android | ios does not expect platform: ${{ needs.setup.outputs.platform }}. "${{ needs.setup.outputs.platform }}" is not "android" or "ios" after all.
  • do some post-processing on Zod types, replacing enums with strings or expanding enum properties to allow that enum or an arbitrary string.

I think I had a branch somewhere that exposed this from www

All in all — not a blocker for this to go.

yarn.lock Outdated Show resolved Hide resolved
packages/eas-cli/package.json Outdated Show resolved Hide resolved

try {
const fileContents = await fs.readFile(filePath, 'utf8');
const parsedYaml = yaml.load(fileContents);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I guess that schema validation would have the biggest benefit for a user here, it would catch all of the typos and so on. Let's move the schema definition to eas-build-job and validate against it here.

Copy link

github-actions bot commented Nov 6, 2024

⏩ The changelog entry check has been skipped since the "no changelog" label is present.

Copy link
Member

@szdziedzic szdziedzic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks for applying suggested changes 🚀

@jonsamp jonsamp merged commit d47b80a into main Nov 7, 2024
10 checks passed
@jonsamp jonsamp deleted the jon/eng-13772-create-workflows-eas-cli-command branch November 7, 2024 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no changelog PR that doesn't require a changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants