Skip to content

Commit 59e54b2

Browse files
mikhailkoliadaMikhail Koliada
authored andcommitted
Migrate python-versions pipeline to GH Actions
1 parent c310309 commit 59e54b2

File tree

4 files changed

+230
-7
lines changed

4 files changed

+230
-7
lines changed

.github/workflows/create-pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ jobs:
3030
-BranchName "update-versions-manifest-file" `
3131
-CommitMessage "Update versions-manifest" `
3232
-PullRequestTitle "[versions-manifest] Update for release from ${formattedDate}" `
33-
-PullRequestBody "Update versions-manifest.json for release from ${formattedDate}"
33+
-PullRequestBody "Update versions-manifest.json for release from ${formattedDate}"
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
name: Build python package
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
VERSION:
7+
description: 'Python version to build and upload'
8+
default: '3.9.6'
9+
required: true
10+
PUBLISH_RELEASES:
11+
description: 'Whether to publish releases'
12+
required: true
13+
default: 'false'
14+
pull_request:
15+
paths-ignore:
16+
- 'versions-manifest.json'
17+
- 'LICENSE'
18+
- '**.md'
19+
branches:
20+
- 'main'
21+
22+
env:
23+
VERSION: ${{ github.event.inputs.VERSION}}
24+
defaults:
25+
run:
26+
shell: pwsh
27+
28+
jobs:
29+
build_python:
30+
strategy:
31+
fail-fast: false
32+
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'
49+
runs-on: ${{ matrix.os }}
50+
env:
51+
ARTIFACT_NAME: python-${{ github.event.inputs.VERSION }}-${{ matrix.platform }}-${{ matrix.arch }}
52+
steps:
53+
54+
- name: Check out repository code
55+
uses: actions/checkout@v2
56+
with:
57+
submodules: true
58+
59+
- name: Build Python ${{ env.VERSION }}
60+
shell: pwsh
61+
run: |
62+
./builders/build-python.ps1 -Version $env:VERSION `
63+
-Platform ${{ matrix.platform }} -Architecture ${{ matrix.arch }}
64+
65+
- name: Publish artifact
66+
uses: actions/upload-artifact@v2
67+
with:
68+
name: ${{ env.ARTIFACT_NAME }}
69+
path: ${{ runner.temp }}/artifact
70+
71+
test_python:
72+
needs: build_python
73+
strategy:
74+
fail-fast: false
75+
matrix:
76+
include:
77+
- platform: 'linux-18.04'
78+
os: 'ubuntu-18.04'
79+
arch: 'x64'
80+
- platform: 'linux-20.04'
81+
os: 'ubuntu-20.04'
82+
arch: 'x64'
83+
- platform: 'darwin'
84+
os: 'macos-10.15'
85+
arch: 'x64'
86+
- platform: 'win32'
87+
os: 'windows-2019'
88+
arch: 'x64'
89+
- platform: 'win32'
90+
os: 'windows-2019'
91+
arch: 'x86'
92+
runs-on: ${{ matrix.os }}
93+
env:
94+
ARTIFACT_NAME: python-${{ github.event.inputs.VERSION }}-${{ matrix.platform }}-${{ matrix.arch }}
95+
steps:
96+
97+
- name: Check out repository code
98+
uses: actions/checkout@v2
99+
with:
100+
submodules: true
101+
102+
- name: Fully cleanup the toolcache directory before testing
103+
run: ./helpers/clean-toolcache.ps1 -ToolName "Python"
104+
105+
- name: Download artifact
106+
uses: actions/download-artifact@v2
107+
with:
108+
path: ${{ runner.temp }}
109+
110+
- name: Extract files
111+
run: |
112+
if ('${{ matrix.platform }}' -eq 'win32') {
113+
$artifactName = "${{ env.ARTIFACT_NAME }}.zip"
114+
7z.exe x "$artifactName" -y | Out-Null
115+
} else {
116+
$artifactName = "${{ env.ARTIFACT_NAME }}.tar.gz"
117+
tar -xzf $artifactName
118+
}
119+
working-directory: ${{ runner.temp }}/${{ env.ARTIFACT_NAME }}
120+
121+
- name: Apply build artifact to the local machine
122+
run: |
123+
if ('${{ matrix.platform }}' -eq 'win32') { powershell ./setup.ps1 } else { sh ./setup.sh }
124+
if ('${{ matrix.platform }}' -ne 'win32') {
125+
cp ${{ runner.temp }}/${{ env.ARTIFACT_NAME }}/build_output.txt ${{ runner.temp }}
126+
}
127+
128+
working-directory: ${{ runner.temp }}/${{ env.ARTIFACT_NAME }}
129+
130+
- name: Setup Python ${{ env.VERSION }}
131+
uses: actions/setup-python@v2
132+
with:
133+
python-version: ${{ env.VERSION }}
134+
135+
- name: Verbose sysconfig dump
136+
run: |
137+
if ('${{ matrix.platform }}' -ne 'win32') { python ./sources/python-config-output.py }
138+
working-directory: ${{ github.workspace }}/tests
139+
140+
- name: Verbose python binary links
141+
run: |
142+
$pythonLocation = which python
143+
if ('${{ matrix.platform }}' -ne 'win32') {
144+
if ('${{ matrix.platform }}' -eq 'darwin') { otool -L $pythonLocation } else { ldd $pythonLocation }
145+
}
146+
147+
- name: Run tests
148+
shell: pwsh
149+
run: |
150+
Install-Module Pester -Force -Scope CurrentUser -RequiredVersion 4.10.1
151+
Import-Module Pester
152+
$pesterParams = @{
153+
Path="./python-tests.ps1";
154+
Parameters=@{
155+
Version="${{ env.VERSION }}";
156+
Platform="${{ matrix.platform }}";
157+
}
158+
}
159+
$Result = Invoke-Pester -PassThru -Script $pesterParams -OutputFile "test_results.xml" -OutputFormat NUnitXml
160+
if ($Result.FailedCount -gt 0) {
161+
$host.SetShouldExit($Result.FailedCount)
162+
exit $Result.FailedCount
163+
}
164+
165+
working-directory: ${{ github.workspace }}/tests
166+
167+
publish_release:
168+
name: Publish release
169+
if: github.event_name == 'workflow_dispatch' && github.event.inputs.PUBLISH_RELEASES == 'true'
170+
needs: test_python
171+
runs-on: ubuntu-latest
172+
steps:
173+
- uses: actions/download-artifact@v2
174+
175+
- name: Publish Release ${{ env.VERSION }}
176+
id: create_release
177+
uses: actions/create-release@v1
178+
env:
179+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
180+
with:
181+
tag_name: ${{ env.VERSION }}-${{ github.run_id }}
182+
release_name: ${{ env.VERSION }}
183+
body: |
184+
Python ${{ env.VERSION }}
185+
186+
- name: Upload release assets
187+
uses: actions/github-script@v2
188+
with:
189+
github-token: ${{ secrets.GITHUB_TOKEN }}
190+
script: |
191+
const fs = require('fs');
192+
for (let artifactDir of fs.readdirSync('.')) {
193+
let artifactName = fs.readdirSync(`${artifactDir}`)[0];
194+
console.log(`Upload ${artifactName} asset`);
195+
github.repos.uploadReleaseAsset({
196+
owner: context.repo.owner,
197+
repo: context.repo.repo,
198+
release_id: ${{ steps.create_release.outputs.id }},
199+
name: artifactName,
200+
data: fs.readFileSync(`./${artifactDir}/${artifactName}`)
201+
});
202+
}
203+
204+
trigger_pr:
205+
name: Trigger "Create Pull Request" workflow
206+
needs: publish_release
207+
runs-on: ubuntu-latest
208+
steps:
209+
- name: Trigger "Create Pull Request" workflow
210+
uses: actions/github-script@v3
211+
with:
212+
github-token: ${{ secrets.PERSONAL_TOKEN }}
213+
script: |
214+
github.actions.createWorkflowDispatch({
215+
owner: context.repo.owner,
216+
repo: context.repo.repo,
217+
workflow_id: 'create-pr.yml',
218+
ref: 'main'
219+
});
220+

