Skip to content

Commit 4bb966c

Browse files
authored
Automatically package executables for releases (#4)
* Automatically package executables for releases * Updated to better package into executables for mac/windows/linux * Allow additional serial port descriptors to be passed in via command line Build executable locally * fix
1 parent 5ac9247 commit 4bb966c

File tree

6 files changed

+159
-13
lines changed

6 files changed

+159
-13
lines changed

.github/workflows/package.yml

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
name: Package
2+
3+
on:
4+
# pull_request:
5+
# branches: [main]
6+
push:
7+
branches: [main]
8+
release:
9+
types: [published]
10+
workflow_dispatch:
11+
12+
jobs:
13+
build_windows:
14+
15+
runs-on: windows-latest
16+
continue-on-error: false
17+
18+
steps:
19+
- name: Checkout repo
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Set up Python
25+
uses: actions/setup-python@v5
26+
id: id_python_313
27+
with:
28+
python-version: '3.13'
29+
30+
- name: PyInstaller
31+
working-directory: .
32+
shell: pwsh
33+
run: |
34+
# setup the python environment
35+
${{ steps.id_python_313.outputs.python-path }} -m pip install -r requirements.txt
36+
# now build the installer
37+
${{ steps.id_python_313.outputs.python-path }} -m PyInstaller --clean src/uart_serial_plotter.spec
38+
$artifact="uart_serial_plotter_$(git describe --tags --dirty)_windows.exe"
39+
mv dist/uart_serial_plotter.exe ${artifact}
40+
"windowsArtifact=${artifact}" | Out-File -FilePath $env:GITHUB_ENV -Append
41+
42+
- uses: actions/upload-artifact@v4
43+
with:
44+
name: ${{ env.windowsArtifact }}
45+
path: ${{ env.windowsArtifact }}
46+
47+
- name: Attach UART Serial Plotter (Windows) Build to release
48+
uses: softprops/action-gh-release@v2
49+
if: ${{ github.event.release && github.event.action == 'published' }}
50+
with:
51+
files: ${{ env.windowsArtifact }}
52+
53+
build_linux:
54+
55+
runs-on: ubuntu-latest
56+
continue-on-error: false
57+
58+
steps:
59+
- name: Checkout repo
60+
uses: actions/checkout@v4
61+
with:
62+
fetch-depth: 0
63+
64+
- name: Set up Python
65+
uses: actions/setup-python@v5
66+
id: id_python_313
67+
with:
68+
python-version: '3.13'
69+
70+
- name: PyInstaller
71+
working-directory: .
72+
run: |
73+
# setup the python environment
74+
${{ steps.id_python_313.outputs.python-path }} -m pip install -r requirements.txt
75+
# now build the installer
76+
${{ steps.id_python_313.outputs.python-path }} -m PyInstaller --clean src/uart_serial_plotter.spec
77+
artifact="uart_serial_plotter_$(git describe --tags --dirty)_linux.bin"
78+
mv dist/uart_serial_plotter $artifact
79+
echo "linuxArtifact=$artifact" >> "$GITHUB_ENV"
80+
81+
- uses: actions/upload-artifact@v4
82+
with:
83+
name: ${{ env.linuxArtifact }}
84+
path: ${{ env.linuxArtifact }}
85+
86+
- name: Attach UART Serial Plotter (Linux) Build to release
87+
uses: softprops/action-gh-release@v2
88+
if: ${{ github.event.release && github.event.action == 'published' }}
89+
with:
90+
files: ${{ env.linuxArtifact }}
91+
92+
build_macos:
93+
94+
runs-on: macos-latest
95+
continue-on-error: false
96+
97+
steps:
98+
- name: Setup XCode
99+
uses: maxim-lobanov/setup-xcode@v1
100+
with:
101+
xcode-version: latest-stable
102+
103+
- name: Set up Python
104+
uses: actions/setup-python@v5
105+
id: id_python_313
106+
with:
107+
python-version: '3.13'
108+
109+
- name: Checkout repo
110+
uses: actions/checkout@v4
111+
with:
112+
fetch-depth: 0
113+
114+
- name: PyInstaller
115+
working-directory: .
116+
run: |
117+
# setup the python environment
118+
${{ steps.id_python_313.outputs.python-path }} -m pip install -r requirements.txt
119+
# now build the installer
120+
${{ steps.id_python_313.outputs.python-path }} -m PyInstaller --clean src/uart_serial_plotter.spec
121+
artifact="uart_serial_plotter_$(git describe --tags --dirty)_macos.bin"
122+
mv dist/uart_serial_plotter $artifact
123+
echo "macosArtifact=$artifact" >> "$GITHUB_ENV"
124+
125+
- uses: actions/upload-artifact@v4
126+
with:
127+
name: ${{ env.macosArtifact }}
128+
path: ${{ env.macosArtifact }}
129+
130+
- name: Attach UART Serial Plotter (MacOS) Build to release
131+
uses: softprops/action-gh-release@v2
132+
if: ${{ github.event.release && github.event.action == 'published' }}
133+
with:
134+
files: ${{ env.macosArtifact }}

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ pip install -r requirements.txt
2929

3030
``` console
3131
source env/bin/activate
32-
cd src
33-
pyinstaller uart_serial_plotter.spec
32+
python -m pyinstaller --clean src/uart_serial_plotter.spec
3433
```
3534

3635
## Quick Start

requirements.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
PyQt5==5.15.10
2-
pyqtgraph==0.12.3
3-
pyserial==3.5
4-
setuptools==57.4.0
1+
PyQt5
2+
pyqtgraph
3+
pyserial
4+
pyinstaller

src/list_serial_ports.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import sys
22
import serial
33

4+
port_descriptors = ["USB Serial Port", "TTL232R-3V3", "USB UART", "USB to UART", "usbserial", "RS232", "USB-UART", "USB Single Serial", "USB JTAG/serial debug unit", "FT231X USB UART"]
5+
6+
def add_port_descriptor(desc):
7+
global port_descriptors
8+
port_descriptors.append(desc)
49

510
def list_serial_ports():
11+
global port_descriptors
612
"""Lists serial port names
713
:raises EnvironmentError:
814
On unsupported or unknown platforms
915
:returns:
1016
A list of the serial ports available on the system
1117
"""
12-
port_descriptors = ["USB Serial Port", "TTL232R-3V3", "USB UART", "USB to UART", "usbserial", "RS232", "USB-UART", "USB Single Serial", "USB JTAG/serial debug unit", "FT231X USB UART"]
1318
ports = list(serial.tools.list_ports.comports())
1419
result = []
1520
# print("Found {} ports:".format(len(ports)))

src/main.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@
44
from PyQt5 import QtGui
55
import signal
66

7+
from list_serial_ports import add_port_descriptor
8+
79
signal.signal(signal.SIGINT, signal.SIG_DFL)
810
import sys
911

1012
from resource_helpers import path
1113

12-
1314
def main():
15+
# get the arguments, and if there are any, add them as allowed port descriptors
16+
for arg in sys.argv[1:]:
17+
print("Adding port descriptor: '{}'".format(arg))
18+
add_port_descriptor(arg)
19+
1420
app = QApplication(sys.argv)
1521
app.setWindowIcon(QtGui.QIcon(path("images/icon.png")))
1622
MainWindow()

src/uart_serial_plotter.spec

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ a = Analysis(['main.py'],
1818
cipher=block_cipher,
1919
noarchive=False)
2020

21-
a.datas += Tree('../images', prefix='images/')
21+
a.datas += Tree('./images', prefix='images/')
2222

2323
pyz = PYZ(a.pure, a.zipped_data,
2424
cipher=block_cipher)
@@ -28,13 +28,15 @@ exe = EXE(pyz,
2828
a.binaries,
2929
a.zipfiles,
3030
a.datas,
31-
[],
32-
name='UART Serial Plotter',
31+
name='uart_serial_plotter',
3332
debug=False,
3433
bootloader_ignore_signals=False,
3534
strip=False,
3635
upx=True,
37-
upx_exclude=[],
3836
runtime_tmpdir=None,
3937
console=False,
40-
icon='../images/icon.ico')
38+
disable_windowed_traceback=False,
39+
target_arch=None,
40+
codesign_identity=None,
41+
entitlements_file=None,
42+
icon='./images/icon.ico')

0 commit comments

Comments
 (0)