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

Bug: Parameters with typeof steps are not generated correctly #161

Open
2 of 4 tasks
Xavientois opened this issue Nov 14, 2022 · 11 comments
Open
2 of 4 tasks

Bug: Parameters with typeof steps are not generated correctly #161

Xavientois opened this issue Nov 14, 2022 · 11 comments
Labels
bug Something isn't working

Comments

@Xavientois
Copy link

Xavientois commented Nov 14, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

Values passed to a parameter with the post_steps parameter type are generated incorrectly.

  • The builtin checkout command produces an empty object
  • A custom reusable command generates a name: property

This causes the generated config to fail when trying to run the pipeline

Minimum reproduction code

https://gist.github.com/Xavientois/21bb00fc854d75d3bab19905611d47a2

Steps to reproduce

No response

Expected behavior

  • Checkout would generate - checkout
  • The custom command would not include the name: property

CircleCI Config SDK version

0.10.1

Node.js version

16.18.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@Xavientois Xavientois added the bug Something isn't working label Nov 14, 2022
@Xavientois Xavientois changed the title Bug: steps parameter type is generated incorrectly Bug: post_steps parameter type is generated incorrectly Nov 15, 2022
@Jaryt
Copy link
Contributor

Jaryt commented Nov 16, 2022

Hi! Thanks for opening this issue. It looks like this is an unexpected way of implementing post-steps which is causing the problem.

The WorkflowJob constructor has the parameter arguments, then two special arguments for pre steps and post steps.

constructor(
    job: Job | OrbRef<JobParameterLiteral>,
    parameters?: Exclude<WorkflowJobParameters, 'type'>,
    pre_steps?: StepsParameter,
    post_steps?: StepsParameter,
  )

So instead of defining the pre_steps in the parameters object yourself, you pass them along in the following arguments.

new CircleCI.Workflow('example', {}, [
    new CircleCI.workflow.WorkflowJob(vfcommon.jobs['install_and_build'], {}, [
      new CircleCI.commands.Checkout(),
      new CircleCI.reusable.ReusedCommand(vfcommon.commands['notify_slack'], {
        event: 'fail',
      }),
    ]),
  ]);

I also found an unexpected output where if you have undefined parameters, the pre and post steps will not be generated. The real issue here means that any "StepsParameter" might not be generating as expected. That's a good find. I'll change the title of this issue to reflect that. (Looks like your first title was correct 😄 )

@Jaryt Jaryt changed the title Bug: post_steps parameter type is generated incorrectly Bug: Parameters with typeof steps are not generated correctly Nov 16, 2022
@Jaryt
Copy link
Contributor

Jaryt commented Nov 17, 2022

I see now that there is a pre_steps are also on the parameters object. This is likely an error, but might be the preferable way. Happy to receive some input on which is better for the end user, as I can see pros and cons to both.

@Xavientois
Copy link
Author

In my opinion, in order to avoid confusion like this, only one or the other should be allowed, not both. Ideally, if we decide to pass pre/post-steps as separate parameters, the type system would complain if the user tries to set them inside the parameters object.

Given that, it might be simplest to remove them as separate parameters and just pass them as members of the parameters object. That way, there is only one unambiguous way to specify pre/post-steps. For that reason, I think that passing them in the parameters object is the better option, as it makes it harder for the user to do the wrong thing (like I did) and get unexpected results.

@Xavientois
Copy link
Author

I found another manifestation of this issue when passing the built-in persist_to_workspace command in a list of steps. Added it to the linked gist above

@Xavientois
Copy link
Author

@Jaryt Any updates on this? We are hoping to start porting some of our existing configs to the SDK, but this is a blocker.

@KyleTryon
Copy link
Contributor

Hey @Xavientois 👋

Would you be willing to test out the #176 PR and let me know if this works for you?

@Xavientois
Copy link
Author

Sure thing! Thanks!

@Xavientois
Copy link
Author

Xavientois commented Feb 10, 2023

@KyleTryon I tested it with the following code, and still saw issues. Maybe my TS setup is broken.
https://gist.github.com/Xavientois/7ea9388408896f2be515c0140ab22a1a

@KyleTryon
Copy link
Contributor

Hey @Xavientois sorry for the delay, I had to attend to some work on another repo. Coming back to take a look here. Thank you for the added info!

@Xavientois
Copy link
Author

Perfect! Thanks! If my example works on your machine, then the issue on my end was likely my TS setup, so I would consider it fixed at that point.

@KyleTryon
Copy link
Contributor

Updating with comments from PR, a new PR will be created.

#176 (comment)

https://gist.github.com/Xavientois/7ea9388408896f2be515c0140ab22a1a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants