Skip to content

Update release spec to only list changed packages #23

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

Merged
merged 16 commits into from
Sep 30, 2022

Conversation

mcmire
Copy link
Contributor

@mcmire mcmire commented Jul 27, 2022

This PR adds a new property to the Package object,
hasChangesSinceLatestRelease. This property is computed when a package
is read from a project by running a diff between the last-created Git
tag associated with that package and whatever the HEAD commit happens to
be, then checking to see whether any of the files changed belong to that
package. If they do, then hasChangesSinceLatestRelease is true,
otherwise it's false. This property is then used to filter the list of
packages that are placed within the release spec template when it is
generated.

There are a couple of things to consider here:

  • "the last-created Git tag associated with that package" — how do we
    know this? How do we map a package's version to a tag? We have to
    account for tags that were created by action-create-release-pr in the
    past as well as the tags that this tool will create in the future. We
    also have to know what kind of package this is — whether it's the root
    package of a monorepo or a workspace package — because the set of
    possible tags will differ. These differences are documented in
    readMonorepoRootPackage and readMonorepoWorkspacePackage.
  • What happens if a repo has no tags? Then all of the packages in that
    repo are considered to have changed, as they have yet to receive their
    initial release, so they will all be included in the release spec
    template.

Fixes #8.

@mcmire mcmire requested a review from a team as a code owner July 27, 2022 05:35
@mcmire mcmire marked this pull request as draft July 29, 2022 17:16
@mcmire mcmire self-assigned this Jul 29, 2022
@mcmire
Copy link
Contributor Author

mcmire commented Jul 29, 2022

include-build-number-in-version needs to be merged into this and conflicts need to be resolved. Done!

@mcmire
Copy link
Contributor Author

mcmire commented Sep 8, 2022

Rebased!

@Gudahtt Gudahtt linked an issue Sep 9, 2022 that may be closed by this pull request
Base automatically changed from include-build-number-in-version to main September 22, 2022 19:34
@mcmire mcmire force-pushed the only-list-changed-packages branch from 34ccbf1 to 3b55821 Compare September 22, 2022 19:58
@mcmire
Copy link
Contributor Author

mcmire commented Sep 22, 2022

This has been rebased again and is now ready for review.

@mcmire mcmire marked this pull request as ready for review September 22, 2022 19:59
This PR adds a new property to the Package object,
`hasChangesSinceLatestRelease`. This property is computed when a package
is read from a project by running a diff between the last-created Git
tag associated with that package and whatever the HEAD commit happens to
be, then checking to see whether any of the files changed belong to that
package. If they do, then `hasChangesSinceLatestRelease` is true,
otherwise it's false. This property is then used to filter the list of
packages that are placed within the release spec template when it is
generated.

There are a couple of things to consider here:

* "the last-created Git tag associated with that package" — how do we
know this? How do we map a package's version to a tag? We have to
account for tags that were created by `action-create-release-pr` in the
past as well as the tags that this tool will create in the future. We
also have to know what kind of package this is — whether it's the root
package of a monorepo or a workspace package — because the set of
possible tags will differ. These differences are documented in
`readMonorepoRootPackage` and `readMonorepoWorkspacePackage`.
* What happens if a repo has no tags? Then all of the packages in that
repo are considered to have changed, as they have yet to receive their
initial release, so they will all be included in the release spec
template.
@mcmire mcmire force-pushed the only-list-changed-packages branch from 3b55821 to 00b7396 Compare September 22, 2022 20:28
src/package.ts Outdated
generateMonorepoRootPackageReleaseTagNames(rootPackageVersion.toString());
const tagNameMatchingLatestRelease = [
...expectedWorkspacePackageReleaseTagNames,
...expectedRootPackageReleaseTagNames,
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps it's worth printing a console warning if the fallback root tag is used? This should only happen in rare circumstances, like when using this tool for the first time on a monorepo that didn't previously have workspace tags (or at least not in the expected format).

A warning might hint that something is amiss if this happens outside of that scenario.

Copy link
Contributor Author

@mcmire mcmire Sep 29, 2022

Choose a reason for hiding this comment

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

If we display a message to the user, I'd like it to be helpful and include a suggestion as to how they can resolve the problem, but I'm curious what that suggestion would be, because I think it differs based on whether this is the first time this tool is being used on a monorepo or not. If it is not the first time, then we can presume that all packages have been tagged properly, and so if the current release for any given package does not have the tag we expect, that is an anomaly and should be corrected. However, if it is the first time, then we can presume that no releases for any of the packages in the monorepo have tags at all, so in that case, if we say that the current release for a given package needs to be tagged properly, we might as well say that ALL releases for a given package need to be tagged properly.

So, it seems that either we need a way to tell whether this is the first time a user is using this tool, and only show this warning if it is not the first time, or we need to always show this warning, but offer another tool the user can use which will validate that all releases for all packages have proper tags and backfill them if necessary.

Thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

Originally I was thinking the user would just want to know the fallback occurred, since as you point out it's not necessarily a problem or something that is actionable.

If we can do better, that would be great. I'll give this some thought.

Copy link
Member

Choose a reason for hiding this comment

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

If it is not the first time, then we can presume that all packages have been tagged properly, and so if the current release for any given package does not have the tag we expect, that is an anomaly and should be corrected.

Yes, agreed. We could even throw an error in this case, this should never happen. That would be an improvement. It's distinct from the suggestion I meant to make here though.

However, if it is the first time, then we can presume that no releases for any of the packages in the monorepo have tags at all, so in that case, if we say that the current release for a given package needs to be tagged properly, we might as well say that ALL releases for a given package need to be tagged properly.

If we're just starting to use this tool, I don't think we can make any assumptions about tags. We don't know what convention, if any, they were using before.

To be clear, I was suggesting that we warn in the case where we find a root monorepo tag but not a workspace tag. We proceed silently in that circumstance in this PR at the moment.

This seems worth highlighting so that the user understands it's happening, even just for auditability. For example, if there were unpublished changes in a workspace that predate the most recent root tag, they would be missed because of us using this fallback. I don't think this scenario is likely, nor do I think it makes sense necessarily to force the user to manually add tags. But calling out that it's happening might leave an audit trail to follow up on if it happens and someone is confused as to why.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough! Added warning in 565c2a5.

@Gudahtt
Copy link
Member

Gudahtt commented Sep 29, 2022

Generally this looks good! I left some comments on minor problems, and left one suggestion.

Gudahtt
Gudahtt previously approved these changes Sep 29, 2022
Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM! one suggestion thread pending but it's non-blocking

Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM!

@mcmire mcmire merged commit 7d545df into main Sep 30, 2022
@mcmire mcmire deleted the only-list-changed-packages branch September 30, 2022 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Monorepo flow: When generating a release spec, only list changed packages
2 participants