Skip to content

Commit

Permalink
feat: add dependency check step to build pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
tadelesh committed Nov 24, 2021
1 parent f3c6958 commit b38b7ef
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
11 changes: 11 additions & 0 deletions eng/pipelines/templates/steps/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ steps:
filePath: eng/scripts/build.ps1
arguments: -vet -skipBuild -filter '${{ parameters.ServiceDirectory }}'

- task: Powershell@2
displayName: 'Dependency Check'
continueOnError: true
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]
Expand Down
77 changes: 77 additions & 0 deletions eng/scripts/Invoke-DependencyCheck.ps1
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"

$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."

0 comments on commit b38b7ef

Please sign in to comment.