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(manifest): node workspace package dependency updates #844

Merged
merged 6 commits into from
Apr 9, 2021

Conversation

joeldodge79
Copy link
Collaborator

Introduces the concept of a "plugin" that can run after release-please
has generated changes but before the PR is created.

In order to support plugin releaser-post-processing (before submitting
the PR) we want to provide the whole contents of the changed file to the
plugin.

@joeldodge79 joeldodge79 requested review from bcoe and a team March 29, 2021 21:28
@joeldodge79 joeldodge79 requested a review from a team as a code owner March 29, 2021 21:28
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Mar 29, 2021
@codecov
Copy link

codecov bot commented Mar 29, 2021

Codecov Report

Merging #844 (d679c1c) into master (6f24661) will increase coverage by 0.29%.
The diff coverage is 98.80%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #844      +/-   ##
==========================================
+ Coverage   93.78%   94.07%   +0.29%     
==========================================
  Files          64       68       +4     
  Lines        9218     9809     +591     
  Branches      939     1014      +75     
==========================================
+ Hits         8645     9228     +583     
- Misses        570      578       +8     
  Partials        3        3              
Impacted Files Coverage Δ
src/manifest.ts 98.94% <93.44%> (-1.06%) ⬇️
src/github.ts 90.13% <100.00%> (+0.01%) ⬆️
src/index.ts 100.00% <100.00%> (ø)
src/plugins/index.ts 100.00% <100.00%> (ø)
src/plugins/node-workspace.ts 100.00% <100.00%> (ø)
src/plugins/plugin.ts 100.00% <100.00%> (ø)
src/updaters/package-json.ts 100.00% <100.00%> (ø)
src/util/package-json-stringify.ts 100.00% <100.00%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6f24661...d679c1c. Read the comment docs.

Copy link
Collaborator Author

@joeldodge79 joeldodge79 left a comment

Choose a reason for hiding this comment

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

@bcoe this is the behemoth PR that represents that last piece of functionality we need for the looker-open-source/sdk-codegen release requirements. not my usual style to drop a 3K LOC PR but, well, here it is (and 2/3rds of the LOC is test code).

I could split it up if you'd like but I think it's at least useful to see the whole picture. I left a bunch of inline comments as a guide

src/github.ts Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
src/manifest.ts Show resolved Hide resolved
src/manifest.ts Show resolved Hide resolved
src/manifest.ts Show resolved Hide resolved
return changelogUpdater.updateContent(changelog);
}

private async setChangelogEntry(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

all this changelog entry manipulation got a bit exasperating at the end but it seems to work pretty well now. There may be a better way of doing it but I was just trying to jam through to the finish line... really wanted to see changelog entries for lerna-based dependency updates.

Copy link
Contributor

Choose a reason for hiding this comment

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

See comment about us moving towards a better markdown generator that actually understands the tree.

src/plugins/plugin.ts Outdated Show resolved Hide resolved
src/util/package-json-stringify.ts Show resolved Hide resolved
test/helpers.ts Outdated Show resolved Hide resolved
test/helpers.ts Outdated Show resolved Hide resolved
@joeldodge79 joeldodge79 force-pushed the node-package-depenedency-updates-with-lerna branch 2 times, most recently from 8491fb1 to 62e3988 Compare March 30, 2021 22:12
Copy link
Contributor

@bcoe bcoe left a comment

Choose a reason for hiding this comment

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

Left some initial comments.

The big thing that jumps out at me, is that the assertions are getting pretty large when confirming actualChanges. For what is partially text content like this, I feel this is where snpshots can really shine.

Here are the snapshots I use for c8, our test coverage library. I feel like they read very well, and it's clear when they beak -- perhaps the problem with the snapshots in relese-please is just that we need a helper for structured objects, that helps output their contents in a format that's slightly more diffable?

package.json Outdated
@@ -51,6 +51,7 @@
"@types/yargs": "^16.0.0",
"c8": "^7.0.0",
"chai": "^4.2.0",
"chai-better-shallow-deep-equal": "^1.1.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

When possible, I'd rather use the built in assert.strictDeepEqual, I like trying to dogfood Node.js with as few dependencies as possible.

@@ -61,9 +62,14 @@
"dependencies": {
"@conventional-commits/parser": "^0.4.1",
"@iarna/toml": "^2.2.5",
"@lerna/collect-updates": "^4.0.0",
"@lerna/package": "^3.16.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

It's nice that lerna is decomposed like this.

// 3. currently unsupported but possible future support:
// - `snapshot`
// - `label`
export type ManifestPackage = Pick<
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the use of Pick here, my colleague @SurferJeffAtGoogle was walking me through some of these advanced TypeScript features the other day.

src/index.ts Outdated Show resolved Hide resolved
src/manifest.ts Show resolved Hide resolved
src/plugins/index.ts Show resolved Hide resolved
return changelogUpdater.updateContent(changelog);
}

private async setChangelogEntry(
Copy link
Contributor

Choose a reason for hiding this comment

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

See comment about us moving towards a better markdown generator that actually understands the tree.

@@ -2049,4 +2049,80 @@ describe('Manifest', () => {
});
}
});

