@@ -83,6 +83,7 @@ function Get-ChangedTerraformFiles($changedFiles = (Get-ChangedFiles)) {
83
83
$changedFiles = Get-ChangedFilesUnderSpecification $changedFiles
84
84
85
85
$changedSwaggerFiles = $changedFiles.Where ({
86
+ # since `git diff` returns paths with `/`, use the following code to match the `main.tf`
86
87
$_.EndsWith (" /main.tf" )
87
88
})
88
89
@@ -113,27 +114,31 @@ function Ensure-Armstrong-Installed {
113
114
114
115
function Validate-Terraform-Error ($repoPath , $filePath ) {
115
116
$fileDirectory = (Split-Path - Parent $filePath )
116
-
117
- $outputDirectory = Join-Path - Path $fileDirectory - ChildPath " 58d50903-36e9-4f57-a1e5-f246d7ecdec0"
118
-
119
- if (! (Test-Path - Path $outputDirectory )) {
120
- New-Item - Path $outputDirectory - ItemType Directory
121
- # run armstrong credscan
122
- $specPath = Join-Path - Path $repoPath - ChildPath " specification"
123
- LogInfo " armstrong credscan -working-dir $fileDirectory -swagger-repo $specPath -output-dir $outputDirectory "
124
- armstrong credscan - working- dir $fileDirectory - swagger- repo $specPath - output- dir $outputDirectory
125
- }
126
-
127
- $result = @ ()
128
- # error reports are stored in a directory named armstrong_credscan_<timestamp>
129
- Get-ChildItem - Path $outputDirectory - Directory - Filter " armstrong_credscan_*" | ForEach-Object {
130
- $errorJsonPath = Join-Path - Path $_.FullName - ChildPath " errors.json"
131
- if (Test-Path - Path $errorJsonPath ) {
132
- Get-Content - Path $errorJsonPath - Raw | ConvertFrom-Json | ForEach-Object {
133
- $result += " $_ "
117
+ $outputDirectory = [System.IO.Path ]::Combine([System.IO.Path ]::GetTempPath(), [System.IO.Path ]::GetRandomFileName())
118
+
119
+ try {
120
+ if (! (Test-Path - Path $outputDirectory )) {
121
+ New-Item - Path $outputDirectory - ItemType Directory
122
+ # run armstrong credscan
123
+ $specPath = Join-Path - Path $repoPath - ChildPath " specification"
124
+ LogInfo " armstrong credscan -working-dir $fileDirectory -swagger-repo $specPath -output-dir $outputDirectory "
125
+ armstrong credscan - working- dir $fileDirectory - swagger- repo $specPath - output- dir $outputDirectory
126
+ }
127
+
128
+ $result = @ ()
129
+ # error reports are stored in a directory named armstrong_credscan_<timestamp>
130
+ Get-ChildItem - Path $outputDirectory - Directory - Filter " armstrong_credscan_*" | ForEach-Object {
131
+ $errorJsonPath = Join-Path - Path $_.FullName - ChildPath " errors.json"
132
+ if (Test-Path - Path $errorJsonPath ) {
133
+ Get-Content - Path $errorJsonPath - Raw | ConvertFrom-Json | ForEach-Object {
134
+ $result += " $_ "
135
+ }
134
136
}
135
137
}
136
138
}
139
+ finally {
140
+ Remove-Item - Path $outputDirectory - Recurse - Force
141
+ }
137
142
138
143
return $result
139
144
}
0 commit comments