...
1$Language = "go"
2$packagePattern = "go.mod"
3$LanguageDisplayName = "go"
4
5# get version from specific files (*constants.go, *version.go)
6function Get-GoModuleVersionInfo($modPath)
7{
8 $NO_PREFIX_VERSION_LINE_REGEX = ".+\s*=\s*`"(?<bad_version>$([AzureEngSemanticVersion]::SEMVER_REGEX))`""
9 $VERSION_LINE_REGEX = ".+\s*=\s*`".*v(?<version>$([AzureEngSemanticVersion]::SEMVER_REGEX))`""
10
11 $versionFiles = Get-ChildItem -Recurse -Path $modPath -Filter *.go
12
13 # for each version file, use regex to search go version num
14 foreach ($versionFile in $versionFiles)
15 {
16 # limit the search to constant and version file
17 if (!$versionFile.Name.Contains("constant") -and !$versionFile.Name.Contains("version")) {
18 continue
19 }
20 $content = Get-Content $versionFile -Raw
21
22 # finding where the version number are
23 if ($content -match $VERSION_LINE_REGEX) {
24 return "$($matches["version"])", $versionFile
25 }
26
27 # This is an easy mistake to make (X.Y.Z instead of vX.Y.Z) so add a very clear error log to make debugging easier
28 if ($content -match $NO_PREFIX_VERSION_LINE_REGEX) {
29 LogError "Version in $versionFile should be 'v$($matches["bad_version"])' not '$($matches["bad_version"])'"
30 }
31 }
32
33 LogWarning "Unable to find version for $modPath"
34 return $null
35}
36
37function Get-GoModuleProperties($goModPath)
38{
39 $goModPath = $goModPath -replace "\\", "/"
40 if ($goModPath -match "(?<modPath>sdk/(?<serviceDir>(resourcemanager/)?([^/]+/)?(?<modName>[^/]+$)))")
41 {
42 $modPath = $matches["modPath"]
43 $modName = $matches["modName"] # We may need to start readong this from the go.mod file if the path and mod config start to differ
44 $serviceDir = $matches["serviceDir"]
45 $sdkType = "client"
46 if ($modName.StartsWith("arm")) { $sdkType = "mgmt" }
47
48 $modVersion, $versionFile = Get-GoModuleVersionInfo $goModPath
49
50 if (!$modVersion) {
51 return $null
52 }
53
54 $pkgProp = [PackageProps]::new($modPath, $modVersion, $goModPath, $serviceDir)
55 $pkgProp.IsNewSdk = $true
56 $pkgProp.SdkType = $sdkType
57
58 $pkgProp | Add-Member -NotePropertyName "VersionFile" -NotePropertyValue $versionFile
59 $pkgProp | Add-Member -NotePropertyName "ModuleName" -NotePropertyValue $modName
60
61 return $pkgProp
62 }
63 return $null
64}
65
66# rewrite from artifact-metadata-parsing.ps1 used in RetrievePackages for fetch go single module info
67function Get-go-PackageInfoFromPackageFile($pkg, $workingDirectory)
68{
69 $releaseNotes = ""
70 $packageProperties = Get-GoModuleProperties $pkg.Directory
71
72 # We have some cases when processing service directories that non-shipping projects like perfdata
73 # we just want to exclude them as opposed to returning a property with invalid data.
74 if (!$packageProperties) {
75 return $null
76 }
77
78 if ($packageProperties.ChangeLogPath -and $packageProperties.Version)
79 {
80 $releaseNotes = Get-ChangeLogEntryAsString -ChangeLogLocation $packageProperties.ChangeLogPath `
81 -VersionString $packageProperties.Version
82 }
83
84 $resultObj = New-Object PSObject -Property @{
85 PackageId = $packageProperties.Name
86 PackageVersion = $packageProperties.Version
87 ReleaseTag = "$($packageProperties.Name)/v$($packageProperties.Version)"
88 Deployable = $true
89 ReleaseNotes = $releaseNotes
90
91 }
92
93 return $resultObj
94}
95
96function Get-AllPackageInfoFromRepo($serviceDirectory)
97{
98 $allPackageProps = @()
99 $searchPath = Join-Path $RepoRoot "sdk"
100 if ($serviceDirectory) {
101 $searchPath = Join-Path $searchPath $serviceDirectory
102 }
103
104 $pkgFiles = Get-ChildItem -Path $searchPath -Include "go.mod" -Recurse
105
106 foreach ($pkgFile in $pkgFiles)
107 {
108 $modPropertes = Get-GoModuleProperties $pkgFile.DirectoryName
109
110 if ($modPropertes) {
111 $allPackageProps += $modPropertes
112 }
113 }
114 return $allPackageProps
115}
116
117function SetPackageVersion ($PackageName, $Version, $ReleaseDate, $PackageProperties, $ReplaceLatestEntryTitle=$true)
118{
119 if(!$ReleaseDate) {
120 $ReleaseDate = Get-Date -Format "yyyy-MM-dd"
121 }
122
123 if (!$PackageProperties) {
124 $PackageProperties = Get-PkgProperties -PackageName $PackageName
125 }
126
127 & "${EngScriptsDir}/Update-ModuleVersion.ps1" `
128 -ModulePath $PackageProperties.Name `
129 -NewVersionString $Version `
130 -ReleaseDate $ReleaseDate `
131 -ReplaceLatestEntryTitle $ReplaceLatestEntryTitle
132}
133
134
135function Find-Go-Artifacts-For-Apireview($ArtifactPath, $PackageName)
136{
137 $artifact = Get-ChildItem -Path (Join-Path $ArtifactPath $PackageName) -Filter "*.gosource"
138 if ($artifact)
139 {
140 $packages = @{
141 $artifact.FullName = $artifact.FullName
142 }
143 return $packages
144 }
145 return $null
146}
View as plain text