describe('plugins', () => {
it('runs the node-workspace plugin', async function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

A few additional comments in this test would help me. Shouldn't we see @pkg2 being updated as well since it depends on @pkg1 which was updated? I only see updates for @pkg1 and python.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if you look at the snapshot it captured the @pkg2 updates. Perhaps confusing because I'm only checking the logging that Manifest is performing here, not any logging the plugin is doing. Given how the plugin is instantiated via the config it's hard to inject a logger (though I could probably stub it). Or I could just remove the Manifest logging for this test case to avoid confusion.

I'll get around to moving the logging out of this file into the snapshot too at some point.

'\n\nAll notable changes to this project will be ' +
'documented in this file.' +
'\n\n### [2.2.3](https://www.github.com/fake/repo/compare' +
'/pkgB-v2.2.2...pkgB-v2.2.3) (1983-10-10)' +
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 that these assertions are going to become a bit fragile, as even subtle changes to the markdown generation will lead to a bunch of fiddling in tests.

Having confirmed the behavior manually (i.e., now that you trust the approach), I would be tempted to move the assertion into a snapshot -- at which point, we should just see small stylistic differences in the snapshot as changes are made to content.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

absolutely. converted the log tracking and the changes to snapshots


/**
* skeleton only representing what we use.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we pull any of these typings in from DefinitelyTyped rather than floating them ourselves?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They don't currently exist there. What I've added here is pretty sparse coverage for the relevant packages. I was hoping to avoid taking on the load of publishing them there which I feel like would require a more comprehensive effort (also, never done it before...)

Copy link
Contributor

@chingor13 chingor13 left a comment

Choose a reason for hiding this comment

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

Can you add an expected usage example for this feature?

Is the plugin a Javascript/Typescript function in the release repo? or in the release-please repo?

@joeldodge79
Copy link
Collaborator Author

@chingor13

Can you add an expected usage example for this feature

I can add documentation on how to use this for sure. I wanted to get it out for some initial feedback first though in case it needs to change significantly before writing up a doc

Yes, the "plugin" exists in the release-please repo (currently just the one: src/plugins/node-workspace.ts

In the real world I've used this for our looker-open-source/sdk-codegen release PR. Here the node-workspace plugin correctly updated all our intra-monorepo-package-dependencies and added corresponding changelog entries.

@bcoe I think I've covered your initial around of feedback (mostly converting to snapshots).

@joeldodge79 joeldodge79 force-pushed the node-package-depenedency-updates-with-lerna branch from bde90b7 to 04d732d Compare April 5, 2021 21:20
@joeldodge79 joeldodge79 requested a review from bcoe April 5, 2021 21:20

const sandbox = sinon.createSandbox();

function stringifyActual(actual: ManifestPackageWithPRData[]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the approach of using this stringifyActual helper 👍

Copy link
Contributor

@bcoe bcoe left a comment

Choose a reason for hiding this comment

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

This is looking good to me, pending @chingor13's comments.

@joeldodge79
Copy link
Collaborator Author

@chingor13 I added a section to the manifest docs

Copy link
Contributor

@bcoe bcoe left a comment

Choose a reason for hiding this comment

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

Small nit about README, I think this is looking good though.

Unlike the individual releasers, which only have the context of the source files
relevant to one package, a plugin receives all the current changes for all
updated packages as well as the configuration containing every package. One
place this is particularly useful is for monorepos that have intra-repo local
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 it would be worth breaking this paragraph in half, the first half can talk about how the plugins work:

  • what they're passed, and what they should output.

In this section I'd then have a code snippet that demonstrates the tiniest potential plugin that someone might right, e.g,. adding one additional update? it can be a toy example.

The second paragraph can then describe why plugins would be useful, exactly as you have right now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

let me know what you think of my num-packages plugin :-)

joeldodge79 and others added 5 commits April 9, 2021 14:16
Introduces the concept of a "plugin" that can run after release-please
has generated changes but before the PR is created.

In order to support plugin releaser-post-processing (before submitting
the PR) we want to provide the whole contents of the changed file to the
plugin.
@joeldodge79 joeldodge79 force-pushed the node-package-depenedency-updates-with-lerna branch from 5e8dc9c to a99a535 Compare April 9, 2021 15:25
@joeldodge79 joeldodge79 requested a review from bcoe April 9, 2021 15:26
@bcoe bcoe merged commit 9ebd422 into master Apr 9, 2021
@bcoe bcoe deleted the node-package-depenedency-updates-with-lerna branch April 9, 2021 22:34
@joeldodge79
Copy link
Collaborator Author

thanks for landing this @bcoe

Are there any docs on local/branch testing release-please changes in the action? I want to test the dynamic importing of plugins in the action and make changes if needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants