Skip to content

Commit f8d437e

Browse files
committed
add pyinstaller CI workflows
1 parent ca5b9e8 commit f8d437e

9 files changed

Lines changed: 199 additions & 0 deletions

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: PyInstaller Release Builds
2+
3+
on:
4+
#push:
5+
# branches: [ main, develop ]
6+
workflow_dispatch:
7+
8+
jobs:
9+
pyinstaller_build:
10+
name: Build for ${{ matrix.os }}
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
os: [windows-latest, ubuntu-latest, macos-latest, ubuntu-24.04-arm]
16+
include:
17+
- os: windows-latest
18+
artifact_name: pyocd-windows
19+
- os: ubuntu-latest
20+
artifact_name: pyocd-linux
21+
- os: macos-latest
22+
artifact_name: pyocd-macos
23+
- os: ubuntu-24.04-arm
24+
artifact_name: pyocd-linux-arm64
25+
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v4
29+
30+
- name: Setup Python
31+
uses: actions/setup-python@v5
32+
with:
33+
python-version: '3.11'
34+
cache: 'pip'
35+
36+
- name: Install package
37+
run: pip install .
38+
39+
- name: Setup build environment
40+
id: setup
41+
run: python get_site-packages.py
42+
43+
- name: Verify environment
44+
run: |
45+
echo "Site packages: ${{ env.SITE_PACKAGES }}"
46+
python -c "import sys; print(sys.version)"
47+
48+
- name: Build with PyInstaller
49+
run: |
50+
pip install pyinstaller
51+
pyinstaller pyocd.spec --log-level=ERROR --clean
52+
53+
- name: Test binary
54+
run: ./dist/pyocd/pyocd --help
55+
if: success()
56+
- name: Upload artifacts
57+
uses: actions/upload-artifact@v4
58+
if: success()
59+
with:
60+
name: pyocd-${{ matrix.os }}
61+
path: dist/pyocd/*
62+
retention-days: 7
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Create Release
2+
3+
on:
4+
release:
5+
types: [prereleased]
6+
branch: cbuild-run-dev
7+
8+
jobs:
9+
trigger-reusable:
10+
uses: your-org/your-repo/.github/workflows/reusable-workflow.yml@${{github.ref_name}}
11+
with:
12+
example-input: "test"
13+
version: ${{ github.event.release.tag_name }}
14+
secrets:
15+
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
16+
17+
retrieve-artifacts:
18+
needs: trigger-reusable
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Download artifact
22+
uses: actions/download-artifact@v4
23+
with:
24+
name: pyocd-artifact
25+
26+
- name: List files
27+
run: ls -l

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ lib
3030
lib64
3131
__pycache__
3232
*.spec
33+
!pyocd.spec
3334

3435
# Installer logs
3536
pip-log.txt

build.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
pip3 install .
4+
python3 get_site-packages.py
5+
6+
rm -R build
7+
rm -R dist
8+
9+
#export value returned from get_site-packages.py
10+
export $(python3 get_site-packages.py)
11+
12+
pyinstaller pyocd.spec --log-level=ERROR --clean
13+
14+
./dist/pyocd/pyocd list --version

get_site-packages.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import subprocess
2+
import sys
3+
import re
4+
import os
5+
6+
def get_site_packages():
7+
result = subprocess.run([sys.executable, '-m', 'site'],
8+
capture_output=True,
9+
text=True)
10+
11+
paths = result.stdout.split('\n')
12+
for line in paths:
13+
if 'site-packages' in line:
14+
match = re.search(r"'([^']*site-packages)'", line)
15+
if match:
16+
return match.group(1)
17+
18+
raise RuntimeError("Could not find site-packages directory")
19+
20+
if __name__ == "__main__":
21+
site_packages = get_site_packages()
22+
23+
# Check if running in GitHub Actions
24+
github_env = os.getenv('GITHUB_ENV')
25+
if github_env:
26+
with open(github_env, "a") as env_file:
27+
env_file.write(f"SITE_PACKAGES={site_packages}\n")
28+
else:
29+
print(f"SITE_PACKAGES={site_packages}")

pyocd.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from pyocd.__main__ import main
2+
3+
if __name__ == '__main__':
4+
main()

pyocd.spec

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# --- Imports ---
2+
import os
3+
import sys
4+
from PyInstaller.utils.hooks import get_package_paths, collect_entry_point, collect_dynamic_libs
5+
6+
# --- Configuration ---
7+
SITE_PACKAGES = os.getenv('SITE_PACKAGES', '')
8+
APP_NAME = 'pyocd'
9+
DEBUG = False
10+
11+
# --- Entry Points ---
12+
datas_probe, hiddenimports_probe = collect_entry_point('pyocd.probe')
13+
datas_rtos, hiddenimports_rtos = collect_entry_point('pyocd.rtos')
14+
15+
# --- Data Files ---
16+
datas = [
17+
(get_package_paths('pyocd')[1], 'pyocd'),
18+
(get_package_paths('pylink')[1], 'pylink'),
19+
('pyocd/debug/sequences/sequences.lark', 'pyocd/debug/sequences'),
20+
('pyocd/debug/svd/svd_data.zip', 'pyocd/debug/svd')
21+
]
22+
datas.append((get_package_paths('cmsis_pack_manager')[1], 'cmsis_pack_manager'))
23+
24+
# --- Analysis Configuration ---
25+
a = Analysis(
26+
['pyocd.py'],
27+
pathex=[],
28+
binaries=collect_dynamic_libs('cmsis_pack_manager') + collect_dynamic_libs('libusb_package'),
29+
datas=datas + datas_probe + datas_rtos,
30+
hiddenimports=hiddenimports_probe + hiddenimports_rtos,
31+
excludes=['tkinter'],
32+
runtime_hooks=[],
33+
cipher=None,
34+
noarchive=False
35+
)
36+
37+
# --- Build Components ---
38+
pyz = PYZ(a.pure, a.zipped_data)
39+
40+
exe = EXE(
41+
pyz,
42+
a.scripts,
43+
[], # Empty list for directory build
44+
exclude_binaries=True,
45+
name=APP_NAME,
46+
debug=DEBUG,
47+
strip=False,
48+
upx=True,
49+
console=True
50+
)
51+
52+
# --- Output Collection ---
53+
coll = COLLECT(
54+
exe,
55+
a.binaries,
56+
a.zipfiles,
57+
a.datas,
58+
strip=False,
59+
upx=True,
60+
name=APP_NAME
61+
)

pyocd_logo.png

92.2 KB
Loading

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cmsis-pack-manager

0 commit comments

Comments
 (0)