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

feat: Add optional project_name to action #755

Merged

Conversation

miguel-botelho
Copy link
Contributor

This PR adds a new optional property called project_name, so that the comments created by the Github action are unique, based on current stack_infra + project_name. This will facilitate working with Pulumi actions inside monorepos, so that multiple jobs are ran in a PR and each job will have its own comment, given they are for different stacks or projects.
Besides that, also added a bit more tests around the pr spec.

On another note, I went with creating project_name as optional, not sure on what is the desired approach for this one. Also, if there's any way to find the name of the Pulumi project without the user specifying on the YML, I believe would be less intrusive (but I couldn't find by reading the project's source code a way to do so). Feedback is more than welcomed!

Fixes #563

Copy link
Contributor

@RobbieMcKinstry RobbieMcKinstry left a comment

Choose a reason for hiding this comment

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

Hey, @miguel-botelho thank you very much for your contribution and especially for implementing this so quickly!

if there's any way to find the name of the Pulumi project without the user specifying on the YML, I believe would be less intrusive

IMO, I think we can get the project name programmatically using the Automation API. The Project Settings have a field for the project name.

For example, we import items from the Automation API here.

You should be able to get an instance of ProjectSettings using this method. I think this method is callable whenever, but you might want to wait until after this line so the stack is selected. Forgive me, I'm not very well-versed on the Automation API.

CHANGELOG.md Outdated
@@ -9,6 +9,8 @@

- feat: Always show login information

