From 8c62a832045ed3cf7cae491e5ea1f063f21ec2cc Mon Sep 17 00:00:00 2001 From: Nikita Bykov Date: Tue, 17 Aug 2021 17:03:20 +0300 Subject: [PATCH 1/5] Add CancelWorkflow method to github-api.psm1 and update get-new-tool-versions.ps1 --- get-new-tool-versions/get-new-tool-versions.ps1 | 6 +++++- github/github-api.psm1 | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/get-new-tool-versions/get-new-tool-versions.ps1 b/get-new-tool-versions/get-new-tool-versions.ps1 index 75e0353..de31ffd 100644 --- a/get-new-tool-versions/get-new-tool-versions.ps1 +++ b/get-new-tool-versions/get-new-tool-versions.ps1 @@ -29,7 +29,11 @@ if ($ToolName -eq "Xamarin") { if ($VersionsToBuild) { $availableVersions = $VersionsToBuild -join $joinChars Write-Host "The following versions are available to build:`n${availableVersions}" - Write-Host "##vso[task.setvariable variable=TOOL_VERSIONS;isOutput=true]${availableVersions}" + if ($ToolName -eq "Go") { + Write-Host "::set-output name=version_number::${availableVersions}" + } else { + Write-Host "##vso[task.setvariable variable=TOOL_VERSIONS;isOutput=true]${availableVersions}" + } } else { Write-Host "There aren't versions to build" } diff --git a/github/github-api.psm1 b/github/github-api.psm1 index 3103ed0..6ba32c7 100644 --- a/github/github-api.psm1 +++ b/github/github-api.psm1 @@ -124,6 +124,11 @@ class GitHubApi } } + [void] CancelWorkflow([string]$WorkflowId) { + $url = "actions/runs/$WorkflowId/cancel" + $this.InvokeRestMethod($url, 'POST', $null, $null) + } + [object] hidden InvokeRestMethod( [string] $Url, [string] $Method, From 6b66054ab678b3824aa1c57f5a0711475897f203 Mon Sep 17 00:00:00 2001 From: Nikita Bykov Date: Thu, 19 Aug 2021 16:11:48 +0300 Subject: [PATCH 2/5] Add new parameter to send-slack-notification.ps1 and update get-new-tool-versions.ps1 --- .../get-new-tool-versions.ps1 | 7 ++--- .../send-slack-notification.ps1 | 30 ++++++++++--------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/get-new-tool-versions/get-new-tool-versions.ps1 b/get-new-tool-versions/get-new-tool-versions.ps1 index de31ffd..4672876 100644 --- a/get-new-tool-versions/get-new-tool-versions.ps1 +++ b/get-new-tool-versions/get-new-tool-versions.ps1 @@ -29,11 +29,8 @@ if ($ToolName -eq "Xamarin") { if ($VersionsToBuild) { $availableVersions = $VersionsToBuild -join $joinChars Write-Host "The following versions are available to build:`n${availableVersions}" - if ($ToolName -eq "Go") { - Write-Host "::set-output name=version_number::${availableVersions}" - } else { - Write-Host "##vso[task.setvariable variable=TOOL_VERSIONS;isOutput=true]${availableVersions}" - } + Write-Host "::set-output name=version_number::${availableVersions}" + Write-Host "##vso[task.setvariable variable=TOOL_VERSIONS;isOutput=true]${availableVersions}" } 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 3f3518a..05be9c6 100644 --- a/get-new-tool-versions/send-slack-notification.ps1 +++ b/get-new-tool-versions/send-slack-notification.ps1 @@ -7,11 +7,13 @@ Required parameter. Incoming Webhook URL to post a message .PARAMETER ToolName Required parameter. The name of tool .PARAMETER ToolVersion -Required parameter. Specifies the version of tool +Optional parameter. Specifies the version of tool .PARAMETER PipelineUrl -Required parameter. The pipeline URL +Optional parameter. The pipeline URL .PARAMETER ImageUrl Optional parameter. The image URL +.PARAMETER Text +Optional parameter. The message to post #> param( @@ -23,25 +25,25 @@ param( [ValidateNotNullOrEmpty()] [System.String]$ToolName, - [Parameter(Mandatory)] - [ValidateNotNullOrEmpty()] [System.String]$ToolVersion, - [System.String]$PipelineUrl, - [System.String]$ImageUrl = 'https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png' + [System.String]$ImageUrl = 'https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png', + [System.String]$Text ) # Import helpers module Import-Module $PSScriptRoot/helpers.psm1 -DisableNameChecking # Create JSON body -if ($toolName -eq "Xamarin") { - $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 ([string]::IsNullOrWhiteSpace($Text)) { + if ($toolName -eq "Xamarin") { + $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" + } } $jsonBodyMessage = @" { @@ -50,7 +52,7 @@ $jsonBodyMessage = @" "type": "section", "text": { "type": "mrkdwn", - "text": "$text" + "text": "$Text" }, "accessory": { "type": "image", From e9ef44e60c2afb3444cd6490fe34157ec9683299 Mon Sep 17 00:00:00 2001 From: Nikita Bykov Date: Fri, 20 Aug 2021 17:40:16 +0300 Subject: [PATCH 3/5] Rename version_number variable to TOOL_VERSIONS --- get-new-tool-versions/get-new-tool-versions.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/get-new-tool-versions/get-new-tool-versions.ps1 b/get-new-tool-versions/get-new-tool-versions.ps1 index 4672876..558dd0f 100644 --- a/get-new-tool-versions/get-new-tool-versions.ps1 +++ b/get-new-tool-versions/get-new-tool-versions.ps1 @@ -29,7 +29,7 @@ if ($ToolName -eq "Xamarin") { if ($VersionsToBuild) { $availableVersions = $VersionsToBuild -join $joinChars Write-Host "The following versions are available to build:`n${availableVersions}" - Write-Host "::set-output name=version_number::${availableVersions}" + Write-Host "::set-output name=TOOL_VERSIONS::${availableVersions}" Write-Host "##vso[task.setvariable variable=TOOL_VERSIONS;isOutput=true]${availableVersions}" } else { Write-Host "There aren't versions to build" From 9b849b3d5afa31a96752c421cb7d5a4c5dfcd08c Mon Sep 17 00:00:00 2001 From: Nikita Bykov Date: Mon, 23 Aug 2021 18:12:30 +0300 Subject: [PATCH 4/5] Move get-xamarin-versions pipeline --- .github/workflows/get-xamarin-versions.yml | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 .github/workflows/get-xamarin-versions.yml diff --git a/.github/workflows/get-xamarin-versions.yml b/.github/workflows/get-xamarin-versions.yml new file mode 100644 index 0000000..8f0c6b3 --- /dev/null +++ b/.github/workflows/get-xamarin-versions.yml @@ -0,0 +1,68 @@ +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: | + ./get-new-tool-versions/send-slack-notification.ps1 -Url "${{ secrets.SLACK_CHANNEL_URL }}" ` + -ToolName "${{ env.TOOL_NAME }}" ` + -ToolVersion "${{ env.TOOL_VERSIONS }}" ` + -ImageUrl "https://avatars.githubusercontent.com/u/790012?s=200&v=4" + + 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" From 5a00becf4740a9c1444cb2ad127100415f001af5 Mon Sep 17 00:00:00 2001 From: Nikita Bykov Date: Wed, 25 Aug 2021 15:45:33 +0300 Subject: [PATCH 5/5] Update Send Slack notification step to send a custom message --- .github/workflows/get-xamarin-versions.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/get-xamarin-versions.yml b/.github/workflows/get-xamarin-versions.yml index 8f0c6b3..2e8960e 100644 --- a/.github/workflows/get-xamarin-versions.yml +++ b/.github/workflows/get-xamarin-versions.yml @@ -45,10 +45,11 @@ jobs: - 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 }}" ` - -ToolVersion "${{ env.TOOL_VERSIONS }}" ` - -ImageUrl "https://avatars.githubusercontent.com/u/790012?s=200&v=4" + -ImageUrl "https://avatars.githubusercontent.com/u/790012?s=200&v=4" ` + -Text "$message" check_build: name: Check build for failures @@ -61,8 +62,8 @@ jobs: - 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" + $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" ` + -Text "$message" ` -ImageUrl "https://avatars.githubusercontent.com/u/790012?s=200&v=4"