From a7532795547eaf24ad4955c18ee0cac5b7add50f Mon Sep 17 00:00:00 2001 From: Maksim Shilov <89912354+shilovmaksim@users.noreply.github.com> Date: Wed, 27 Oct 2021 10:31:19 +0300 Subject: [PATCH] New parser for xamarin and python. Reworked workflow with composite actions (#41) --- .../send-slack-notification/action.yml | 39 +++++++++ .github/workflows/get-tools-new-versions.yml | 82 +++++++++++++++++++ .github/workflows/get-xamarin-versions.yml | 69 ---------------- .../send-slack-notification.ps1 | 14 ++-- ...verify-new-tool-version-added-to-image.ps1 | 48 +++++++++++ 5 files changed, 178 insertions(+), 74 deletions(-) create mode 100644 .github/actions/send-slack-notification/action.yml create mode 100644 .github/workflows/get-tools-new-versions.yml delete mode 100644 .github/workflows/get-xamarin-versions.yml create mode 100644 get-new-tool-versions/verify-new-tool-version-added-to-image.ps1 diff --git a/.github/actions/send-slack-notification/action.yml b/.github/actions/send-slack-notification/action.yml new file mode 100644 index 0000000..42062d3 --- /dev/null +++ b/.github/actions/send-slack-notification/action.yml @@ -0,0 +1,39 @@ +name: 'Send Slack notification' +description: 'SendSlack notification about new versions of a tool' +inputs: + url: + required: true + description: 'Slack channel url' + tool-name: + required: true + description: 'Name of a tool to send notification for. Like Xamarin or Python' + default: 'Xamarin' + tool-version: + required: false + description: 'New versions of a tool' + pipeline-url: + required: false + description: 'Url of a pipeline' + image-url: + required: false + description: 'Image url for message' + default: 'https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png' + text: + required: false + description: 'Message text' + add-to-toolset-flag: + required: false + description: 'Flag to use notification for adding new versions to toolset' +runs: + using: "composite" + steps: + - id: send-slack-notification + name: Send Slack notification + shell: pwsh + run: ./get-new-tool-versions/send-slack-notification.ps1 -Url "${{ inputs.url }}" ` + -ToolName "${{ inputs.tool-name }}" ` + -ToolVersion "${{ inputs.tool-version }}" ` + -PipelineUrl "${{ inputs.pipeline-url }}" ` + -ImageUrl "${{ inputs.image-url }}" ` + -Text "${{ inputs.text }}" ` + ${{ inputs.add-to-toolset-flag }} diff --git a/.github/workflows/get-tools-new-versions.yml b/.github/workflows/get-tools-new-versions.yml new file mode 100644 index 0000000..729ac15 --- /dev/null +++ b/.github/workflows/get-tools-new-versions.yml @@ -0,0 +1,82 @@ +name: Get tools new versions +on: + schedule: + - cron: '0 8 * * THU' + workflow_dispatch: + +defaults: + run: + shell: pwsh + +jobs: + find-new-xamarin-versions: + name: Searching for new Xamarin versions + runs-on: ubuntu-latest + outputs: + versions-output: ${{ steps.get-new-xamarin-versions.outputs.versions-output }} + steps: + - uses: actions/checkout@v2 + - id: get-new-xamarin-versions + name: Get new Xamarin versions + run: echo "::set-output name=versions-output::$(./get-new-tool-versions/verify-new-tool-version-added-to-image.ps1 -ToolName Xamarin)" + + check-new-xamarin-versions: + name: Verifying new Xamarin versions exist + runs-on: ubuntu-latest + needs: find-new-xamarin-versions + steps: + - uses: actions/checkout@v2 + - name: Check Versions + if: needs.find-new-xamarin-versions.outputs.versions-output == '' + run: Write-Host "No new versions found" + - uses: ./.github/actions/send-slack-notification + if: needs.find-new-xamarin-versions.outputs.versions-output != '' + with: + url: ${{ secrets.SLACK_CHANNEL_URL }} + tool-name: 'Xamarin' + tool-version: ${{ needs.find-new-xamarin-versions.outputs.versions-output }} + image-url: 'https://avatars.githubusercontent.com/u/790012?s=200&v=4' + add-to-toolset-flag: '-AddToToolsetFlag' + + find-new-python-versions: + name: Searching for new Python versions + runs-on: ubuntu-latest + outputs: + versions-output: ${{ steps.get-new-python-versions.outputs.versions-output }} + steps: + - uses: actions/checkout@v2 + - id: get-new-python-versions + name: Get new Python versions + run: echo "::set-output name=versions-output::$(./get-new-tool-versions/verify-new-tool-version-added-to-image.ps1 -ToolName Python)" + + check-new-python-versions: + name: Verifying new Python versions exist + runs-on: ubuntu-latest + needs: find-new-python-versions + steps: + - uses: actions/checkout@v2 + - name: Check Versions + if: needs.find-new-python-versions.outputs.versions-output == '' + run: Write-Host "No new versions found" + - uses: ./.github/actions/send-slack-notification + if: needs.find-new-python-versions.outputs.versions-output != '' + with: + url: ${{ secrets.SLACK_CHANNEL_URL }} + tool-name: 'Python' + tool-version: ${{ needs.find-new-python-versions.outputs.versions-output }} + image-url: 'https://www.python.org/static/community_logos/python-powered-h-100x130.png' + add-to-toolset-flag: '-AddToToolsetFlag' + + check_build: + name: Check build for failures + runs-on: ubuntu-latest + needs: [check-new-xamarin-versions, check-new-python-versions] + if: failure() + steps: + - uses: actions/checkout@v2 + - uses: ./.github/actions/send-slack-notification + with: + url: ${{ secrets.SLACK_CHANNEL_URL }} + tool-name: 'Python or Xamarin' + pipeline-url: '$env:GITHUB_SERVER_URL/$env:GITHUB_REPOSITORY/actions/runs/$env:GITHUB_RUN_ID' + text: "The build of the Xamarin or Python detection pipeline has failed stages:" diff --git a/.github/workflows/get-xamarin-versions.yml b/.github/workflows/get-xamarin-versions.yml deleted file mode 100644 index 2e8960e..0000000 --- a/.github/workflows/get-xamarin-versions.yml +++ /dev/null @@ -1,69 +0,0 @@ -name: Get Xamarin versions -on: - schedule: - - cron: '0 8 * * THU' - workflow_dispatch: - -env: - TOOL_NAME: "Xamarin" -defaults: - run: - shell: pwsh - -jobs: - find_new_versions: - name: Find new versions - runs-on: ubuntu-latest - outputs: - versions_output: ${{ steps.Get_new_versions.outputs.TOOL_VERSIONS }} - steps: - - uses: actions/checkout@v2 - - - id: Get_new_versions - name: Get new versions - run: ./get-new-tool-versions/get-new-tool-versions.ps1 -ToolName ${{ env.TOOL_NAME }} - - check_new_versions: - name: Check new versions - runs-on: ubuntu-latest - needs: find_new_versions - env: - TOOL_VERSIONS: ${{needs.find_new_versions.outputs.versions_output}} - steps: - - uses: actions/checkout@v2 - - - name: Check Versions - if: success() && env.TOOL_VERSIONS == '' - run: | - Write-Host "No new versions were found" - Import-Module "./github/github-api.psm1" - $gitHubApi = Get-GitHubApi -RepositoryFullName "$env:GITHUB_REPOSITORY" ` - -AccessToken "${{ secrets.GITHUB_TOKEN }}" - - $gitHubApi.CancelWorkflow("$env:GITHUB_RUN_ID") - Start-Sleep -Seconds 60 - - - name: Send Slack notification - run: | - $message = "The following versions of '${{ env.TOOL_NAME }}' are available, consider adding them to toolset: ${{ env.TOOL_VERSIONS }}" - ./get-new-tool-versions/send-slack-notification.ps1 -Url "${{ secrets.SLACK_CHANNEL_URL }}" ` - -ToolName "${{ env.TOOL_NAME }}" ` - -ImageUrl "https://avatars.githubusercontent.com/u/790012?s=200&v=4" ` - -Text "$message" - - check_build: - name: Check build for failures - runs-on: ubuntu-latest - needs: [find_new_versions, check_new_versions] - if: failure() - steps: - - uses: actions/checkout@v2 - - - name: Send Slack notification if build fails - run: | - $pipelineUrl = "$env:GITHUB_SERVER_URL/$env:GITHUB_REPOSITORY/actions/runs/$env:GITHUB_RUN_ID" - $message = "The build of the '${{ env.TOOL_NAME }}' detection pipeline failed :progress-error:\nLink to the pipeline: $pipelineUrl" - ./get-new-tool-versions/send-slack-notification.ps1 -Url "${{ secrets.SLACK_CHANNEL_URL }}" ` - -ToolName "${{ env.TOOL_NAME }}" ` - -Text "$message" ` - -ImageUrl "https://avatars.githubusercontent.com/u/790012?s=200&v=4" diff --git a/get-new-tool-versions/send-slack-notification.ps1 b/get-new-tool-versions/send-slack-notification.ps1 index 05be9c6..c609a4b 100644 --- a/get-new-tool-versions/send-slack-notification.ps1 +++ b/get-new-tool-versions/send-slack-notification.ps1 @@ -14,6 +14,8 @@ Optional parameter. The pipeline URL Optional parameter. The image URL .PARAMETER Text Optional parameter. The message to post +.PARAMETER AddToToolsetFlag +Optional parameter. Flag to alternate message text for adding new version of a tool to toolset notification #> param( @@ -28,7 +30,8 @@ param( [System.String]$ToolVersion, [System.String]$PipelineUrl, [System.String]$ImageUrl = 'https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png', - [System.String]$Text + [System.String]$Text, + [Switch]$AddToToolsetFlag ) # Import helpers module @@ -36,15 +39,16 @@ Import-Module $PSScriptRoot/helpers.psm1 -DisableNameChecking # Create JSON body if ([string]::IsNullOrWhiteSpace($Text)) { - if ($toolName -eq "Xamarin") { + if ($AddToToolsetFlag) { $Text = "The following versions of '$toolName' are available, consider adding them to toolset: $toolVersion" } else { $Text = "The following versions of '$toolName' are available to upload: $toolVersion" } - if (-not ([string]::IsNullOrWhiteSpace($PipelineUrl))) { - $Text += "\nLink to the pipeline: $pipelineUrl" - } } +if (-not ([string]::IsNullOrWhiteSpace($PipelineUrl))) { + $Text += "\nLink to the pipeline: $pipelineUrl" +} + $jsonBodyMessage = @" { "blocks": [ diff --git a/get-new-tool-versions/verify-new-tool-version-added-to-image.ps1 b/get-new-tool-versions/verify-new-tool-version-added-to-image.ps1 new file mode 100644 index 0000000..da09401 --- /dev/null +++ b/get-new-tool-versions/verify-new-tool-version-added-to-image.ps1 @@ -0,0 +1,48 @@ +<# +.SYNOPSIS +Check and return list of new available tool versions that not added to toolsets yet + +.PARAMETER ToolName +Required parameter. The name of tool for which parser is available (Python, Xamarin) +#> + +param ( + [Parameter(Mandatory)] + [ValidateSet("Python", "Xamarin")] + [string]$ToolName +) + +if ($ToolName -eq "Python") { + $pythonVesionsManifestUrl = "https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json" + $builtStableMinorVersions = (Invoke-RestMethod $pythonVesionsManifestUrl) | + Where-Object stable -eq $true | + ForEach-Object {$_.version.split(".")[0,1] -join"."} | + Select-Object -Unique + $toolsetUrl = "https://raw.githubusercontent.com/actions/virtual-environments/main/images/win/toolsets/toolset-2019.json" + $latestExistingMinorVesion = ((Invoke-RestMethod $toolsetUrl).toolcache | + Where-Object {$_.name -eq "Python" -and $_.arch -eq "x64"}).versions | + ForEach-Object {$_.split(".")[0,1] -join"."} | + Select-Object -Last 1 + $versionsToAdd = $builtStableMinorVersions | Where-Object {[version]$_ -gt [version]$latestExistingMinorVesion} +} + +if ($ToolName -eq "Xamarin") { + $xamarinReleases = (Invoke-RestMethod "http://aka.ms/manifest/stable").items + $xamarinProducts = @('Mono Framework', 'Xamarin.Android', 'Xamarin.iOS', 'Xamarin.Mac') + $filteredReleases = $xamarinReleases | Where-Object {$_.name -in $xamarinProducts} | Sort-Object name | Select-Object name, version + $toolsetUrl = "https://raw.githubusercontent.com/actions/virtual-environments/main/images/macos/toolsets/toolset-11.json" + $uploadedReleases = (Invoke-RestMethod $toolsetUrl).xamarin + $releasesOnImage = @{ + 'Mono Framework' = $uploadedReleases.'mono-versions' + 'Xamarin.Android' = $uploadedReleases.'android-versions' + 'Xamarin.iOS' = $uploadedReleases.'ios-versions' + 'Xamarin.Mac' = $uploadedReleases.'mac-versions' + } + $versionsToAdd = $filteredReleases | Where-Object {$releasesOnImage[$_.name] -notcontains $_.version } | ForEach-Object {[string]::Empty} { + '{0,-15} : {1}' -f $_.name, $_.version + } + $joinChars = "\n\t" +} +$versionsToAdd = $versionsToAdd -join $joinChars + +return $versionsToAdd