Skip to content

Commit

Permalink
[Validate-TypeSpec.ps1] Add GitClean switch (#24933)
Browse files Browse the repository at this point in the history
- Continuation of #24629
  • Loading branch information
ckairen authored Jul 21, 2023
1 parent f8e61c6 commit 94144ac
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion eng/pipelines/typespec-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ jobs:
condition: succeededOrFailed()

- pwsh: |
$(Build.SourcesDirectory)/eng/scripts/Validate-TypeSpec.ps1 $(Build.SourcesDirectory)
$(Build.SourcesDirectory)/eng/scripts/Validate-TypeSpec.ps1 $(Build.SourcesDirectory) -GitClean
displayName: Validate All Specs
condition: succeededOrFailed()
3 changes: 2 additions & 1 deletion eng/pipelines/typespec-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
$(Build.SourcesDirectory)/eng/scripts/Validate-TypeSpec.ps1 `
$(Build.SourcesDirectory) `
"origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH}" `
"${env:SYSTEM_PULLREQUEST_SOURCECOMMITID}"
"${env:SYSTEM_PULLREQUEST_SOURCECOMMITID}" `
-GitClean
displayName: Validate Impacted Specs
condition: succeededOrFailed()
3 changes: 3 additions & 0 deletions eng/scripts/Get-TypeSpec-Folders.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ $allChangedFiles = (Get-ChildItem -path ./specification tspconfig.yaml -Recurse)
$allChangedFiles = $allChangedFiles -replace '\\', '/'

if ([string]::IsNullOrEmpty($TargetBranch) -or [string]::IsNullOrEmpty($SourceBranch)) {
if ($TargetBranch -or $SourceBranch) {
throw "Please provide both target branch and source branch."
}
$changedFiles = $allChangedFiles
}
else {
Expand Down
12 changes: 9 additions & 3 deletions eng/scripts/Validate-TypeSpec.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ param (
[Parameter(Position = 1, Mandatory = $false)]
[string]$TargetBranch,
[Parameter(Position = 2, Mandatory = $false)]
[string]$SourceBranch
[string]$SourceBranch,
[Parameter(Mandatory = $false)]
[switch]$GitClean
)

$exitCode = 0
Expand All @@ -25,8 +27,12 @@ if ($typespecFolders) {
if ($LASTEXITCODE) {
$exitCode = 1
}
git restore .
git clean -df
if ($GitClean) {
Write-Host "git restore ."
git restore .
Write-Host "git clean -df"
git clean -df
}
}
}

Expand Down

0 comments on commit 94144ac

Please sign in to comment.