Skip to content

Commit c86ae26

Browse files
authored
[ci] Fail build if any git tracked files were modified. (#1288)
Context: dotnet/android@208c529 Scenarios where the build unintentionally modifies git tracked files on some platforms are frustrating, so let's prevent them from happening in the first place. Add a CI check to fail a build if any git tracked files were modified. Also contains a fix for the `<GenAPITask/>` task, which always generates files with Windows line endings, which causes `git status` to show the file as modified on other platforms.
1 parent 4f06201 commit c86ae26

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

build-tools/automation/azure-pipelines.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ jobs:
6161
nativeAotRid: win-x64
6262
platformName: .NET - Windows
6363

64+
- template: templates\fail-on-dirty-tree.yaml
65+
6466
- template: templates\fail-on-issue.yaml
6567

6668
- task: PublishPipelineArtifact@1
@@ -92,6 +94,8 @@ jobs:
9294
nativeAotRid: osx-x64
9395
platformName: .NET - MacOS
9496

97+
- template: templates\fail-on-dirty-tree.yaml
98+
9599
- template: templates\fail-on-issue.yaml
96100

97101

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Ensure the build did not produce any modified checked in files
2+
3+
parameters:
4+
condition: succeeded()
5+
6+
steps:
7+
- powershell: |
8+
# Run this to log the output for the user
9+
git status
10+
11+
# Run this to error the build if untracked files
12+
$process= git status --porcelain --untracked-files=no
13+
14+
if ($process)
15+
{
16+
Write-Host "##vso[task.logissue type=error]git tree has modified tracked files."
17+
Write-Host "##vso[task.complete result=Failed;]"
18+
}
19+
20+
git diff
21+
displayName: Ensure no modified committed files
22+
condition: ${{ parameters.condition }}

src/Java.Base/Java.Base.targets

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,18 @@
8484
</PropertyGroup>
8585
</Target>
8686

87+
<!--
88+
The <GenAPITask/> task always generates files with WIndows line endings,
89+
which causes `git status` to show the file as modified.
90+
91+
Update `$(GenAPITargetPath)` so that it contains Unix line endings..
92+
-->
93+
<Target Name="_FixGenApiLineEndings"
94+
Condition=" !$([MSBuild]::IsOSPlatform ('windows')) "
95+
AfterTargets="GenerateReferenceAssemblySource">
96+
<Move SourceFiles="$(GenAPITargetPath)" DestinationFiles="$(GenAPITargetPath).crlf" />
97+
<Exec Command="tr -d '\015' &lt; $(GenAPITargetPath).crlf > $(GenAPITargetPath)" />
98+
<Delete Files="$(GenAPITargetPath).crlf" />
99+
</Target>
100+
87101
</Project>

0 commit comments

Comments
 (0)