- feat: Add project name to avoid having unintended edited comments
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- feat: Add project name to avoid having unintended edited comments
- feat: Includes the project name in comments, eliminating conflicts when working with multiple projects in the same repository. ([#563](https://github.com/pulumi/actions/issues/563))

Copy link
Contributor Author

@miguel-botelho miguel-botelho Oct 17, 2022

Choose a reason for hiding this comment

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

Thanks for the suggestion! Committed here: 905033c

src/libs/pr.ts Outdated
let heading = `#### :tropical_drink: \`${command}\` on ${stackName}`;
if (projectName) {
heading = `${heading} for project ${projectName}`
}
Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM.

Nit: Assume projectName is set. Do you think the message would be clear enough if written as

#### :tropical_drink: \`${command}\` on ${projectName}/${stackName}`

...or do you think having for project ${projectName} is necessary for clarity?

I'm leaning towards "not clear enough" but WDYT?

Copy link
Contributor Author

@miguel-botelho miguel-botelho Oct 17, 2022

Choose a reason for hiding this comment

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

I think projectName/stackName is enough IMO, if the name of the project is something indicative. Not sure what's the "norm" for Pulumi project names, but for the ones I use, the simpler output is better 😄
I ended up refactoring to be less verbose here: 905033c, but I can always change it back

@RobbieMcKinstry RobbieMcKinstry added kind/bug Some behavior is incorrect or out of spec impact/reliability Something that feels unreliable or flaky area/cicd labels Oct 15, 2022
@RobbieMcKinstry
Copy link
Contributor

Oh, I also wanted to say thanks for fixing up the tests too!

@miguel-botelho
Copy link
Contributor Author

Hey, @miguel-botelho thank you very much for your contribution and especially for implementing this so quickly!

if there's any way to find the name of the Pulumi project without the user specifying on the YML, I believe would be less intrusive

IMO, I think we can get the project name programmatically using the Automation API. The Project Settings have a field for the project name.

For example, we import items from the Automation API here.

You should be able to get an instance of ProjectSettings using this method. I think this method is callable whenever, but you might want to wait until after this line so the stack is selected. Forgive me, I'm not very well-versed on the Automation API.

Hey @RobbieMcKinstry , many thanks for the help and the quick review. I ended up passing the projectName as a property of the current Config object, not sure if there's a better/cleaner approach, so feel free to leave your feedback on this one: 905033c

@miguel-botelho
Copy link
Contributor Author

Another question, how can I test this development on one of my projects?

Copy link
Contributor

@simenandre simenandre left a comment

Choose a reason for hiding this comment

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

I think this looks good!

Thanks for this, I'm sure people will love this addition! Especially the ones with mono-repos with multiple stacks :)

src/main.ts Outdated
@@ -41,6 +41,8 @@ const main = async () => {
? LocalWorkspace.createOrSelectStack(stackArgs, stackOpts)
: LocalWorkspace.selectStack(stackArgs, stackOpts));

config.projectName = (await stack.workspace.projectSettings()).name;
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should split this into two variables?

Suggested change
config.projectName = (await stack.workspace.projectSettings()).name;
const projectSettings = await stack.workspace.projectSettings();
config.projectName = projectSettings.name;

Something like that? Just to improve readability?

Maybe we should add an invariant as well? I'm not sure if we do any validation in projectSettings(), so might not be needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

LGTM! Just committed it here: 1f66ab8

I ended up not adding the invariant as the name property is required inside the ProjectSettings object.

src/config.ts Outdated
@@ -34,6 +34,7 @@ export const config = rt
command: command,
stackName: rt.String,
workDir: rt.String,
projectName: rt.String,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can eliminate the projectName input entirely by relying on this line below:

const projectSettings = await stack.workspace.projectSettings();

We should always be able to get the project name from the config.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the input part and did something similar to the isPullRequest property inside the Config object. Are you suggesting removing the projectName entirely from the Config object and pass it to the handlePullRequest method in another parameter?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, did you push that change? Right now, in the diff, I see the value in Config is always set to the empty string.
My goal is to eliminate partially initialized states in the Config object. As much as possible, that Config object should be immutable:

  1. If at the time of construction, we can access the projectName, then that works.
  2. But if not, I'd prefer passing the projectName field into the handlePullRequest` function.

From the diff I'm seeing, the config object is initialized with an empty string here and that value is overwritten here. I'd prefer if we could avoid this mutation.

Does that help? 😅 Sorry if that's unclear or inconsistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it! I think it's easier to pass projectName as a field on the function as well (and also avoids having a variable with a different value, depending on time of calling). I'll look into it in a bit, commit the changes, and test it as well via the link you sent. I'll notify in here when I've tested it "for real" 👍

@RobbieMcKinstry
Copy link
Contributor

Another question, how can I test this development on one of my projects?

I think you can refer to the public URL and commit SHA (or branch name).

https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-using-versioned-actions

@miguel-botelho miguel-botelho force-pushed the feat/add-optional-project-name branch 2 times, most recently from 9d869e5 to 0df7385 Compare October 19, 2022 09:17
@miguel-botelho miguel-botelho requested review from RobbieMcKinstry and simenandre and removed request for RobbieMcKinstry October 19, 2022 09:22
@miguel-botelho
Copy link
Contributor Author

Hey @cobraz @RobbieMcKinstry 👋
Many thanks for the review and help getting this one figured out. I've made the necessary changes to retrieve the projectName automatically and pass it down to the handlePullRequest method. I also went ahead and compiled the project in this branch (I've already reverted it) to test it on one of our monorepos, and it looks like it's working:

image

Feel free to review it again and leave your feedback on this one 😄

@miguel-botelho miguel-botelho requested review from RobbieMcKinstry and simenandre and removed request for simenandre and RobbieMcKinstry October 19, 2022 09:51
@miguel-botelho
Copy link
Contributor Author

Hey @RobbieMcKinstry , sorry for pinging you again, were you able to review this one? 🙏

@miguel-botelho miguel-botelho force-pushed the feat/add-optional-project-name branch from 43e3945 to f0fd28e Compare November 9, 2022 11:33
@miguel-botelho miguel-botelho force-pushed the feat/add-optional-project-name branch from 3dbdb02 to 007f11b Compare November 9, 2022 11:35
@miguel-botelho
Copy link
Contributor Author

Hey @RobbieMcKinstry , just rebased it with the most recent changes in master, it's good to take a look again 👍

Copy link
Contributor

@RobbieMcKinstry RobbieMcKinstry left a comment

Choose a reason for hiding this comment

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

Thank you for this contribution! I appreciate your thoughtful effort in working through my requested changes and your patience and persistence after I went dark on review. Seriously, thank you @miguel-botelho! 🙇🏻

@RobbieMcKinstry
Copy link
Contributor

@miguel-botelho Would you be willing to send me an email at robbie@pulumi.com? I want to send a small thank-you gift from Pulumi for your contribution.

@RobbieMcKinstry RobbieMcKinstry merged commit a9fe814 into pulumi:master Nov 10, 2022
@miguel-botelho
Copy link
Contributor Author

@miguel-botelho Would you be willing to send me an email at robbie@pulumi.com? I want to send a small thank-you gift from Pulumi for your contribution.

Many thanks! I'll ping you there in a few minutes. Also, I'm the one that should be thanking for guiding me during the review phase 🙇

@RobbieMcKinstry
Copy link
Contributor

Hah, anytime, friend!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cicd impact/reliability Something that feels unreliable or flaky kind/bug Some behavior is incorrect or out of spec
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support multiple editable PR comments: Bug for Monrepos and Matrix Stategy actions
3 participants