Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add dependency check step to build pipeline #16265

Merged
merged 8 commits into from
Dec 10, 2021
10 changes: 10 additions & 0 deletions eng/pipelines/templates/steps/analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ parameters:

steps:

- task: Powershell@2
displayName: 'Dependency Check'
env:
GO111MODULE: 'on'
inputs:
targetType: filePath
pwsh: true
filePath: eng/scripts/Invoke-DependencyCheck.ps1
arguments: 'sdk/${{ parameters.ServiceDirectory }}'

- script: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${{parameters.LintVersion}}
golangci-lint --version
Expand Down
69 changes: 69 additions & 0 deletions eng/scripts/Invoke-DependencyCheck.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
Param(
[string] $newPackageDirectory
)

. (Join-Path $PSScriptRoot .. common scripts common.ps1)

$ignoreCheck = ,"sdk/synapse/azartifacts"

$sdks = Get-AllPackageInfoFromRepo

## 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 }

# Get all existed packages
$packagesImport = ""
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 $RepoRoot $newPackageDirectory)).Path)
weshaggard marked this conversation as resolved.
Show resolved Hide resolved
{
## Add replace for new package
$modPath = Join-Path $RepoRoot "sdk" "depcheck" "go.mod"
Add-Content $modPath "`nreplace github.com/Azure/azure-sdk-for-go/$($sdk.Name) => ../../$($sdk.Name)`n"
weshaggard marked this conversation as resolved.
Show resolved Hide resolved
}
$packagesImport = $packagesImport + "`t_ `"github.com/Azure/azure-sdk-for-go/$($sdk.Name)`"`n"
}

## 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() {
}
"

## 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 -v ./... in " $workingPath
go build -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."
4 changes: 2 additions & 2 deletions eng/scripts/Invoke-MgmtTestgen.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ function Invoke-MgmtTestgen ()

if (!$skipBuild)
{
Write-Host "##[command]Executing go build -x -v ./... in " $currentDirectory
go build -x -v ./...
Write-Host "##[command]Executing go build -v ./... in " $currentDirectory
go build -v ./...
Write-Host "##[command]Build Complete!"
if ($LASTEXITCODE) { exit $LASTEXITCODE }
}
Expand Down
4 changes: 2 additions & 2 deletions eng/scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ function Process-Sdk ()

if (!$skipBuild)
{
Write-Host "##[command]Executing go build -x -v ./... in " $currentDirectory
go build -x -v ./...
Write-Host "##[command]Executing go build -v ./... in " $currentDirectory
go build -v ./...
Write-Host "##[command]Build Complete!"
if ($LASTEXITCODE) { exit $LASTEXITCODE }
}
Expand Down