-
Notifications
You must be signed in to change notification settings - Fork 60
fix(ng-dev): publishing fails if pre-release is cut for new minor/major #126
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| /** | ||
| * @license | ||
| * Copyright Google LLC All Rights Reserved. | ||
| * | ||
| * Use of this source code is governed by an MIT-style license that can be | ||
| * found in the LICENSE file at https://angular.io/license | ||
| */ | ||
|
|
||
| import {GitClient} from '../../../utils/git/git-client'; | ||
| import { | ||
| CommitFromGitLog, | ||
| gitLogFormatForParsing, | ||
| parseCommitFromGitLog, | ||
| } from '../../../commit-message/parse'; | ||
| import {computeUniqueIdFromCommitMessage} from './unique-commit-id'; | ||
|
|
||
| /** | ||
| * Gets all commits the head branch contains, but the base branch does not include. | ||
| * This follows the same semantics as Git's double-dot revision range. | ||
| * | ||
| * i.e. `<baseRef>..<headRef>` revision range as per Git. | ||
| * https://git-scm.com/book/en/v2/Git-Tools-Revision-Selection. | ||
| * | ||
| * Branches in the Angular organization are diverging quickly due to multiple factors | ||
| * concerning the versioning and merging. i.e. Commits are cherry-picked into branches, | ||
| * resulting in different SHAs for each branch. Additionally, branches diverge quickly | ||
| * because changes can be made only for specific branches (e.g. a master-only change). | ||
| * | ||
| * In order to allow for comparisons that follow similar semantics as Git's double-dot | ||
| * revision range syntax, the logic re-implementing the semantics need to account for | ||
| * the mentioned semi-diverged branches. We achieve this by excluding commits in the | ||
| * head branch which have a similarly-named commit in the base branch. We cannot rely on | ||
| * SHAs for determining common commits between the two branches (as explained above). | ||
| * | ||
| * More details can be found in the `get-commits-in-range.png` file which illustrates a | ||
| * scenario where commits from the patch branch need to be excluded from the main branch. | ||
| */ | ||
| export function getCommitsForRangeWithDeduping( | ||
| client: GitClient, | ||
| baseRef: string, | ||
| headRef: string, | ||
| ): CommitFromGitLog[] { | ||
| const commits: CommitFromGitLog[] = []; | ||
| const commitsForHead = fetchCommitsForRevisionRange(client, `${baseRef}..${headRef}`); | ||
| const commitsForBase = fetchCommitsForRevisionRange(client, `${headRef}..${baseRef}`); | ||
|
|
||
| // Map that keeps track of commits within the base branch. Commits are | ||
| // stored with an unique id based on the commit message. If a similarly-named | ||
| // commit appears multiple times, the value number will reflect that. | ||
| const knownCommitsOnlyInBase = new Map<string, number>(); | ||
|
|
||
devversion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| for (const commit of commitsForBase) { | ||
| const id = computeUniqueIdFromCommitMessage(commit); | ||
| const numSimilarCommits = knownCommitsOnlyInBase.get(id) ?? 0; | ||
| knownCommitsOnlyInBase.set(id, numSimilarCommits + 1); | ||
| } | ||
|
|
||
| for (const commit of commitsForHead) { | ||
| const id = computeUniqueIdFromCommitMessage(commit); | ||
| const numSimilarCommits = knownCommitsOnlyInBase.get(id) ?? 0; | ||
|
|
||
| // If there is a similar commit in the base branch, the current commit in the head branch | ||
| // needs to be skipped. We keep track of the number of similar commits so that we do not | ||
| // accidentally "dedupe" a commit. e.g. consider a case where commit `X` lands in the | ||
| // patch branch and next branch. Then a similar similarly named commits lands only in the | ||
| // next branch. We would not want to omit that one as it is not part of the patch branch. | ||
| if (numSimilarCommits > 0) { | ||
| knownCommitsOnlyInBase.set(id, numSimilarCommits - 1); | ||
| continue; | ||
| } | ||
|
|
||
| commits.push(commit); | ||
| } | ||
|
|
||
| return commits; | ||
| } | ||
|
|
||
| /** Fetches commits for the given revision range using `git log`. */ | ||
| export function fetchCommitsForRevisionRange( | ||
| client: GitClient, | ||
| revisionRange: string, | ||
| ): CommitFromGitLog[] { | ||
| const splitDelimiter = '-------------ɵɵ------------'; | ||
| const output = client.run([ | ||
| 'log', | ||
| `--format=${gitLogFormatForParsing}${splitDelimiter}`, | ||
| revisionRange, | ||
| ]); | ||
|
|
||
| return output.stdout | ||
| .split(splitDelimiter) | ||
| .filter((entry) => !!entry.trim()) | ||
| .map((entry) => parseCommitFromGitLog(Buffer.from(entry, 'utf-8'))); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /** | ||
| * @license | ||
| * Copyright Google LLC All Rights Reserved. | ||
| * | ||
| * Use of this source code is governed by an MIT-style license that can be | ||
| * found in the LICENSE file at https://angular.io/license | ||
| */ | ||
|
|
||
| import {Commit} from '../../../commit-message/parse'; | ||
|
|
||
| /** | ||
| * Fields from a `Commit` to incorporate when building up an unique | ||
| * id for a commit message. | ||
| * | ||
| * Note: The header incorporates the commit type, scope and message | ||
| * but lacks information for fixup, revert or squash commits.. | ||
| */ | ||
| const fieldsToIncorporateForId: (keyof Commit)[] = ['header', 'isFixup', 'isRevert', 'isSquash']; | ||
|
|
||
| /** | ||
| * Computes an unique id for the given commit using its commit message. | ||
| * This can be helpful for comparisons, if commits differ in SHAs due | ||
| * to cherry-picking. | ||
| */ | ||
| export function computeUniqueIdFromCommitMessage(commit: Commit): string { | ||
| // Join all resolved fields with a special character to build up an id. | ||
| return fieldsToIncorporateForId.map((f) => commit[f]).join('ɵɵ'); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.