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

refactor(manifest): manifest handling cleanup #805

Merged
merged 1 commit into from
Mar 1, 2021

Conversation

joeldodge79
Copy link
Collaborator

@joeldodge79 joeldodge79 commented Feb 26, 2021

  • stronger typing for manifest file: using VersionsMap type
  • cleanup logic around manifest handling:
    1. retrieving manifest - use overload to distinguish between a call
      for the manifest at a specific sha vs at HEAD
    2. clearer logic to handle bootstrapping (i.e. falling back to HEAD
      manifest and then to defaultInitialVersion)
    3. more logging around version determination.
  • switch to using a mock in tests
  • typo fix in lastMergedPRByHeadBranch graphql query

@joeldodge79 joeldodge79 requested a review from a team as a code owner February 26, 2021 21:34
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Feb 26, 2021
@codecov
Copy link

codecov bot commented Feb 26, 2021

Codecov Report

Merging #805 (eb1525b) into master (732e453) will increase coverage by 0.09%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #805      +/-   ##
==========================================
+ Coverage   92.83%   92.92%   +0.09%     
==========================================
  Files          63       63              
  Lines        8573     8683     +110     
  Branches      833      897      +64     
==========================================
+ Hits         7959     8069     +110     
  Misses        611      611              
  Partials        3        3              
Impacted Files Coverage Δ
src/github.ts 89.54% <100.00%> (+<0.01%) ⬆️
src/manifest.ts 96.51% <100.00%> (+1.00%) ⬆️
src/release-pr.ts 93.89% <100.00%> (ø)
src/releasers/go-yoshi.ts 92.70% <100.00%> (ø)
src/releasers/java-bom.ts 92.94% <100.00%> (ø)
src/releasers/java-yoshi.ts 86.98% <100.00%> (ø)
src/releasers/python.ts 100.00% <100.00%> (ø)
src/releasers/rust.ts 94.11% <100.00%> (ø)
src/releasers/terraform-module.ts 91.80% <100.00%> (ø)

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 732e453...bda21fe. Read the comment docs.

Comment on lines +88 to +92
protected async getFile(fileName: string): Promise<GitHubFileContents>;
protected async getFile(
fileName: string,
sha: string
): Promise<GitHubFileContents | undefined>;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I may be abusing overloading here - this getFile function might be trying to do too many different things

  1. getFile('release-please-config.json') - get the config file
  2. getFile('.release-please-manifest.json', 'abc123') - get the manifest at last release sha
  3. getFile('.release-please-manifest.json') - get the manifest at tip of default branch

Instead of breaking it apart I've tried to clarify the different usage with overloads but that might just be silly - I'm still on the fence - happy to receive a nudge either way (keep overloads or break up function into separate helpers)

Copy link
Contributor

Choose a reason for hiding this comment

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

I might just be tempted to add an additional getManifest helper which calls getFile, but understands the sha parameter.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

getManifest is the helper :-)
(overloaded to distinguish between a call for latest manifest version at tip of default branch (no sha) vs manifest from last release (sha required))

}
const releaserOptions = {
monorepoTags: packages.length > 1,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I originally thought this could make the manifest releaser behave exactly like just using a regular releaser on a single package repo (i.e. no need for monorepoTags). But I decided that added too much complexity. So, even though the manifest releaser can be configured on a single package repo, it will still produce the packageName.getComponent() in the tag/release name

Copy link
Contributor

Choose a reason for hiding this comment

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

That seems like the right call to me 100%. I'd honestly like us to move to the stable branch name across the board, because it would make it easier to back port to LTS branches.

}
}
return Object.values(packagesToRelease);
}

private async validateJsonFile<T extends object>(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

now that the manifest file type is VersionsMap it was unwieldy to try to keep this generic. type coercion pushed back into callers

and anyway, hopefully this will get swapped out for ajv soonish...

@@ -186,7 +186,7 @@ export class ReleasePR {
}
}

protected defaultInitialVersion(): string {
defaultInitialVersion(): string {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I log this during the Manifest.pullRequest run so I need it to be public

.withExactArgs('.release-please-manifest.json', lastReleaseSha, false)
.rejects(Object.assign(Error('not found'), {status: 404}));
} else {
mock.expects('getFileContentsWithSimpleAPI').never();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

really appreciating the strictness that mock allows - all though I do wonder if I'm testing the implementation details too closely...

Comment on lines +481 to 512
[
'Found version 3.2.1 for node/pkg1 in ' +
'.release-please-manifest.json at abc123 of main',
CheckpointType.Success,
],
[
'Failed to find version for node/pkg2 in ' +
'.release-please-manifest.json at abc123 of main',
CheckpointType.Failure,
],
[
'Found version 1.2.3 for python in ' +
'.release-please-manifest.json at abc123 of main',
CheckpointType.Success,
],
[
'Bootstrapping from .release-please-manifest.json at tip of main ' +
'for missing paths [node/pkg2]',
CheckpointType.Failure,
],
[
'Failed to find version for node/pkg2 in ' +
'.release-please-manifest.json at tip of main',
CheckpointType.Failure,
],
['Processing package: Node(@node/pkg1)', CheckpointType.Success],
['Processing package: Node(@node/pkg2)', CheckpointType.Success],
[
'Falling back to default version for Node(@node/pkg2): 1.0.0',
CheckpointType.Failure,
],
['Processing package: Python(foolib)', CheckpointType.Success],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I feel like this kind of output will be useful to end-users trying to debug why a package is getting the version it is

- stronger typing for manifest file: using VersionsMap type
- cleanup logic around manifest handling:
  1. retrieving manifest - use overload to distinguish between a call
     for the manifest at a specific sha vs at HEAD
  2. clearer logic to handle bootstrapping (i.e. falling back to HEAD
     manifest and then to defaultInitialVersion)
  3. more logging around version determination.
- switch to using a mock in tests
- typo fix in lastMergedPRByHeadBranch graphql query
@bcoe bcoe merged commit d8ac967 into googleapis:master Mar 1, 2021
@joeldodge79 joeldodge79 deleted the manifest2-switch-to-mocks branch March 1, 2021 21:39
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.

None yet

2 participants