-
Notifications
You must be signed in to change notification settings - Fork 836
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add dependency check step to build pipeline
- Loading branch information
Showing
2 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,16 @@ steps: | |
filePath: eng/scripts/build.ps1 | ||
arguments: -vet -skipBuild -filter '${{ parameters.ServiceDirectory }}' | ||
|
||
- task: Powershell@2 | ||
displayName: 'Dependency Check' | ||
env: | ||
GO111MODULE: 'on' | ||
inputs: | ||
targetType: filePath | ||
pwsh: true | ||
filePath: eng/scripts/Invoke-DependencyCheck.ps1 | ||
arguments: '${{ parameters.ServiceDirectory }}' | ||
|
||
- pwsh: | | ||
go install github.com/jstemmer/[email protected] | ||
go install github.com/axw/gocov/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
Param( | ||
[string] $newPackageDirectory | ||
) | ||
|
||
. (Join-Path $PSScriptRoot .. common scripts common.ps1) | ||
|
||
$ignoreCheck = "sdk/synapse/azartifacts", "sdk/template/aztemplate", "sdk/azcore", "sdk/azidentity" | ||
|
||
$sdks = Get-AllPackageInfoFromRepo | ||
|
||
$sdkRoot = Join-Path $RepoRoot "sdk" | ||
|
||
# Get all existed packages | ||
$packagesImport = "" | ||
$newPackage = "" | ||
foreach ($sdk in $sdks) | ||
{ | ||
if ($sdk.Name -like "*internal*" -or $sdk.Name -in $ignoreCheck) | ||
{ | ||
continue | ||
} | ||
if ((Resolve-Path $sdk.DirectoryPath).Path -eq (Resolve-Path (Join-Path $sdkRoot $newPackageDirectory)).Path) | ||
{ | ||
$newPackage = $sdk.Name | ||
} | ||
$packagesImport = $packagesImport + "`t_ `"github.com/Azure/azure-sdk-for-go/$($sdk.Name)`"`n" | ||
} | ||
|
||
## Create depcheck module | ||
$workingPath = Join-Path $RepoRoot "sdk" "depcheck" | ||
if (Test-Path -Path $workingPath) | ||
{ | ||
Remove-Item -Path $workingPath -Recurse -Force | ||
} | ||
New-Item -ItemType Directory -Force -Path $workingPath | ||
|
||
## Init go mod | ||
Set-Location $workingPath | ||
Write-Host "##[command]Executing go mod init in " $workingPath | ||
go mod init github.com/Azure/azure-sdk-for-go/sdk/depcheck | ||
if ($LASTEXITCODE) { exit $LASTEXITCODE } | ||
|
||
## Add main.go | ||
$mainPath = Join-Path $RepoRoot "sdk" "depcheck" "main.go" | ||
New-Item -Path $mainPath -ItemType File -Value '' -Force | ||
Add-Content $mainPath "package main | ||
import ( | ||
$packagesImport | ||
) | ||
func main() { | ||
} | ||
" | ||
|
||
## Add replace for new package | ||
if ($newPackage -ne "") | ||
{ | ||
$modPath = Join-Path $RepoRoot "sdk" "depcheck" "go.mod" | ||
Add-Content $modPath "`nreplace github.com/Azure/azure-sdk-for-go/$newPackage => ../../$newPackage`n" | ||
} | ||
|
||
## Run go mod tidy | ||
Write-Host "##[command]Executing go mod tidy in " $workingPath | ||
go mod tidy | ||
if ($LASTEXITCODE) { exit $LASTEXITCODE } | ||
|
||
## Run go build and go vet | ||
Write-Host "##[command]Executing go build -x -v ./... in " $workingPath | ||
go build -x -v ./... | ||
if ($LASTEXITCODE) { exit $LASTEXITCODE } | ||
|
||
Write-Host "##[command]Executing go vet ./... in " $workingPath | ||
go vet ./... | ||
if ($LASTEXITCODE) { exit $LASTEXITCODE } | ||
|
||
Write-Host "Checking dependency has completed. All packages are compatible." |