Skip to content

Commit 7651b64

Browse files
[xa-prep-tasks] fix build errors for long darc- branch names (#9740)
Context: #9732 PR #9732 failed with: NuGet.Build.Tasks.Pack.targets(221,5): error NU5123: Warning As Error: The file 'package/services/metadata/core-properties/027a96e260344b159133798c830dab61.psmdcp' path, name, or both are too long. Your package might not work without long file path support. Please shorten the file path or file name. The branch name is 68 characters long: darc-release/10.0.1xx-preview1-94740166-a85b-4349-9dd7-c8274168049c Update the `<GitBranch/>` MSBuild task to substring long `darc-` branch names to avoid this problem. I found even 50 characters was causing the issue, so I chose 32.
1 parent 18af3ac commit 7651b64

File tree

1 file changed

+17
-5
lines changed
  • build-tools/xa-prep-tasks/Xamarin.Android.BuildTools.PrepTasks

1 file changed

+17
-5
lines changed

build-tools/xa-prep-tasks/Xamarin.Android.BuildTools.PrepTasks/GitBranch.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public override bool Execute ()
3232
if (!string.IsNullOrEmpty (build_sourcebranchname) && build_sourcebranchname.IndexOf ("merge", StringComparison.OrdinalIgnoreCase) == -1) {
3333
Branch = build_sourcebranchname.Replace ("refs/heads/", string.Empty);
3434
Log.LogMessage ($"Using BUILD_SOURCEBRANCH value: {Branch}");
35-
return true;
35+
goto done;
3636
}
3737

3838
string gitHeadFile = Path.Combine (WorkingDirectory.ItemSpec, ".git", "HEAD");
@@ -48,15 +48,27 @@ public override bool Execute ()
4848
base.Execute ();
4949
}
5050

51+
done:
52+
CheckBranchLength ();
53+
Log.LogMessage (MessageImportance.Low, $" [Output] {nameof (Branch)}: {Branch}");
54+
return !Log.HasLoggedErrors;
55+
}
56+
57+
void CheckBranchLength ()
58+
{
5159
// Trim generated dependabot branch names that are too long to produce useful package names
60+
const int maxBranchLength = 32;
5261
var lastSlashIndex = Branch.LastIndexOf ('/');
53-
if (Branch.StartsWith ("dependabot") && lastSlashIndex != -1 && Branch.Length > 60) {
62+
if (Branch.StartsWith ("dependabot") && lastSlashIndex != -1 && Branch.Length > maxBranchLength) {
63+
Log.LogMessage ($"Trimming characters from the branch name at index {lastSlashIndex}: {Branch}");
5464
Branch = Branch.Substring (lastSlashIndex + 1);
5565
}
5666

57-
Log.LogMessage (MessageImportance.Low, $" [Output] {nameof (Branch)}: {Branch}");
58-
59-
return !Log.HasLoggedErrors;
67+
// Trim darc/Maestro branch names that are too long
68+
if (Branch.StartsWith ("darc-") && Branch.Length > maxBranchLength) {
69+
Log.LogMessage ($"Trimming to {maxBranchLength} characters from the branch name: {Branch}");
70+
Branch = Branch.Substring (0, maxBranchLength);
71+
}
6072
}
6173

6274
protected override string GenerateCommandLineCommands ()

0 commit comments

Comments
 (0)