X Tutup
Skip to content

Commit 59f7213

Browse files
authored
Merge pull request microsoft#1639 from chaseholland/master
[rush] Fix applying git tags when using --pack --apply-git-tags-on-pack and using publish --include-all
2 parents 38025d9 + efbbee2 commit 59f7213

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

apps/rush-lib/src/cli/actions/PublishAction.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,15 @@ export class PublishAction extends BaseRushAction {
324324
return;
325325
}
326326

327-
// Do not tag packages that already exist. This will fail with a fatal error.
328-
if (this._packageExists(packageConfig)) {
327+
const packageVersion: string = packageConfig.packageJson.version;
328+
329+
// Do not create a new tag if one already exists, this will result in a fatal error
330+
if (git.hasTag(packageConfig)) {
331+
console.log(`Not tagging ${packageName}@${packageVersion}. A tag already exists for this version.`);
329332
return;
330333
}
331334

332-
git.addTag(!!this._publish.value && !this._registryUrl.value, packageName, packageConfig.packageJson.version);
335+
git.addTag(!!this._publish.value, packageName, packageVersion);
333336
updated = true;
334337
};
335338

apps/rush-lib/src/logic/PublishGit.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// See LICENSE in the project root for license information.
33

44
import { PublishUtilities } from './PublishUtilities';
5+
import { Utilities } from '../utilities/Utilities';
6+
import { RushConfigurationProject } from '../api/RushConfigurationProject';
57

68
export class PublishGit {
79
private _targetBranch: string | undefined;
@@ -51,6 +53,22 @@ export class PublishGit {
5153
['tag', '-a', tagName, '-m', `${packageName} v${packageVersion}`]);
5254
}
5355

56+
public hasTag(packageConfig: RushConfigurationProject): boolean {
57+
const tagName: string = PublishUtilities.createTagname(
58+
packageConfig.packageName,
59+
packageConfig.packageJson.version
60+
);
61+
const tagOutput: string = Utilities.executeCommandAndCaptureOutput(
62+
'git',
63+
['tag', '-l', tagName],
64+
packageConfig.projectFolder,
65+
PublishUtilities.getEnvArgs(),
66+
true
67+
).replace(/(\r\n|\n|\r)/gm, '');
68+
69+
return tagOutput === tagName;
70+
}
71+
5472
public commit(commitMessage: string): void {
5573
PublishUtilities.execCommand(!!this._targetBranch, 'git', ['commit', '-m', commitMessage]);
5674
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/rush",
5+
"comment": "Resolve an issue where git tags were not being applied when using pack or publish with --include-all",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush",
10+
"email": "chaseholland@users.noreply.github.com"
11+
}

0 commit comments

Comments
 (0)
X Tutup