Skip to content

Commit 8033206

Browse files
committed
Improve bump command and fix publisher error codes
- Update AutoUpdatedVersions.props even when version was already bumped - Change SuccessCode.Fatal to SuccessCode.Error in publishers - Rename RunClaude.g.ps1 to RunClaude.ps1
1 parent 529918c commit 8033206

File tree

7 files changed

+111
-19
lines changed

7 files changed

+111
-19
lines changed

DockerBuild.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,13 +559,13 @@ if (-not $BuildImage)
559559
{
560560
# Non-interactive mode with prompt - no -it flags
561561
$dockerArgs = @()
562-
$inlineScript = "${substCommandsInline}& c:\Init.g.ps1; ${copyClaudeJsonScript}cd '$SourceDirName'; & .\eng\RunClaude.g.ps1 -Prompt `"$ClaudePrompt`""
562+
$inlineScript = "${substCommandsInline}& c:\Init.g.ps1; ${copyClaudeJsonScript}cd '$SourceDirName'; & .\eng\RunClaude.ps1 -Prompt `"$ClaudePrompt`""
563563
}
564564
else
565565
{
566566
# Interactive mode - requires TTY
567567
$dockerArgs = @("-it")
568-
$inlineScript = "${substCommandsInline}& c:\Init.g.ps1; ${copyClaudeJsonScript}cd '$SourceDirName'; & .\eng\RunClaude.g.ps1"
568+
$inlineScript = "${substCommandsInline}& c:\Init.g.ps1; ${copyClaudeJsonScript}cd '$SourceDirName'; & .\eng\RunClaude.ps1"
569569
}
570570

571571
$dockerArgsAsString = $dockerArgs -join " "

eng/RunClaude.ps1

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# The original of this file is in the PostSharp.Engineering repo.
2+
# You can generate this file using `./Build.ps1 generate-scripts`.
3+
4+
param(
5+
[string]$Prompt
6+
)
7+
8+
$ErrorActionPreference = "Stop"
9+
10+
if ($env:RUNNING_IN_DOCKER -ne "true")
11+
{
12+
Write-Error "This script must be run inside a Docker container. Set RUNNING_IN_DOCKER=true to override."
13+
exit 1
14+
}
15+
16+
Write-Host "Starting Claude CLI..." -ForegroundColor Green
17+
18+
# Run Claude
19+
if ($Prompt)
20+
{
21+
Write-Host "Running Claude with prompt: $Prompt" -ForegroundColor Cyan
22+
claude --dangerously-skip-permissions -p $Prompt
23+
}
24+
else
25+
{
26+
Write-Host "Running Claude in interactive mode" -ForegroundColor Cyan
27+
claude --dangerously-skip-permissions
28+
}
29+
30+
exit $LASTEXITCODE

src/PostSharp.Engineering.BuildTools/Build/Bumping/BumpCommand.cs

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,44 @@ private static bool Execute( BuildContext context, BumpSettings settings )
9494
return false;
9595
}
9696

97+
// Doing a dry run of AutoUpdatedVersionsFile both gets the versions of all dependencies and gets the current version.
98+
// Do not write the AutoUpdatedVersions.props file yet - we will do it after we set our own version.
99+
if ( !AutoUpdatedVersionsFile.TryWrite( context, true, out var hasChangesInDependencies, out var hasChangesInAutoUpdatedVersionsFile, out _, out var currentVersion ) )
100+
{
101+
return false;
102+
}
103+
97104
if ( hasBumpSinceLastDeployment && !settings.OverridePreviousBump )
98105
{
99106
console.WriteWarning( "Version has already been bumped since the last deployment." );
100107

101-
return true;
102-
}
108+
// Even though the version has been bumped, we still need to verify that AutoUpdatedVersions.props is correct.
109+
if ( hasChangesInAutoUpdatedVersionsFile )
110+
{
111+
console.WriteWarning( "AutoUpdatedVersions.props needs to be updated. Updating now." );
103112

104-
// Doing a dry run of AutoUpdatedVersionsFile both gets the versions of all dependencies and gets the current version.
105-
// Do not write the AutoUpdatedVersions.props file yet - we will do it after we set our own version.
106-
if ( !AutoUpdatedVersionsFile.TryWrite( context, true, out var hasChangesInDependencies, out _, out _, out var currentVersion ) )
107-
{
108-
return false;
113+
if ( !AutoUpdatedVersionsFile.TryWrite( context, false, out _, out _, out _, out _ ) )
114+
{
115+
return false;
116+
}
117+
118+
// Commit the changes.
119+
if ( !GitIntegrationHelper.TryCommitAutoUpdatedVersions( context ) )
120+
{
121+
return false;
122+
}
123+
124+
// If we are running in TeamCity, push.
125+
if ( context.IsContinuousIntegrationBuild )
126+
{
127+
if ( !GitHelper.TryPush( context ) )
128+
{
129+
return false;
130+
}
131+
}
132+
}
133+
134+
return true;
109135
}
110136

111137
if ( !hasChangesInDependencies && !hasChangesSinceLastDeployment )

