Skip to content

Commit 3ec6c98

Browse files
Add ability to choose platform to build Python
1 parent 797eb71 commit 3ec6c98

File tree

1 file changed

+36
-33
lines changed

1 file changed

+36
-33
lines changed

.github/workflows/python-builder.yml

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ on:
1111
description: 'Whether to publish releases'
1212
required: true
1313
default: 'false'
14+
PLATFORMS:
15+
description: 'Platforms for execution in "os" or "os_arch" format (arch is "x64" by default)'
16+
required: true
17+
default: 'ubuntu-18.04,ubuntu-20.04,macos-10.15,windows-2019_x64,windows-2019_x86'
1418
pull_request:
1519
paths-ignore:
1620
- 'versions-manifest.json'
@@ -26,26 +30,40 @@ defaults:
2630
shell: pwsh
2731

2832
jobs:
33+
generate_matrix:
34+
runs-on: ubuntu-latest
35+
outputs:
36+
matrix: ${{ steps.generate-matrix.outputs.matrix }}
37+
steps:
38+
- name: Generate execution matrix
39+
id: generate-matrix
40+
run: |
41+
$configurations = "${{ github.event.inputs.platforms }}".Split(",").Trim()
42+
$matrix = @()
43+
44+
foreach ($configuration in $configurations) {
45+
$parts = $configuration.Split("_")
46+
$os = $parts[0]
47+
$arch = $(if ($parts[1]) {$parts[1]} else {"x64"})
48+
switch -wildcard ($os) {
49+
"*ubuntu*" { $platform = $os.Replace("ubuntu","linux")}
50+
"*macos*" { $platform = 'darwin' }
51+
"*windows*" { $platform = 'win32' }
52+
}
53+
$matrix += @{
54+
'platform' = $platform
55+
'os' = $os
56+
'arch' = $arch
57+
}
58+
}
59+
echo "::set-output name=matrix::$($matrix | ConvertTo-Json -Compress)"
60+
2961
build_python:
62+
needs: generate_matrix
3063
strategy:
3164
fail-fast: false
3265
matrix:
33-
include:
34-
- platform: 'linux-18.04'
35-
os: 'ubuntu-18.04'
36-
arch: 'x64'
37-
- platform: 'linux-20.04'
38-
os: 'ubuntu-20.04'
39-
arch: 'x64'
40-
- platform: 'darwin'
41-
os: 'macos-10.15'
42-
arch: 'x64'
43-
- platform: 'win32'
44-
os: 'windows-2019'
45-
arch: 'x64'
46-
- platform: 'win32'
47-
os: 'windows-2019'
48-
arch: 'x86'
66+
include: ${{ fromJson(needs.generate_matrix.outputs.matrix) }}
4967
runs-on: ${{ matrix.os }}
5068
env:
5169
ARTIFACT_NAME: python-${{ github.event.inputs.VERSION || '3.9.9' }}-${{ matrix.platform }}-${{ matrix.arch }}
@@ -68,26 +86,11 @@ jobs:
6886
path: ${{ runner.temp }}/artifact
6987

7088
test_python:
71-
needs: build_python
89+
needs: [generate_matrix, build_python]
7290
strategy:
7391
fail-fast: false
7492
matrix:
75-
include:
76-
- platform: 'linux-18.04'
77-
os: 'ubuntu-18.04'
78-
arch: 'x64'
79-
- platform: 'linux-20.04'
80-
os: 'ubuntu-20.04'
81-
arch: 'x64'
82-
- platform: 'darwin'
83-
os: 'macos-10.15'
84-
arch: 'x64'
85-
- platform: 'win32'
86-
os: 'windows-2019'
87-
arch: 'x64'
88-
- platform: 'win32'
89-
os: 'windows-2019'
90-
arch: 'x86'
93+
include: ${{ fromJson(needs.generate_matrix.outputs.matrix) }}
9194
runs-on: ${{ matrix.os }}
9295
env:
9396
ARTIFACT_NAME: python-${{ github.event.inputs.VERSION || '3.9.9' }}-${{ matrix.platform }}-${{ matrix.arch }}

0 commit comments

Comments
 (0)