...

Text file src/github.com/Azure/azure-sdk-for-go/eng/scripts/Invoke-DependencyCheck.ps1

Documentation: github.com/Azure/azure-sdk-for-go/eng/scripts

     1Param(
     2    [string] $PackageDirectory
     3)
     4
     5. (Join-Path $PSScriptRoot .. common scripts common.ps1)
     6
     7$sdks = Get-AllPackageInfoFromRepo
     8
     9## Create depcheck module
    10$workingPath = Join-Path $RepoRoot "sdk" "depcheck"
    11if (Test-Path -Path $workingPath)
    12{
    13    Remove-Item -Path $workingPath -Recurse -Force
    14}
    15New-Item -ItemType Directory -Force -Path $workingPath
    16
    17## Init go mod
    18Set-Location $workingPath
    19Write-Host "##[command]Executing go mod init in " $workingPath
    20go mod init github.com/Azure/azure-sdk-for-go/sdk/depcheck
    21if ($LASTEXITCODE) { exit $LASTEXITCODE }
    22
    23# Find whether latest version is in the `retract` section in `go.mod` to judge whether the package is temporarily deprecated. 
    24function IsPackageDeprecated($sdk)
    25{
    26    $RETRACT_SECTION_REGEX = "retract\s*((?<retract>(.|\s)*))"
    27    $DEPRECATE_SECTION_REGEX = "\/\/\s*Deprecated:"
    28    $modContent = Get-Content (Join-Path $sdk.DirectoryPath 'go.mod') -Raw
    29    if ($modContent -match $DEPRECATE_SECTION_REGEX)
    30    {
    31        return $true
    32    }
    33    if ($modContent -match $RETRACT_SECTION_REGEX)
    34    {
    35        return $($matches["retract"]).Indexof($sdk.Version) -ne -1
    36    }
    37    return $false
    38}
    39
    40# Get all existed packages
    41$packagesImport = ""
    42foreach ($sdk in $sdks)
    43{
    44    if ($sdk.Name -like "*internal*" -or (IsPackageDeprecated $sdk))
    45    {
    46        continue
    47    }
    48    $parsedSemver = [AzureEngSemanticVersion]::ParseVersionString($sdk.Version)
    49
    50    
    51    if ($sdk.Name -eq $PackageDirectory)
    52    {
    53        ## Add replace for new package
    54        $modPath = Join-Path $RepoRoot "sdk" "depcheck" "go.mod"
    55        if ($parsedSemver.Major -gt 1)
    56        {
    57            Add-Content $modPath "`nreplace github.com/Azure/azure-sdk-for-go/$($sdk.Name)/v$($parsedSemver.Major) => ../../$($sdk.Name)`n"
    58        }
    59        else
    60        {
    61            Add-Content $modPath "`nreplace github.com/Azure/azure-sdk-for-go/$($sdk.Name) => ../../$($sdk.Name)`n"
    62        }
    63    }
    64
    65    if ($parsedSemver.Major -gt 1)
    66    {
    67        $packagesImport = $packagesImport + "`t_ `"github.com/Azure/azure-sdk-for-go/$($sdk.Name)/v$($parsedSemver.Major)`"`n"
    68    }
    69    else
    70    {
    71        $packagesImport = $packagesImport + "`t_ `"github.com/Azure/azure-sdk-for-go/$($sdk.Name)`"`n"
    72    }
    73}
    74
    75## Add main.go
    76$mainPath = Join-Path $RepoRoot "sdk" "depcheck" "main.go"
    77New-Item -Path $mainPath -ItemType File -Value '' -Force
    78Add-Content $mainPath "package main
    79
    80import (
    81$packagesImport
    82)
    83
    84func main() {
    85}
    86"
    87
    88## Run go mod tidy
    89Write-Host "##[command]Executing go mod tidy in " $workingPath
    90go mod tidy
    91if ($LASTEXITCODE) { exit $LASTEXITCODE }
    92
    93## Run go build and go vet
    94Write-Host "##[command]Executing go build -v ./... in " $workingPath
    95go build -v ./...
    96if ($LASTEXITCODE) { exit $LASTEXITCODE }
    97
    98Write-Host "##[command]Executing go vet ./... in " $workingPath
    99go vet ./...
   100if ($LASTEXITCODE) { exit $LASTEXITCODE }
   101
   102Write-Host "Checking dependency has completed. All packages are compatible."

View as plain text