Skip to content

Commit

Permalink
[ci] Fail build if any git tracked files were modified. (#9661)
Browse files Browse the repository at this point in the history
When running `xaprepare` on Windows, your local `git` tree ends up
dirty due to line ending changes in `THIRD-PARTY-NOTICES.txt`.

Update `xaprepare` to always normalize line endings to
`Environment.NewLine` in `THIRD-PARTY-NOTICES.txt` to prevent
this issue.

Additionally, these 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.

Example:

> ❌ **git gree has modified tracked files.**

![image](https://github.com/user-attachments/assets/ec8869f5-75a5-4234-b7f4-20c2cabd743e)

Clicking the error will show the modified file(s):

>     "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInte…
>     HEAD detached at b1a5f77
>     Changes not staged for commit:
>       (use "git add ‹file›..." to update what will be committed)
>       (use "git restore ‹file›..." to discard changes in working directory)
>            modified:  THIRD-PARTY-NOTICES. TXT
>     …
>     ##[error]git tree has modified tracked files.

![image](https://github.com/user-attachments/assets/395ee30e-8a37-450c-94ec-106221c40db3)
  • Loading branch information
jpobst authored Jan 9, 2025
1 parent c4a6a9a commit 208c529
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
4 changes: 4 additions & 0 deletions build-tools/automation/yaml-templates/build-linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,8 @@ stages:
includeBuildResults: true
use1ESTemplate: ${{ parameters.use1ESTemplate }}

- template: /build-tools/automation/yaml-templates/fail-on-dirty-tree.yaml
parameters:
xaSourcePath: $(System.DefaultWorkingDirectory)/xamarin-android

- template: /build-tools/automation/yaml-templates/fail-on-issue.yaml
4 changes: 4 additions & 0 deletions build-tools/automation/yaml-templates/build-macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,7 @@ stages:
artifactName: ${{ parameters.buildResultArtifactName }}
includeBuildResults: true
use1ESTemplate: ${{ parameters.use1ESTemplate }}

- template: /build-tools/automation/yaml-templates/fail-on-dirty-tree.yaml
parameters:
xaSourcePath: ${{ parameters.xaSourcePath }}
2 changes: 2 additions & 0 deletions build-tools/automation/yaml-templates/build-windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,6 @@ stages:
artifactName: ${{ parameters.buildResultArtifactName }}
includeBuildResults: true

- template: /build-tools/automation/yaml-templates/fail-on-dirty-tree.yaml

- template: /build-tools/automation/yaml-templates/fail-on-issue.yaml
22 changes: 22 additions & 0 deletions build-tools/automation/yaml-templates/fail-on-dirty-tree.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Ensure the build did not produce any modified checked in files

parameters:
condition: succeeded()
xaSourcePath:

steps:
- powershell: |
# Run this to log the output for the user
git status
# Run this to error the build if untracked files
$process= git status --porcelain --untracked-files=no
if ($process)
{
Write-Host "##vso[task.logissue type=error]git tree has modified tracked files."
Write-Host "##vso[task.complete result=Failed;]"
}
displayName: Ensure no modified committed files
workingDirectory: ${{ parameters.xaSourcePath }}
condition: ${{ parameters.condition }}
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ string FetchTPNLicense (string relativeFilePath)
if (!File.Exists (path))
throw new InvalidOperationException ($"License file {path} does not exist");

return File.ReadAllText (path);
return File.ReadAllText (path).ReplaceLineEndings ();
}

void EnsureValidTPNType (Type type)
Expand Down

0 comments on commit 208c529

Please sign in to comment.