forked from wojiushixiaobai/Python-Embed-Win64
-
Notifications
You must be signed in to change notification settings - Fork 1
118 lines (100 loc) · 4.25 KB
/
Copy pathbuild_package.yml
File metadata and controls
118 lines (100 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
name: Build Embedded Python Package
on:
workflow_dispatch:
inputs:
python_tag:
description: "Python embed release tag (example: 3.14.4)"
required: true
default: "3.14.4"
requirements_url:
description: "URL to requirements.txt"
required: true
output_zip_name:
description: "Output zip file name (example: python-custom.zip)"
required: true
default: "python-custom.zip"
permissions:
contents: write
jobs:
build-package:
runs-on: windows-latest
steps:
- name: Checkout Code
uses: actions/checkout@v5
- name: Download and extract embedded Python
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
$tag = "${{ inputs.python_tag }}"
$embedZip = "python-$tag-embed-amd64.zip"
$releaseUrl = "https://github.com/jumpserver-dev/Python-Embed-Win64/releases/download/$tag/$embedZip"
Write-Host "Downloading from: $releaseUrl"
Invoke-WebRequest -Uri $releaseUrl -OutFile $embedZip
Expand-Archive -Path $embedZip -DestinationPath python-embed -Force
Write-Host "Embedded Python extracted to python-embed"
- name: Enable import site in embedded Python
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
$pthFile = Get-ChildItem -Path python-embed -Filter "python*._pth" | Select-Object -First 1
if (-not $pthFile) {
throw "Cannot find python*._pth in python-embed"
}
$content = Get-Content -Path $pthFile.FullName -Raw
if ($content -match "#import site") {
$content = $content -replace "#import site", "import site"
Set-Content -Path $pthFile.FullName -Value $content -NoNewline
Write-Host "Enabled import site in $($pthFile.Name)"
} elseif ($content -notmatch "import site") {
Add-Content -Path $pthFile.FullName -Value "`r`nimport site"
Write-Host "Added import site to $($pthFile.Name)"
} else {
Write-Host "import site already enabled"
}
- name: Install pip and requirements
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
$pythonExe = (Resolve-Path "python-embed/python.exe").Path
Write-Host "Downloading requirements from: ${{ inputs.requirements_url }}"
Invoke-WebRequest -Uri "${{ inputs.requirements_url }}" -OutFile "requirements.txt"
Write-Host "Installing requirements"
& $pythonExe -m pip install -r requirements.txt
if ($LASTEXITCODE -ne 0) {
throw "pip install failed with exit code $LASTEXITCODE"
}
- name: Remove embedded Python path isolation from package
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
$pthFile = Get-ChildItem -Path python-embed -Filter "python*._pth" | Select-Object -First 1
if (-not $pthFile) {
throw "Cannot find python*._pth in python-embed"
}
Remove-Item -Path $pthFile.FullName -Force
Write-Host "Removed path isolation file from package: $($pthFile.Name)"
- name: Pack embedded Python to zip
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
$zipName = "${{ inputs.output_zip_name }}"
if (-not $zipName.EndsWith(".zip")) {
$zipName = "$zipName.zip"
}
$stageRoot = Join-Path $PWD "__package_stage"
if (Test-Path $stageRoot) {
Remove-Item -Path $stageRoot -Recurse -Force
}
$pythonRoot = Join-Path $stageRoot "Python"
New-Item -Path $pythonRoot -ItemType Directory -Force | Out-Null
Copy-Item -Path "python-embed/*" -Destination $pythonRoot -Recurse -Force
Compress-Archive -Path $pythonRoot -DestinationPath $zipName -Force
Remove-Item -Path $stageRoot -Recurse -Force
Write-Host "Created package: $zipName"
"OUTPUT_ZIP=$zipName" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Upload zip to GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ inputs.python_tag }}
files: ${{ env.OUTPUT_ZIP }}
overwrite_files: true