Skip to content

Commit e74fccf

Browse files
authored
Adding python-versions-runner workflow (actions#137)
1 parent 797eb71 commit e74fccf

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Python versions runner
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
versions:
6+
description: 'Versions to build'
7+
required: true
8+
default: '","'
9+
publish-releases:
10+
description: 'Whether to publish releases'
11+
required: true
12+
default: 'false'
13+
14+
defaults:
15+
run:
16+
shell: pwsh
17+
18+
jobs:
19+
trigger_builds:
20+
name: Trigger python build
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Check out repository code
24+
uses: actions/checkout@v2
25+
26+
- name: Trigger python workflow
27+
run: |
28+
$versions = ${{ github.event.inputs.versions }}
29+
./builders/python-versions-runner.ps1 -Versions $versions.Split(",") -PublishRelease ${{ github.event.inputs.publish-releases }}
30+
env:
31+
PERSONAL_TOKEN: ${{ secrets.PERSONAL_TOKEN }}

builders/invoke-workflow.psm1

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
function Invoke-Workflow {
2+
param (
3+
[string] $Version,
4+
[string] $PublishRelease
5+
)
6+
7+
$payload = @{
8+
"ref" = "main"
9+
"inputs" = @{
10+
"VERSION" = "$Version"
11+
"PUBLISH_RELEASES" = "$PublishRelease"
12+
}
13+
} | ConvertTo-Json
14+
$headers = @{
15+
Authorization="Bearer $env:PERSONAL_TOKEN"
16+
}
17+
$actionsRepoUri = "$env:GITHUB_API_URL/repos/$env:GITHUB_REPOSITORY/actions"
18+
Invoke-RestMethod -uri "$actionsRepoUri/workflows/python-builder.yml/dispatches" -method POST -headers $headers -body $payload
19+
20+
$result = [PSCustomObject]@{
21+
Version = $Version
22+
Conclusion = "failure"
23+
Url = "Not run"
24+
}
25+
# Triggering workflow and verifying that it has been triggered with retries
26+
while (-not $workflowToCheck) {
27+
Start-Sleep -seconds 40
28+
$workflowRuns = (Invoke-RestMethod "$actionsRepoUri/runs").workflow_runs | Where-Object {$_.status -like "*progress*" -and $_.id -ne $env:GITHUB_RUN_ID}
29+
$workflowToCheck = $workflowRuns | Where-Object {
30+
(Invoke-RestMethod "$actionsRepoUri/runs/$($_.id)/jobs").jobs.steps.name -like "*$Version"
31+
}
32+
$retries++
33+
if ($retries -gt 10) {
34+
Write-Host "Workflow triggered for version '$Version' not found or something went wrong with fetching the workflow status"
35+
return $result
36+
}
37+
}
38+
# Waiting for workflow to complete
39+
while ($workflowToCheck.status -ne "completed") {
40+
Start-Sleep -Seconds 120
41+
$workflowToCheck = Invoke-RestMethod "$actionsRepoUri/runs/$($workflowToCheck.id)"
42+
Write-Host "Workflow run with Id: $($workflowToCheck.id) for version '$Version' - status '$($workflowToCheck.status)'"
43+
}
44+
$result.Conclusion = $workflowToCheck.conclusion
45+
$result.Url = $workflowToCheck.html_url
46+
if ($workflowToCheck.conclusion -ne "success") {
47+
Write-Host "Triggered workflow for version '$Version' completed unsuccessfully with result '$($workflowToCheck.conclusion)'. Check the logs: $($workflowToCheck.html_url)"
48+
return $result
49+
}
50+
Write-Host "Triggered workflow for version '$Version' succeeded; Url: $($workflowToCheck.html_url)"
51+
return $result
52+
}

builders/python-versions-runner.ps1

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<#
2+
.SYNOPSIS
3+
Generate Python artifact.
4+
5+
.DESCRIPTION
6+
Script that triggering and fetching the result of the "Build python package" workflows with provided python versions
7+
8+
.PARAMETER Version
9+
Required parameter. Python versions to trigger builds for.
10+
11+
.PARAMETER PublishRelease
12+
Switch parameter. Whether to publish release for built version.
13+
14+
#>
15+
16+
param(
17+
[Parameter (Mandatory=$true, HelpMessage="Python version to trigger build for")]
18+
[array] $Versions,
19+
[Parameter (Mandatory=$false, HelpMessage="Whether to publish release for built version")]
20+
[string] $PublishRelease
21+
)
22+
23+
$summary = $Versions | ForEach-Object -Parallel {
24+
Import-Module "./builders/invoke-workflow.psm1"
25+
Invoke-Workflow -Version $_ -PublishRelease $Using:PublishRelease
26+
}
27+
Write-Host "Results of triggered workflows:"
28+
$summary | Out-String
29+
if ($summary.Conclusion -contains "failure" -or $summary.Conclusion -contains "cancelled") {
30+
exit 1
31+
}

0 commit comments

Comments
 (0)