builders/python-builder.psm1

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@ class PythonBuilder {
4141
PythonBuilder ([semver] $version, [string] $architecture, [string] $platform) {
4242
$this.InstallationTemplatesLocation = Join-Path -Path $PSScriptRoot -ChildPath "../installers"
4343

44-
$this.HostedToolcacheLocation = $env:AGENT_TOOLSDIRECTORY
45-
$this.TempFolderLocation = $env:BUILD_SOURCESDIRECTORY
46-
$this.WorkFolderLocation = $env:BUILD_BINARIESDIRECTORY
47-
$this.ArtifactFolderLocation = $env:BUILD_STAGINGDIRECTORY
44+
New-Item -Force -Type Directory (Join-Path $env:RUNNER_TEMP "artifact")
45+
New-Item -Force -Type Directory (Join-Path $env:RUNNER_TEMP "work")
46+
47+
$this.HostedToolcacheLocation = $env:RUNNER_TOOL_CACHE
48+
$this.TempFolderLocation = $env:RUNNER_TEMP
49+
$this.WorkFolderLocation = Join-Path $env:RUNNER_TEMP "work"
50+
$this.ArtifactFolderLocation = Join-Path $env:RUNNER_TEMP "artifact"
4851

4952
$this.Version = $version
5053
$this.Architecture = $architecture

tests/python-tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Describe "Tests" {
3939
"python --version" | Should -ReturnZeroExitCode
4040
$pythonLocation = (Get-Command "python").Path
4141
$pythonLocation | Should -Not -BeNullOrEmpty
42-
$expectedPath = Join-Path -Path $env:AGENT_TOOLSDIRECTORY -ChildPath "Python"
42+
$expectedPath = Join-Path -Path $env:RUNNER_TOOL_CACHE -ChildPath "Python"
4343
$pythonLocation.startsWith($expectedPath) | Should -BeTrue
4444
}
4545

@@ -61,7 +61,7 @@ Describe "Tests" {
6161
if (IsNixPlatform $Platform) {
6262

6363
It "Check for failed modules in build_output" {
64-
$buildOutputLocation = Join-Path $env:BUILD_BINARIESDIRECTORY "build_output.txt"
64+
$buildOutputLocation = Join-Path $env:RUNNER_TEMP "build_output.txt"
6565
Analyze-MissingModules $buildOutputLocation | Should -Be 0
6666
}
6767

0 commit comments

Comments
 (0)