src/PostSharp.Engineering.BuildTools/Build/Helpers/GitIntegrationHelper.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,42 @@ public static bool TryCommitVersionBump( BuildContext context, Version? currentV
119119
return true;
120120
}
121121

122+
/// <summary>
123+
/// Commits only the AutoUpdatedVersions.props file without bumping the main version.
124+
/// Used when the version has already been bumped but AutoUpdatedVersions.props needs updating.
125+
/// </summary>
126+
public static bool TryCommitAutoUpdatedVersions( BuildContext context )
127+
{
128+
var product = context.Product;
129+
130+
// Adds updated AutoUpdatedVersions.props to Git staging area.
131+
if ( !ToolInvocationHelper.InvokeTool(
132+
context.Console,
133+
"git",
134+
$"add {product.AutoUpdatedVersionsFilePath}",
135+
context.RepoDirectory ) )
136+
{
137+
return false;
138+
}
139+
140+
// Gets the remote origin.
141+
if ( !GitHelper.TryGetRemoteUrl( context, out var gitOrigin ) )
142+
{
143+
return false;
144+
}
145+
146+
if ( !ToolInvocationHelper.InvokeTool(
147+
context.Console,
148+
"git",
149+
"commit -m \"<<AUTO_UPDATED_VERSIONS>>\"",
150+
context.RepoDirectory ) )
151+
{
152+
return false;
153+
}
154+
155+
return true;
156+
}
157+
122158
internal static bool TryAnalyzeGitHistory(
123159
BuildContext context,
124160
MainVersionFile mainVersionFile,

src/PostSharp.Engineering.BuildTools/Build/Publishing/GitRepoPublisher.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public override SuccessCode PublishFile(
7272
{
7373
console.WriteError( "Failed to clone the repository." );
7474

75-
return SuccessCode.Fatal;
75+
return SuccessCode.Error;
7676
}
7777

7878
// Delete all files in the repo except .git directory.
@@ -113,7 +113,7 @@ public override SuccessCode PublishFile(
113113
{
114114
console.WriteError( "Failed to get git status." );
115115

116-
return SuccessCode.Fatal;
116+
return SuccessCode.Error;
117117
}
118118

119119
var changes = statusOutput.Split( '\n', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries );
@@ -136,7 +136,7 @@ public override SuccessCode PublishFile(
136136
{
137137
console.WriteError( "Failed to stage changes." );
138138

139-
return SuccessCode.Fatal;
139+
return SuccessCode.Error;
140140
}
141141

142142
// Commit the changes.
@@ -151,7 +151,7 @@ public override SuccessCode PublishFile(
151151
{
152152
console.WriteError( "Failed to commit changes." );
153153

154-
return SuccessCode.Fatal;
154+
return SuccessCode.Error;
155155
}
156156

157157
// Push to remote (skip in dry mode).
@@ -172,7 +172,7 @@ public override SuccessCode PublishFile(
172172
{
173173
console.WriteError( "Failed to push changes to remote repository." );
174174

175-
return SuccessCode.Fatal;
175+
return SuccessCode.Error;
176176
}
177177

178178
console.WriteSuccess( $"Successfully published '{file}' to '{gitHubUrl}'." );
@@ -184,7 +184,7 @@ public override SuccessCode PublishFile(
184184
{
185185
console.WriteError( $"Error publishing to git repository: {e.Message}" );
186186

187-
return SuccessCode.Fatal;
187+
return SuccessCode.Error;
188188
}
189189
finally
190190
{

src/PostSharp.Engineering.BuildTools/Build/Publishing/S3Publisher.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public override SuccessCode PublishFile(
8080
{
8181
context.Console.WriteError( "AmazonS3Client failed to publish the file." );
8282

83-
return SuccessCode.Fatal;
83+
return SuccessCode.Error;
8484
}
8585

8686
return SuccessCode.Success;
@@ -91,15 +91,15 @@ public override SuccessCode PublishFile(
9191
"AWS S3 error encountered. Message:'{0}' when writing an object",
9292
e.Message );
9393

94-
return SuccessCode.Fatal;
94+
return SuccessCode.Error;
9595
}
9696
catch ( Exception e )
9797
{
9898
context.Console.WriteError(
9999
"Unknown error encountered. Message:'{0}' when writing an object",
100100
e.Message );
101101

102-
return SuccessCode.Fatal;
102+
return SuccessCode.Error;
103103
}
104104
}
105105
}

src/PostSharp.Engineering.BuildTools/ContinuousIntegration/GenerateScriptsCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static bool Execute( BuildContext context, CommonCommandSettings settings
3232
if ( product.UseDocker )
3333
{
3434
EmbeddedResourceHelper.ExtractScript( context, "DockerBuild.ps1", "" );
35-
EmbeddedResourceHelper.ExtractScript( context, "RunClaude.g.ps1", "eng" );
35+
EmbeddedResourceHelper.ExtractScript( context, "RunClaude.ps1", "eng" );
3636
var image = (ContainerRequirements) product.OverriddenBuildAgentRequirements!;
3737

3838
if ( !image.WriteDockerfile( context ) )

0 commit comments

Comments
 (0)