Adding python-versions-runner workflow (#137)

This commit is contained in:
Maksim Shilov 2022-02-18 15:14:27 +03:00 committed by GitHub
parent 797eb71c41
commit e74fccfe13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 114 additions and 0 deletions

View File

@ -0,0 +1,31 @@
name: Python versions runner
on:
workflow_dispatch:
inputs:
versions:
description: 'Versions to build'
required: true
default: '","'
publish-releases:
description: 'Whether to publish releases'
required: true
default: 'false'
defaults:
run:
shell: pwsh
jobs:
trigger_builds:
name: Trigger python build
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v2
- name: Trigger python workflow
run: |
$versions = ${{ github.event.inputs.versions }}
./builders/python-versions-runner.ps1 -Versions $versions.Split(",") -PublishRelease ${{ github.event.inputs.publish-releases }}
env:
PERSONAL_TOKEN: ${{ secrets.PERSONAL_TOKEN }}

View File

@ -0,0 +1,52 @@
function Invoke-Workflow {
param (
[string] $Version,
[string] $PublishRelease
)
$payload = @{
"ref" = "main"
"inputs" = @{
"VERSION" = "$Version"
"PUBLISH_RELEASES" = "$PublishRelease"
}
} | ConvertTo-Json
$headers = @{
Authorization="Bearer $env:PERSONAL_TOKEN"
}
$actionsRepoUri = "$env:GITHUB_API_URL/repos/$env:GITHUB_REPOSITORY/actions"
Invoke-RestMethod -uri "$actionsRepoUri/workflows/python-builder.yml/dispatches" -method POST -headers $headers -body $payload
$result = [PSCustomObject]@{
Version = $Version
Conclusion = "failure"
Url = "Not run"
}
# Triggering workflow and verifying that it has been triggered with retries
while (-not $workflowToCheck) {
Start-Sleep -seconds 40
$workflowRuns = (Invoke-RestMethod "$actionsRepoUri/runs").workflow_runs | Where-Object {$_.status -like "*progress*" -and $_.id -ne $env:GITHUB_RUN_ID}
$workflowToCheck = $workflowRuns | Where-Object {
(Invoke-RestMethod "$actionsRepoUri/runs/$($_.id)/jobs").jobs.steps.name -like "*$Version"
}
$retries++
if ($retries -gt 10) {
Write-Host "Workflow triggered for version '$Version' not found or something went wrong with fetching the workflow status"
return $result
}
}
# Waiting for workflow to complete
while ($workflowToCheck.status -ne "completed") {
Start-Sleep -Seconds 120
$workflowToCheck = Invoke-RestMethod "$actionsRepoUri/runs/$($workflowToCheck.id)"
Write-Host "Workflow run with Id: $($workflowToCheck.id) for version '$Version' - status '$($workflowToCheck.status)'"
}
$result.Conclusion = $workflowToCheck.conclusion
$result.Url = $workflowToCheck.html_url
if ($workflowToCheck.conclusion -ne "success") {
Write-Host "Triggered workflow for version '$Version' completed unsuccessfully with result '$($workflowToCheck.conclusion)'. Check the logs: $($workflowToCheck.html_url)"
return $result
}
Write-Host "Triggered workflow for version '$Version' succeeded; Url: $($workflowToCheck.html_url)"
return $result
}

View File

@ -0,0 +1,31 @@
<#
.SYNOPSIS
Generate Python artifact.
.DESCRIPTION
Script that triggering and fetching the result of the "Build python package" workflows with provided python versions
.PARAMETER Version
Required parameter. Python versions to trigger builds for.
.PARAMETER PublishRelease
Switch parameter. Whether to publish release for built version.
#>
param(
[Parameter (Mandatory=$true, HelpMessage="Python version to trigger build for")]
[array] $Versions,
[Parameter (Mandatory=$false, HelpMessage="Whether to publish release for built version")]
[string] $PublishRelease
)
$summary = $Versions | ForEach-Object -Parallel {
Import-Module "./builders/invoke-workflow.psm1"
Invoke-Workflow -Version $_ -PublishRelease $Using:PublishRelease
}
Write-Host "Results of triggered workflows:"
$summary | Out-String
if ($summary.Conclusion -contains "failure" -or $summary.Conclusion -contains "cancelled") {
exit 1
}