-
Notifications
You must be signed in to change notification settings - Fork 1
116 lines (100 loc) · 3.57 KB
/
python-app.yml
File metadata and controls
116 lines (100 loc) · 3.57 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
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: Python application
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
permissions:
contents: write
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python 3.11
uses: actions/setup-python@v3
with:
python-version: "3.11"
- name: Extract latest version from commits
id: extract-version
run: |
$version = git log --pretty=format:%s | ForEach-Object {
if ($_ -match '^v\d+(\.\d+)+') {
$matches[0]
}
} | Select-Object -First 1
if (-not $version) {
throw "No version tag found in git log."
}
echo "Latest version: $version"
echo "VERSION_TAG=$version" >> $env:GITHUB_ENV
shell: pwsh
- name: Get latest UPX version
id: get-upx
run: |
$response = Invoke-RestMethod -Uri "https://api.github.com/repos/upx/upx/releases/latest"
$version = $response.tag_name -replace 'v',''
$downloadUrl = $response.assets | Where-Object { $_.name -match 'win64\.zip$' } | Select-Object -ExpandProperty browser_download_url
echo "UPX_VERSION=$version" >> $env:GITHUB_ENV
echo "UPX_URL=$downloadUrl" >> $env:GITHUB_ENV
echo "UPX_DIR=upx-$version-win64" >> $env:GITHUB_ENV
shell: pwsh
- name: Install UPX
run: |
# Clean up any previous failed attempts
Remove-Item -Path upx -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -Path upx.zip -Force -ErrorAction SilentlyContinue
# Download and extract
Invoke-WebRequest -Uri $env:UPX_URL -OutFile upx.zip
Expand-Archive -Path upx.zip -DestinationPath upx -Force
# Verify UPX works
& "$env:GITHUB_WORKSPACE\upx\$env:UPX_DIR\upx.exe" --version
shell: pwsh
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
shell: cmd
- name: Build the application
run: |
pyinstaller app.spec --upx-dir="$env:GITHUB_WORKSPACE\upx\$env:UPX_DIR"
shell: pwsh
- name: Get application name
id: app-name
run: |
$appName = Get-ChildItem -Path dist | Where-Object { $_.PSIsContainer } | Select-Object -ExpandProperty Name
echo "APP_NAME=$appName" >> $env:GITHUB_ENV
shell: pwsh
- name: Archive the built program
run: |
mkdir release
Compress-Archive -Path "dist\$env:APP_NAME\*" -DestinationPath "release\$env:APP_NAME.zip"
shell: pwsh
- name: Delete existed tag
env:
GITHUB_TOKEN: ${{ secrets.BUILDER_PAT }}
run: |
try {
gh release delete $env:VERSION_TAG --yes
} catch {
Write-Host "No existing release found, skipped deleting."
}
try {
git push origin ":refs/tags/$env:VERSION_TAG"
} catch {
Write-Host "No existing tag found, skipped deleting."
}
shell: pwsh
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.BUILDER_PAT }}
with:
tag_name: ${{ env.VERSION_TAG }}
name: ${{ env.APP_NAME }}
files: release/${{ env.APP_NAME }}.zip
body: Automatically built and released by GitHub Actions.