From 1cde18bd446196549d0704a2cabfc11e1654b56c Mon Sep 17 00:00:00 2001 From: Jonathan Pobst Date: Wed, 8 Jan 2025 09:34:47 -1000 Subject: [PATCH] [ci] Fail build if any git tracked files were modified. --- .../yaml-templates/build-linux.yaml | 4 ++++ .../yaml-templates/build-macos.yaml | 4 ++++ .../yaml-templates/build-windows.yaml | 2 ++ .../yaml-templates/fail-on-dirty-tree.yaml | 22 +++++++++++++++++++ .../xaprepare/Steps/Step_ThirdPartyNotices.cs | 2 +- 5 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 build-tools/automation/yaml-templates/fail-on-dirty-tree.yaml diff --git a/build-tools/automation/yaml-templates/build-linux.yaml b/build-tools/automation/yaml-templates/build-linux.yaml index 29f35e1907d..6e098e9bb40 100644 --- a/build-tools/automation/yaml-templates/build-linux.yaml +++ b/build-tools/automation/yaml-templates/build-linux.yaml @@ -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 diff --git a/build-tools/automation/yaml-templates/build-macos.yaml b/build-tools/automation/yaml-templates/build-macos.yaml index 0a29943c4d8..c13fc2ef93f 100644 --- a/build-tools/automation/yaml-templates/build-macos.yaml +++ b/build-tools/automation/yaml-templates/build-macos.yaml @@ -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 }} diff --git a/build-tools/automation/yaml-templates/build-windows.yaml b/build-tools/automation/yaml-templates/build-windows.yaml index 0a69a37b602..832cddfbede 100644 --- a/build-tools/automation/yaml-templates/build-windows.yaml +++ b/build-tools/automation/yaml-templates/build-windows.yaml @@ -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 diff --git a/build-tools/automation/yaml-templates/fail-on-dirty-tree.yaml b/build-tools/automation/yaml-templates/fail-on-dirty-tree.yaml new file mode 100644 index 00000000000..866e460669c --- /dev/null +++ b/build-tools/automation/yaml-templates/fail-on-dirty-tree.yaml @@ -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 }} diff --git a/build-tools/xaprepare/xaprepare/Steps/Step_ThirdPartyNotices.cs b/build-tools/xaprepare/xaprepare/Steps/Step_ThirdPartyNotices.cs index 6b28b261528..47c2690e4cb 100644 --- a/build-tools/xaprepare/xaprepare/Steps/Step_ThirdPartyNotices.cs +++ b/build-tools/xaprepare/xaprepare/Steps/Step_ThirdPartyNotices.cs @@ -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)