From be051a1f12cf72831a794ca2ec3a3e61c76b7e03 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Wed, 9 Dec 2020 11:06:04 +0300 Subject: [PATCH 01/10] add parsers --- .../templates/get-tool-versions-steps.yml | 5 +- .../get-new-tool-versions.ps1 | 61 ++++--------------- get-new-tool-versions/helpers.psm1 | 14 ----- .../parsers/base-parser.psm1 | 32 ++++++++++ get-new-tool-versions/parsers/go-parser.psm1 | 25 ++++++++ .../parsers/node-parser.psm1 | 30 +++++++++ .../parsers/parsers-factory.psm1 | 19 ++++++ .../parsers/python-parser.psm1 | 54 ++++++++++++++++ 8 files changed, 173 insertions(+), 67 deletions(-) create mode 100644 get-new-tool-versions/parsers/base-parser.psm1 create mode 100644 get-new-tool-versions/parsers/go-parser.psm1 create mode 100644 get-new-tool-versions/parsers/node-parser.psm1 create mode 100644 get-new-tool-versions/parsers/parsers-factory.psm1 create mode 100644 get-new-tool-versions/parsers/python-parser.psm1 diff --git a/azure-pipelines/templates/get-tool-versions-steps.yml b/azure-pipelines/templates/get-tool-versions-steps.yml index 4dae6fc..e01a238 100644 --- a/azure-pipelines/templates/get-tool-versions-steps.yml +++ b/azure-pipelines/templates/get-tool-versions-steps.yml @@ -6,10 +6,7 @@ steps: targetType: filePath filePath: './get-new-tool-versions/get-new-tool-versions.ps1' arguments: | - -DistURL "$(DIST_URL)" ` - -ManifestLink "$(MANIFEST_URL)" ` - -VersionFilterToInclude $(INCLUDE_FILTER) ` - -VersionFilterToExclude $(EXCLUDE_FILTER) + -ToolName "$(TOOL_NAME)" - task: PowerShell@2 displayName: 'Cancel build' diff --git a/get-new-tool-versions/get-new-tool-versions.ps1 b/get-new-tool-versions/get-new-tool-versions.ps1 index af4b1a8..2e9064d 100644 --- a/get-new-tool-versions/get-new-tool-versions.ps1 +++ b/get-new-tool-versions/get-new-tool-versions.ps1 @@ -17,61 +17,24 @@ Optional parameter. Retry count #> param ( - [Parameter(Mandatory)] [string] $DistURL, - [Parameter(Mandatory)] [string] $ManifestLink, - [string[]] $VersionFilterToInclude, - [string[]] $VersionFilterToExclude, - [UInt32] $RetryIntervalSec = 60, - [UInt32] $RetryCount = 3 + [Parameter(Mandatory)] [string] $ToolName ) -Import-Module (Join-Path $PSScriptRoot "helpers.psm1") +Import-Module "$PSScriptRoot/parsers/parsers-factory.psm1" -function Get-VersionsByUrl { - param ( - [Parameter(Mandatory)] [string] $ToolPackagesUrl, - [Parameter(Mandatory)] [UInt32] $RetryIntervalSec, - [Parameter(Mandatory)] [UInt32] $RetryCount - ) +$ToolVersionParser = Get-ToolVersionsParser -ToolName $ToolName +$VersionsFromDist = $ToolVersionParser.GetAvailableVersions() +$VersionsFromManifest = $ToolVersionParser.GetUploadedVersions() - $packages = Invoke-RestMethod $ToolPackagesUrl -MaximumRetryCount $RetryCount -RetryIntervalSec $RetryIntervalSec - return $packages.version -} - -if ($VersionFilterToInclude) { - Validate-FiltersFormat -Filters $VersionFilterToInclude -} - -if ($VersionFilterToExclude) { - Validate-FiltersFormat -Filters $VersionFilterToExclude -} - -Write-Host "Get the packages list from $DistURL" -$versionsFromDist = Get-VersionsByUrl -ToolPackagesUrl $DistURL ` - -RetryIntervalSec $RetryIntervalSec ` - -RetryCount $RetryCount - -Write-Host "Get the packages list from $ManifestLink" -[Version[]] $versionsFromManifest = Get-VersionsByUrl -ToolPackagesUrl $ManifestLink ` - -RetryIntervalSec $RetryIntervalSec ` - -RetryCount $RetryCount - -[Version[]] $formattedVersions = Format-Versions -Versions $versionsFromDist - -$formattedVersions = Select-VersionsByFilter -Versions $formattedVersions ` - -IncludeFilters $VersionFilterToInclude ` - -ExcludeFilters $VersionFilterToExclude - -if (-not $formattedVersions) { - Write-Host "Couldn't find available versions with current filters" - exit 1 -} +Write-Host "Dist" +$VersionsFromDist | ForEach-Object { Write-Host $_ } +Write-Host "Manifest" +$VersionsFromManifest | ForEach-Object { Write-Host $_ } -$versionsToBuild = Skip-ExistingVersions -VersionsFromManifest $versionsFromManifest ` - -VersionsFromDist $formattedVersions +$VersionsToBuild = $VersionsFromDist | Where-Object { $VersionsFromManifest -notcontains $_ } -if ($versionsToBuild) { - $availableVersions = $versionsToBuild -join "," +if ($VersionsToBuild) { + $availableVersions = $VersionsToBuild -join "," $toolVersions = $availableVersions.Replace(",",", ") Write-Host "The following versions are available to build:`n$toolVersions" Write-Output "##vso[task.setvariable variable=TOOL_VERSIONS;isOutput=true]$toolVersions" diff --git a/get-new-tool-versions/helpers.psm1 b/get-new-tool-versions/helpers.psm1 index fb63f61..488d6c1 100644 --- a/get-new-tool-versions/helpers.psm1 +++ b/get-new-tool-versions/helpers.psm1 @@ -1,17 +1,3 @@ -function Validate-FiltersFormat { - param ( - [Parameter(Mandatory)] [string[]] $Filters - ) - - foreach($filter in $Filters) { - $filter.Split('.') | ForEach-Object { - if (($_ -notmatch '^\d+$') -and ($_ -ne '*')) { - throw "Invalid filter format - $filter" - } - } - } -} - function Format-Versions { param ( [Parameter(Mandatory)] [string[]] $Versions diff --git a/get-new-tool-versions/parsers/base-parser.psm1 b/get-new-tool-versions/parsers/base-parser.psm1 new file mode 100644 index 0000000..706f879 --- /dev/null +++ b/get-new-tool-versions/parsers/base-parser.psm1 @@ -0,0 +1,32 @@ +class BaseVersionsParser { + [Int32]$ApiRetryCount = 3 + [Int32]$ApiRetryIntervalSeconds = 60 + + [SemVer[]] GetAvailableVersions() { + $allVersionsRaw = $this.ParseAllAvailableVersions() + $allVersions = $allVersionsRaw | ForEach-Object { Write-Host $_; $this.FormatVersion($_) } + $filteredVersions = $allVersions | Where-Object { $this.ShouldIncludeVersion($_) } + return $filteredVersions + } + + [SemVer[]] GetUploadedVersions() { + throw "Method is not implemented in base class" + } + + hidden [SemVer[]] ParseAllAvailableVersions() { + throw "Method is not implemented in base class" + } + + hidden [SemVer] FormatVersion([string]$VersionSpec) { + throw "Method is not implemented in base class" + } + + hidden [bool] ShouldIncludeVersion([SemVer]$Version) { + throw "Method is not implemented in base class" + } + + hidden [string] BuildGitHubFileUrl($OrganizationName, $RepositoryName, $BranchName, $FilePath) { + # https://raw.githubusercontent.com/actions/node-versions/main/versions-manifest.json + return "https://raw.githubusercontent.com/${OrganizationName}/${RepositoryName}/${BranchName}/${FilePath}" + } +} \ No newline at end of file diff --git a/get-new-tool-versions/parsers/go-parser.psm1 b/get-new-tool-versions/parsers/go-parser.psm1 new file mode 100644 index 0000000..6091555 --- /dev/null +++ b/get-new-tool-versions/parsers/go-parser.psm1 @@ -0,0 +1,25 @@ +using module "./base-parser.psm1" + +class GoVersionsParser: BaseVersionsParser { + [SemVer[]] GetUploadedVersions() { + $url = $this.BuildGitHubFileUrl("actions", "go-versions", "main", "versions-manifest.json") + $releases = Invoke-RestMethod $url -MaximumRetryCount $this.ApiRetryCount -RetryIntervalSec $this.ApiRetryIntervalSeconds + return $releases.version + } + + hidden [string[]] ParseAllAvailableVersions() { + $url = "https://golang.org/dl/?mode=json&include=all" + $releases = Invoke-RestMethod $url -MaximumRetryCount $this.ApiRetryCount -RetryIntervalSec $this.ApiRetryIntervalSeconds + return $releases.version + } + + hidden [SemVer] FormatVersion([string]$VersionSpec) { + $cleanVersion = $VersionSpec -replace "^go", "" + return [SemVer]$cleanVersion + } + + hidden [bool] ShouldIncludeVersion([SemVer]$Version) { + # For Go, we include all versions greater than 1.12 + return $Version -gt [SemVer]"1.12.0" + } +} \ No newline at end of file diff --git a/get-new-tool-versions/parsers/node-parser.psm1 b/get-new-tool-versions/parsers/node-parser.psm1 new file mode 100644 index 0000000..f15d74f --- /dev/null +++ b/get-new-tool-versions/parsers/node-parser.psm1 @@ -0,0 +1,30 @@ +using module "./base-parser.psm1" + +class NodeVersionsParser: BaseVersionsParser { + [SemVer[]] GetUploadedVersions() { + $url = $this.BuildGitHubFileUrl("actions", "node-versions", "main", "versions-manifest.json") + $releases = Invoke-RestMethod $url -MaximumRetryCount $this.ApiRetryCount -RetryIntervalSec $this.ApiRetryIntervalSeconds + return $releases.version + } + + hidden [string[]] ParseAllAvailableVersions() { + $url = "https://nodejs.org/dist/index.json" + $releases = Invoke-RestMethod $url -MaximumRetryCount $this.ApiRetryCount -RetryIntervalSec $this.ApiRetryIntervalSeconds + return $releases.version + } + + hidden [SemVer] FormatVersion([string]$VersionSpec) { + $cleanVersion = $VersionSpec -replace "^v", "" + return [SemVer]$cleanVersion + } + + hidden [bool] ShouldIncludeVersion([SemVer]$Version) { + if ($Version.Major -lt 8) { + return $false + } + + # For Node.JS, we should include all LTS versions (all even-numbered releases) + # https://nodejs.org/en/about/releases/ + return $Version.Major % 2 -eq 0 + } +} \ No newline at end of file diff --git a/get-new-tool-versions/parsers/parsers-factory.psm1 b/get-new-tool-versions/parsers/parsers-factory.psm1 new file mode 100644 index 0000000..eb9b69c --- /dev/null +++ b/get-new-tool-versions/parsers/parsers-factory.psm1 @@ -0,0 +1,19 @@ +using module "./node-parser.psm1" +using module "./go-parser.psm1" +using module "./python-parser.psm1" + +function Get-ToolVersionsParser { + param( + [Parameter(Mandatory)] + [string]$ToolName + ) + + switch ($ToolName) { + "Node" { return [NodeVersionsParser]::New() } + "Go" { return [GoVersionsParser]::New() } + "Python" { return [PythonVersionsParser]::New() } + Default { + throw "Unknown tool name" + } + } +} \ No newline at end of file diff --git a/get-new-tool-versions/parsers/python-parser.psm1 b/get-new-tool-versions/parsers/python-parser.psm1 new file mode 100644 index 0000000..e82f730 --- /dev/null +++ b/get-new-tool-versions/parsers/python-parser.psm1 @@ -0,0 +1,54 @@ +using module "./base-parser.psm1" + +class PythonVersionsParser: BaseVersionsParser { + [SemVer[]] GetUploadedVersions() { + $url = $this.BuildGitHubFileUrl("actions", "python-versions", "main", "versions-manifest.json") + $releases = Invoke-RestMethod $url -MaximumRetryCount $this.ApiRetryCount -RetryIntervalSec $this.ApiRetryIntervalSeconds + return $releases.version + } + + hidden [string[]] ParseAllAvailableVersions() { + $stableVersionsUrl = "https://www.python.org/ftp/python" + $stableVersionsHtmlRaw = Invoke-WebRequest $stableVersionsUrl + $stableVersionsList = $stableVersionsHtmlRaw.Links.href | Where-Object { + $parsed = $null + return $_.EndsWith("/") -and [SemVer]::TryParse($_.Replace("/", ""), [ref]$parsed) + } + + return $stableVersionsList | ForEach-Object { + $subVersionsUrl = "${stableVersionsUrl}/${_}" + $subVersionsHtmlRaw = Invoke-WebRequest $subVersionsUrl + return $subVersionsHtmlRaw.Links.href | ForEach-Object { + if ($_ -match "^Python-(\d+\.\d+\.\d+[a-z]{0,2}\d*)\.tgz$") { + return $Matches[1] + } + } | ForEach-Object { $_ } | Where-Object { $_ } + } + } + + hidden [SemVer] FormatVersion([string]$VersionSpec) { + $VersionSpec -match "^(\d+)\.(\d+)\.(\d+)([a-z]{1,2})?(\d+)?$" + + if ($Matches.Count -gt 4) { + $VersionLabel = "{0}.{1}" -f $this.ConvertPythonLabel($Matches[4]), $Matches[5] + return [SemVer]::new($Matches[1], $Matches[2], $Matches[3], $VersionLabel) + } + + return [SemVer]::new($Matches[1], $Matches[2], $Matches[3]) + } + + hidden [string] ConvertPythonLabel([string]$Label) { + switch ($Label) { + "a" { return "alpha" } + "b" { return "beta" } + "rc" { return "rc" } + } + + return $Label + } + + [bool] ShouldIncludeVersion([SemVer]$Version) { + # For Go, we include all versions greater than 1.12 + return $Version -gt [SemVer]"3.9.0" + } +} \ No newline at end of file From 109e6bd0094e06070c9a08c26cfe914ee4c806cf Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Wed, 9 Dec 2020 11:15:10 +0300 Subject: [PATCH 02/10] check condition --- azure-pipelines/get-tool-versions.yml | 1 + .../templates/get-tool-versions-steps.yml | 46 +++++++++---------- .../parsers/base-parser.psm1 | 3 +- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/azure-pipelines/get-tool-versions.yml b/azure-pipelines/get-tool-versions.yml index 8c38d6c..b4cf600 100644 --- a/azure-pipelines/get-tool-versions.yml +++ b/azure-pipelines/get-tool-versions.yml @@ -32,6 +32,7 @@ stages: - stage: Trigger_Builds dependsOn: Get_New_Versions + condition: and(succeeded(), ne(stageDependencies.Get_New_Versions.Get_Tool_Versions.outputs['Get_versions.TOOL_VERSIONS'], '') jobs: - deployment: Run_Builds pool: diff --git a/azure-pipelines/templates/get-tool-versions-steps.yml b/azure-pipelines/templates/get-tool-versions-steps.yml index e01a238..b783b34 100644 --- a/azure-pipelines/templates/get-tool-versions-steps.yml +++ b/azure-pipelines/templates/get-tool-versions-steps.yml @@ -8,18 +8,18 @@ steps: arguments: | -ToolName "$(TOOL_NAME)" -- task: PowerShell@2 - displayName: 'Cancel build' - condition: and(succeeded(), eq(variables['Get_versions.TOOL_VERSIONS'], '')) - inputs: - TargetType: inline - script: | - Import-Module "./azure-devops/azure-devops-api.ps1" - $azureDevOpsApi = Get-AzureDevOpsApi -TeamFoundationCollectionUri $(System.TeamFoundationCollectionUri) ` - -ProjectName $(System.TeamProject) ` - -AccessToken $(System.AccessToken) +# - task: PowerShell@2 +# displayName: 'Cancel build' +# condition: and(succeeded(), eq(variables['Get_versions.TOOL_VERSIONS'], '')) +# inputs: +# TargetType: inline +# script: | +# Import-Module "./azure-devops/azure-devops-api.ps1" +# $azureDevOpsApi = Get-AzureDevOpsApi -TeamFoundationCollectionUri $(System.TeamFoundationCollectionUri) ` +# -ProjectName $(System.TeamProject) ` +# -AccessToken $(System.AccessToken) - $AzureDevOpsApi.UpdateBuildStatus($(Build.BuildId), 'Cancelling') | Out-Null +# $AzureDevOpsApi.UpdateBuildStatus($(Build.BuildId), 'Cancelling') | Out-Null - task: PowerShell@2 displayName: 'Set env variable' @@ -30,15 +30,15 @@ steps: $PipelineUrl = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId)" Write-Output "##vso[task.setvariable variable=PIPELINE_URL]$PipelineUrl" -- task: PowerShell@2 - displayName: 'Send Slack notification' - condition: and(succeeded(), ne(variables['Get_versions.TOOL_VERSIONS'], '')) - inputs: - targetType: filePath - filePath: './get-new-tool-versions/send-slack-notification.ps1' - arguments: | - -Url "$(SLACK_CHANNEL_URL)" ` - -ToolName "$(TOOL_NAME)" ` - -ToolVersion "$(Get_versions.TOOL_VERSIONS)" ` - -PipelineUrl "$(PIPELINE_URL)" ` - -ImageUrl "$(IMAGE_URL)" +# - task: PowerShell@2 +# displayName: 'Send Slack notification' +# condition: and(succeeded(), ne(variables['Get_versions.TOOL_VERSIONS'], '')) +# inputs: +# targetType: filePath +# filePath: './get-new-tool-versions/send-slack-notification.ps1' +# arguments: | +# -Url "$(SLACK_CHANNEL_URL)" ` +# -ToolName "$(TOOL_NAME)" ` +# -ToolVersion "$(Get_versions.TOOL_VERSIONS)" ` +# -PipelineUrl "$(PIPELINE_URL)" ` +# -ImageUrl "$(IMAGE_URL)" diff --git a/get-new-tool-versions/parsers/base-parser.psm1 b/get-new-tool-versions/parsers/base-parser.psm1 index 706f879..6118fd9 100644 --- a/get-new-tool-versions/parsers/base-parser.psm1 +++ b/get-new-tool-versions/parsers/base-parser.psm1 @@ -4,7 +4,7 @@ class BaseVersionsParser { [SemVer[]] GetAvailableVersions() { $allVersionsRaw = $this.ParseAllAvailableVersions() - $allVersions = $allVersionsRaw | ForEach-Object { Write-Host $_; $this.FormatVersion($_) } + $allVersions = $allVersionsRaw | ForEach-Object { $this.FormatVersion($_) } $filteredVersions = $allVersions | Where-Object { $this.ShouldIncludeVersion($_) } return $filteredVersions } @@ -26,7 +26,6 @@ class BaseVersionsParser { } hidden [string] BuildGitHubFileUrl($OrganizationName, $RepositoryName, $BranchName, $FilePath) { - # https://raw.githubusercontent.com/actions/node-versions/main/versions-manifest.json return "https://raw.githubusercontent.com/${OrganizationName}/${RepositoryName}/${BranchName}/${FilePath}" } } \ No newline at end of file From 21cbc1e8cab5a4cf9723686495fd95a4e42b536f Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Wed, 9 Dec 2020 11:15:51 +0300 Subject: [PATCH 03/10] Update get-tool-versions.yml --- azure-pipelines/get-tool-versions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines/get-tool-versions.yml b/azure-pipelines/get-tool-versions.yml index b4cf600..5475427 100644 --- a/azure-pipelines/get-tool-versions.yml +++ b/azure-pipelines/get-tool-versions.yml @@ -32,7 +32,7 @@ stages: - stage: Trigger_Builds dependsOn: Get_New_Versions - condition: and(succeeded(), ne(stageDependencies.Get_New_Versions.Get_Tool_Versions.outputs['Get_versions.TOOL_VERSIONS'], '') + condition: and(succeeded(), ne(stageDependencies.Get_New_Versions.Get_Tool_Versions.outputs['Get_versions.TOOL_VERSIONS'], '')) jobs: - deployment: Run_Builds pool: From f4ff9fb93d616fe100ead4713a3cbf055ac5c696 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Wed, 9 Dec 2020 11:48:13 +0300 Subject: [PATCH 04/10] test --- azure-pipelines/get-tool-versions.yml | 2 +- .../templates/get-tool-versions-steps.yml | 50 +++++++++---------- .../get-new-tool-versions.ps1 | 2 +- .../send-slack-notification.ps1 | 8 +-- 4 files changed, 29 insertions(+), 33 deletions(-) diff --git a/azure-pipelines/get-tool-versions.yml b/azure-pipelines/get-tool-versions.yml index 5475427..d408885 100644 --- a/azure-pipelines/get-tool-versions.yml +++ b/azure-pipelines/get-tool-versions.yml @@ -32,7 +32,7 @@ stages: - stage: Trigger_Builds dependsOn: Get_New_Versions - condition: and(succeeded(), ne(stageDependencies.Get_New_Versions.Get_Tool_Versions.outputs['Get_versions.TOOL_VERSIONS'], '')) + condition: and(succeeded(), ne(stageDependencies.Get_New_Versions.Get_Tool_Versions.outputs['Get_versions.TOOL_VERSIONS'], ''), ne(variables['WORKFLOW_FILE_NAME'], '')) jobs: - deployment: Run_Builds pool: diff --git a/azure-pipelines/templates/get-tool-versions-steps.yml b/azure-pipelines/templates/get-tool-versions-steps.yml index b783b34..7423477 100644 --- a/azure-pipelines/templates/get-tool-versions-steps.yml +++ b/azure-pipelines/templates/get-tool-versions-steps.yml @@ -8,37 +8,33 @@ steps: arguments: | -ToolName "$(TOOL_NAME)" -# - task: PowerShell@2 -# displayName: 'Cancel build' -# condition: and(succeeded(), eq(variables['Get_versions.TOOL_VERSIONS'], '')) -# inputs: -# TargetType: inline -# script: | -# Import-Module "./azure-devops/azure-devops-api.ps1" -# $azureDevOpsApi = Get-AzureDevOpsApi -TeamFoundationCollectionUri $(System.TeamFoundationCollectionUri) ` -# -ProjectName $(System.TeamProject) ` -# -AccessToken $(System.AccessToken) - -# $AzureDevOpsApi.UpdateBuildStatus($(Build.BuildId), 'Cancelling') | Out-Null - - task: PowerShell@2 displayName: 'Set env variable' - condition: and(succeeded(), ne(variables['Get_versions.TOOL_VERSIONS'], '')) + condition: and(succeeded(), ne(variables['TOOL_NAME'], "Python")) inputs: TargetType: inline script: | $PipelineUrl = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId)" - Write-Output "##vso[task.setvariable variable=PIPELINE_URL]$PipelineUrl" + Write-Host "##vso[task.setvariable variable=PIPELINE_URL]$PipelineUrl" + +- task: PowerShell@2 + displayName: 'Change build name' + condition: and(succeeded(), ne(variables['Get_versions.TOOL_VERSIONS'], '')) + inputs: + TargetType: inline + script: | + $newBuildName = "[FOUND] $(Build.BuildNumber)" + Write-Host "##vso[build.updatebuildnumber]$newBuildName" -# - task: PowerShell@2 -# displayName: 'Send Slack notification' -# condition: and(succeeded(), ne(variables['Get_versions.TOOL_VERSIONS'], '')) -# inputs: -# targetType: filePath -# filePath: './get-new-tool-versions/send-slack-notification.ps1' -# arguments: | -# -Url "$(SLACK_CHANNEL_URL)" ` -# -ToolName "$(TOOL_NAME)" ` -# -ToolVersion "$(Get_versions.TOOL_VERSIONS)" ` -# -PipelineUrl "$(PIPELINE_URL)" ` -# -ImageUrl "$(IMAGE_URL)" +- task: PowerShell@2 + displayName: 'Send Slack notification' + condition: and(succeeded(), ne(variables['Get_versions.TOOL_VERSIONS'], '')) + inputs: + targetType: filePath + filePath: './get-new-tool-versions/send-slack-notification.ps1' + arguments: | + -Url "$(SLACK_CHANNEL_URL)" ` + -ToolName "$(TOOL_NAME)" ` + -ToolVersion "$(Get_versions.TOOL_VERSIONS)" ` + -PipelineUrl "$(PIPELINE_URL)" ` + -ImageUrl "$(IMAGE_URL)" diff --git a/get-new-tool-versions/get-new-tool-versions.ps1 b/get-new-tool-versions/get-new-tool-versions.ps1 index 2e9064d..42f9312 100644 --- a/get-new-tool-versions/get-new-tool-versions.ps1 +++ b/get-new-tool-versions/get-new-tool-versions.ps1 @@ -37,7 +37,7 @@ if ($VersionsToBuild) { $availableVersions = $VersionsToBuild -join "," $toolVersions = $availableVersions.Replace(",",", ") Write-Host "The following versions are available to build:`n$toolVersions" - Write-Output "##vso[task.setvariable variable=TOOL_VERSIONS;isOutput=true]$toolVersions" + Write-Host "##vso[task.setvariable variable=TOOL_VERSIONS;isOutput=true]$toolVersions" } else { Write-Host "There aren't versions to build" } diff --git a/get-new-tool-versions/send-slack-notification.ps1 b/get-new-tool-versions/send-slack-notification.ps1 index 75441e9..0c6e57e 100644 --- a/get-new-tool-versions/send-slack-notification.ps1 +++ b/get-new-tool-versions/send-slack-notification.ps1 @@ -27,10 +27,7 @@ param( [ValidateNotNullOrEmpty()] [System.String]$ToolVersion, - [Parameter(Mandatory)] - [ValidateNotNullOrEmpty()] [System.String]$PipelineUrl, - [System.String]$ImageUrl = 'https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png' ) @@ -38,7 +35,10 @@ param( Import-Module $PSScriptRoot/helpers.psm1 -DisableNameChecking # Create JSON body -$text = "The following versions of '$toolName' are available to upload: $toolVersion\nLink to the pipeline: $pipelineUrl" +$text = "The following versions of '$toolName' are available to upload: $toolVersion" +if ($PipelineUrl) { + $text += "\nLink to the pipeline: $pipelineUrl" +} $jsonBodyMessage = @" { "blocks": [ From 02afcca5c664eaacf71f4e0f96f6f237f2c01e7f Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Wed, 9 Dec 2020 11:50:51 +0300 Subject: [PATCH 05/10] Update get-tool-versions-steps.yml --- azure-pipelines/templates/get-tool-versions-steps.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines/templates/get-tool-versions-steps.yml b/azure-pipelines/templates/get-tool-versions-steps.yml index 7423477..11eae4d 100644 --- a/azure-pipelines/templates/get-tool-versions-steps.yml +++ b/azure-pipelines/templates/get-tool-versions-steps.yml @@ -10,7 +10,7 @@ steps: - task: PowerShell@2 displayName: 'Set env variable' - condition: and(succeeded(), ne(variables['TOOL_NAME'], "Python")) + condition: and(succeeded(), ne(variables['TOOL_NAME'], 'Python')) inputs: TargetType: inline script: | From 236d44a167aeef8d086b0fb756abcc7320f63c43 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Wed, 9 Dec 2020 12:07:11 +0300 Subject: [PATCH 06/10] Update get-tool-versions-steps.yml --- azure-pipelines/templates/get-tool-versions-steps.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure-pipelines/templates/get-tool-versions-steps.yml b/azure-pipelines/templates/get-tool-versions-steps.yml index 11eae4d..e6b160e 100644 --- a/azure-pipelines/templates/get-tool-versions-steps.yml +++ b/azure-pipelines/templates/get-tool-versions-steps.yml @@ -9,7 +9,7 @@ steps: -ToolName "$(TOOL_NAME)" - task: PowerShell@2 - displayName: 'Set env variable' + displayName: 'Set PIPELINE_URL variable' condition: and(succeeded(), ne(variables['TOOL_NAME'], 'Python')) inputs: TargetType: inline @@ -36,5 +36,5 @@ steps: -Url "$(SLACK_CHANNEL_URL)" ` -ToolName "$(TOOL_NAME)" ` -ToolVersion "$(Get_versions.TOOL_VERSIONS)" ` - -PipelineUrl "$(PIPELINE_URL)" ` + -PipelineUrl "${{ variables.PIPELINE_URL }}" ` -ImageUrl "$(IMAGE_URL)" From 5e5de280d6924c011689755f79cab314531e2b46 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Wed, 9 Dec 2020 12:28:15 +0300 Subject: [PATCH 07/10] fix minor nitpicks --- get-new-tool-versions/get-new-tool-versions.ps1 | 5 ----- get-new-tool-versions/parsers/python-parser.psm1 | 8 ++++---- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/get-new-tool-versions/get-new-tool-versions.ps1 b/get-new-tool-versions/get-new-tool-versions.ps1 index 42f9312..9c707db 100644 --- a/get-new-tool-versions/get-new-tool-versions.ps1 +++ b/get-new-tool-versions/get-new-tool-versions.ps1 @@ -26,11 +26,6 @@ $ToolVersionParser = Get-ToolVersionsParser -ToolName $ToolName $VersionsFromDist = $ToolVersionParser.GetAvailableVersions() $VersionsFromManifest = $ToolVersionParser.GetUploadedVersions() -Write-Host "Dist" -$VersionsFromDist | ForEach-Object { Write-Host $_ } -Write-Host "Manifest" -$VersionsFromManifest | ForEach-Object { Write-Host $_ } - $VersionsToBuild = $VersionsFromDist | Where-Object { $VersionsFromManifest -notcontains $_ } if ($VersionsToBuild) { diff --git a/get-new-tool-versions/parsers/python-parser.psm1 b/get-new-tool-versions/parsers/python-parser.psm1 index e82f730..c67e5ca 100644 --- a/get-new-tool-versions/parsers/python-parser.psm1 +++ b/get-new-tool-versions/parsers/python-parser.psm1 @@ -9,7 +9,7 @@ class PythonVersionsParser: BaseVersionsParser { hidden [string[]] ParseAllAvailableVersions() { $stableVersionsUrl = "https://www.python.org/ftp/python" - $stableVersionsHtmlRaw = Invoke-WebRequest $stableVersionsUrl + $stableVersionsHtmlRaw = Invoke-WebRequest $stableVersionsUrl -MaximumRetryCount $this.ApiRetryCount -RetryIntervalSec $this.ApiRetryIntervalSeconds $stableVersionsList = $stableVersionsHtmlRaw.Links.href | Where-Object { $parsed = $null return $_.EndsWith("/") -and [SemVer]::TryParse($_.Replace("/", ""), [ref]$parsed) @@ -17,12 +17,12 @@ class PythonVersionsParser: BaseVersionsParser { return $stableVersionsList | ForEach-Object { $subVersionsUrl = "${stableVersionsUrl}/${_}" - $subVersionsHtmlRaw = Invoke-WebRequest $subVersionsUrl + $subVersionsHtmlRaw = Invoke-WebRequest $subVersionsUrl -MaximumRetryCount $this.ApiRetryCount -RetryIntervalSec $this.ApiRetryIntervalSeconds return $subVersionsHtmlRaw.Links.href | ForEach-Object { if ($_ -match "^Python-(\d+\.\d+\.\d+[a-z]{0,2}\d*)\.tgz$") { return $Matches[1] } - } | ForEach-Object { $_ } | Where-Object { $_ } + } } } @@ -48,7 +48,7 @@ class PythonVersionsParser: BaseVersionsParser { } [bool] ShouldIncludeVersion([SemVer]$Version) { - # For Go, we include all versions greater than 1.12 + # For Python, we include all versions greater than 3.9.0 return $Version -gt [SemVer]"3.9.0" } } \ No newline at end of file From 4ce7f7efbccabf74439020345fee4de44780a429 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Wed, 9 Dec 2020 13:32:54 +0300 Subject: [PATCH 08/10] Delete get-new-tool-versions.Tests.ps1 --- .../get-new-tool-versions.Tests.ps1 | 93 ------------------- 1 file changed, 93 deletions(-) delete mode 100644 get-new-tool-versions/get-new-tool-versions.Tests.ps1 diff --git a/get-new-tool-versions/get-new-tool-versions.Tests.ps1 b/get-new-tool-versions/get-new-tool-versions.Tests.ps1 deleted file mode 100644 index f16728b..0000000 --- a/get-new-tool-versions/get-new-tool-versions.Tests.ps1 +++ /dev/null @@ -1,93 +0,0 @@ -#Requires -Modules Pester - -Import-Module (Join-Path $PSScriptRoot "helpers.psm1") -Force - -Describe "Validate-FiltersFormat" { - It "Filter with word" { - { Validate-FiltersFormat -Filters @("1two.2") } | Should -Throw "Invalid filter format" - } - - It "Filter with non-word character" { - { Validate-FiltersFormat -Filters @("1,.2") } | Should -Throw "Invalid filter format" - } - - It "Valid filters" { - { Validate-FiltersFormat -Filters @("*", "1", "1.*", "1.2", "1.2.*") } | Should -Not -Throw "Invalid filter format" - } -} - -Describe "Format-Versions" { - It "Clean versions" { - $actualOutput = Format-Versions -Versions @("14.2.0", "1.14.0") - $expectedOutput = @("14.2.0", "1.14.0") - $actualOutput | Should -Be $expectedOutput - } - - It "Versions with prefixes" { - $actualOutput = Format-Versions -Versions @("v14.2.0", "go1.14.0") - $expectedOutput = @("14.2.0", "1.14.0") - $actualOutput | Should -Be $expectedOutput - } - - It "Skip beta and rc versions" { - $actualOutput = Format-Versions -Versions @("14.2.0-beta", "v1.14.0-rc-1") - $expectedOutput = @() - $actualOutput | Should -Be $expectedOutput - } - - It "Short version" { - $actualOutput = Format-Versions -Versions @("14.2", "v2.0") - $expectedOutput = @("14.2.0", "2.0.0") - $actualOutput | Should -Be $expectedOutput - } - - It "Skip versions with 1 digit" { - $actualOutput = Format-Versions -Versions @("14", "v2") - $expectedOutput = @() - $actualOutput | Should -Be $expectedOutput - } -} - -Describe "Select-VersionsByFilter" { - $inputVersions = @("8.2.1", "9.3.3", "10.0.2", "10.0.3", "10.5.6", "12.4.3", "12.5.1", "14.2.0") - - It "Include filter only" { - $includeFilters = @("8.*", "14.*") - $excludeFilters = @() - $actualOutput = Select-VersionsByFilter -Versions $inputVersions -IncludeFilters $includeFilters -ExcludeFilters $excludeFilters - $expectedOutput = @("8.2.1", "14.2.0") - $actualOutput | Should -Be $expectedOutput - } - - It "Include and exclude filters" { - $includeFilters = @("10.*", "12.*") - $excludeFilters = @("10.0.*", "12.4.3") - $actualOutput = Select-VersionsByFilter -Versions $inputVersions -IncludeFilters $includeFilters -ExcludeFilters $excludeFilters - $expectedOutput = @("10.5.6", "12.5.1") - $actualOutput | Should -Be $expectedOutput - } - - It "Exclude filter only" { - $includeFilters = @() - $excludeFilters = @("10.*", "12.*") - $actualOutput = Select-VersionsByFilter -Versions $inputVersions -IncludeFilters $includeFilters -ExcludeFilters $excludeFilters - $expectedOutput = @("8.2.1", "9.3.3", "14.2.0") - $actualOutput | Should -Be $expectedOutput - } - - It "Include and exclude filters are empty" { - $actualOutput = Select-VersionsByFilter -Versions $inputVersions - $expectedOutput = @("8.2.1", "9.3.3", "10.0.2", "10.0.3", "10.5.6", "12.4.3", "12.5.1", "14.2.0") - $actualOutput | Should -Be $expectedOutput - } -} - -Describe "Skip-ExistingVersions" { - It "Substract versions correctly" { - $distInput = @("14.2.0", "14.3.0", "14.4.0", "14.4.1") - $manifestInput = @("12.0.0", "14.2.0", "14.4.0") - $actualOutput = Skip-ExistingVersions -VersionsFromDist $distInput -VersionsFromManifest $manifestInput - $expectedOutput = @("14.3.0", "14.4.1") - $actualOutput | Should -Be $expectedOutput - } -} \ No newline at end of file From 5b7cb28e2ed33cf3668d81e4ca5f60c4691a12ce Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Wed, 9 Dec 2020 14:30:30 +0300 Subject: [PATCH 09/10] fix nitpicks --- get-new-tool-versions/get-new-tool-versions.ps1 | 14 ++------------ get-new-tool-versions/parsers/python-parser.psm1 | 1 - 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/get-new-tool-versions/get-new-tool-versions.ps1 b/get-new-tool-versions/get-new-tool-versions.ps1 index 9c707db..91a739f 100644 --- a/get-new-tool-versions/get-new-tool-versions.ps1 +++ b/get-new-tool-versions/get-new-tool-versions.ps1 @@ -2,18 +2,8 @@ .SYNOPSIS Check and return list of new available tool versions -.PARAMETER DistURL -Required parameter. Link to the json file included all available tool versions -.PARAMETER ManifestLink -Required parameter. Link to the the version-manifest.json file -.PARAMETER VersionFilterToInclude -Optional parameter. List of filters to include particular versions -.PARAMETER VersionFilterToExclude -Optional parameter. List of filters to exclude particular versions -.PARAMETER RetryIntervalSec -Optional parameter. Retry interval in seconds -.PARAMETER RetryCount -Optional parameter. Retry count +.PARAMETER ToolName +Required parameter. The name of tool for which parser is available (Node, Go, Python) #> param ( diff --git a/get-new-tool-versions/parsers/python-parser.psm1 b/get-new-tool-versions/parsers/python-parser.psm1 index c67e5ca..5cbb7bc 100644 --- a/get-new-tool-versions/parsers/python-parser.psm1 +++ b/get-new-tool-versions/parsers/python-parser.psm1 @@ -41,7 +41,6 @@ class PythonVersionsParser: BaseVersionsParser { switch ($Label) { "a" { return "alpha" } "b" { return "beta" } - "rc" { return "rc" } } return $Label From 2e6d8df3453528f53fd72d82e76bb5e4473277d4 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Wed, 9 Dec 2020 15:17:11 +0300 Subject: [PATCH 10/10] fix comments --- get-new-tool-versions/get-new-tool-versions.ps1 | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/get-new-tool-versions/get-new-tool-versions.ps1 b/get-new-tool-versions/get-new-tool-versions.ps1 index 91a739f..e2f0474 100644 --- a/get-new-tool-versions/get-new-tool-versions.ps1 +++ b/get-new-tool-versions/get-new-tool-versions.ps1 @@ -19,10 +19,9 @@ $VersionsFromManifest = $ToolVersionParser.GetUploadedVersions() $VersionsToBuild = $VersionsFromDist | Where-Object { $VersionsFromManifest -notcontains $_ } if ($VersionsToBuild) { - $availableVersions = $VersionsToBuild -join "," - $toolVersions = $availableVersions.Replace(",",", ") - Write-Host "The following versions are available to build:`n$toolVersions" - Write-Host "##vso[task.setvariable variable=TOOL_VERSIONS;isOutput=true]$toolVersions" + $availableVersions = $VersionsToBuild -join ", " + Write-Host "The following versions are available to build:`n${availableVersions}" + Write-Host "##vso[task.setvariable variable=TOOL_VERSIONS;isOutput=true]${availableVersions}" } else { Write-Host "There aren't versions to build" }