diff --git a/.github/actions/find-new-tool-versions/action.yml b/.github/actions/find-new-tool-versions/action.yml new file mode 100644 index 0000000..243c36b --- /dev/null +++ b/.github/actions/find-new-tool-versions/action.yml @@ -0,0 +1,19 @@ +name: 'Find new versions' +description: 'Find new versions of a tool' +inputs: + tool-name: + required: true + description: 'Name of a tool to search versions for. Like Xamarin or Python' + default: 'Xamarin' +outputs: + versions-output: + description: "New versions found" + value: ${{ steps.get-new-versions.outputs.versions-output }} +runs: + using: "composite" + steps: + - uses: actions/checkout@v2 + - id: get-new-versions + name: Get new versions + shell: pwsh + run: echo "::set-output name=versions-output::$(./get-new-tool-versions/verify-new-tool-version-added-to-image.ps1 -ToolName ${{ inputs.tool-name }})" diff --git a/.github/actions/send-slack-notification/action.yml b/.github/actions/send-slack-notification/action.yml new file mode 100644 index 0000000..53ec310 --- /dev/null +++ b/.github/actions/send-slack-notification/action.yml @@ -0,0 +1,35 @@ +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' +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 }}" diff --git a/.github/workflows/get-xamarin-versions.yml b/.github/workflows/get-xamarin-versions.yml index 2e8960e..8192a98 100644 --- a/.github/workflows/get-xamarin-versions.yml +++ b/.github/workflows/get-xamarin-versions.yml @@ -1,69 +1,87 @@ -name: Get Xamarin versions +name: Get tools new 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 + find-new-xamarin-versions: + name: Searching for new Xamarin versions runs-on: ubuntu-latest outputs: - versions_output: ${{ steps.Get_new_versions.outputs.TOOL_VERSIONS }} + versions-output: ${{ steps.get-new-xamarin-versions.outputs.versions-output }} 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 + - id: get-new-xamarin-versions + uses: ./.github/actions/find-new-tool-versions + with: + tool-name: 'Xamarin' + + check-new-xamarin-versions: + name: Verifying new Xamarin versions exist runs-on: ubuntu-latest - needs: find_new_versions - env: - TOOL_VERSIONS: ${{needs.find_new_versions.outputs.versions_output}} + needs: find-new-xamarin-versions 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 - + 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' - 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" - + run: Write-Host "New versions found '${{ needs.find-new-xamarin-versions.outputs.versions-output }}'" + + 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 + uses: ./.github/actions/find-new-tool-versions + with: + tool-name: '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://avatars.githubusercontent.com/u/790012?s=200&v=4' + - name: Send Slack notification + run: Write-Host "New versions found '${{ needs.find-new-python-versions.outputs.versions-output }}'" + check_build: name: Check build for failures runs-on: ubuntu-latest - needs: [find_new_versions, check_new_versions] + needs: [check-new-xamarin-versions, check-new-python-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" + - uses: ./.github/actions/send-slack-notification + with: + url: ${{ secrets.SLACK_CHANNEL_URL }} + tool-name: 'Xamarin or Python' + pipeline-url: '${{ $env:GITHUB_SERVER_URL }}/${{ $env:GITHUB_REPOSITORY }}/actions/runs/${{ $env:GITHUB_RUN_ID }}' + image-url: 'https://avatars.githubusercontent.com/u/790012?s=200&v=4' + text: "The build of the Xamarin or Python detection pipeline failed :progress-error:" diff --git a/get-new-tool-versions/send-slack-notification.ps1 b/get-new-tool-versions/send-slack-notification.ps1 index 05be9c6..770db35 100644 --- a/get-new-tool-versions/send-slack-notification.ps1 +++ b/get-new-tool-versions/send-slack-notification.ps1 @@ -36,7 +36,7 @@ Import-Module $PSScriptRoot/helpers.psm1 -DisableNameChecking # Create JSON body if ([string]::IsNullOrWhiteSpace($Text)) { - if ($toolName -eq "Xamarin") { + if ($toolName -eq ("Xamarin" -or "Python")) { $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" 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..5c36249 --- /dev/null +++ b/get-new-tool-versions/verify-new-tool-version-added-to-image.ps1 @@ -0,0 +1,34 @@ +<# +.SYNOPSIS +Check and return list of new available tool versions + +.PARAMETER ToolName +Required parameter. The name of tool for which parser is available (Node, Go, Python, Xamarin) +#> + +param ( + [Parameter(Mandatory)] [string] $ToolName +) + +if ($ToolName -eq "Python") { + $builtStableMinorVersionsList = ((Invoke-RestMethod "https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json") | Where-Object {$_.stable -eq "True"} | Select-Object -First 10).version | ForEach-Object {$_.split(".")[0,1] -join(".")} | Select-Object -Unique + $existingMinorVesionsList = ((Invoke-RestMethod "https://raw.githubusercontent.com/shilovmaksim/virtual-environments/main/images/win/toolsets/toolset-2019.json").toolcache | Where-Object {$_.name -eq "Python" -and $_.arch -eq "x64"}).versions | ForEach-Object {$_.split(".")[0,1] -join(".")} | Select-Object -Unique + $versionsToAdd = $builtStableMinorVersionsList | Where-Object {$_ -notin $existingMinorVesionsList} +} + +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 + $uploadedReleases = (Invoke-RestMethod "https://raw.githubusercontent.com/shilovmaksim/virtual-environments/main/images/macos/toolsets/toolset-11.json").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 + } +} +return $versionsToAdd