Skip to content

Commit 322129d

Browse files
author
Toyota Yaris 2009
committed
fix: improve build script and workflow with better debugging and platform handling
1 parent c3e679b commit 322129d

File tree

2 files changed

+176
-32
lines changed

2 files changed

+176
-32
lines changed

.github/workflows/build-and-release.yml

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,34 +44,82 @@ jobs:
4444
run: |
4545
mkdir -p dist
4646
47+
- name: Debug environment
48+
shell: bash
49+
run: |
50+
echo "OS: ${{ matrix.os }}"
51+
echo "Expected executable: ${{ matrix.executable }}"
52+
echo "Python version:"
53+
python --version
54+
echo "PyInstaller version:"
55+
pip show pyinstaller
56+
echo "Current directory:"
57+
pwd
58+
echo "Directory contents:"
59+
ls -la
60+
4761
- name: Run build script
4862
run: |
4963
python build.py
5064
51-
- name: Verify build output
65+
- name: Debug build output
5266
shell: bash
5367
run: |
54-
if [ "${{ matrix.os }}" = "windows-latest" ]; then
55-
test -f "dist/${{ matrix.executable }}" || { echo "Build failed: Windows executable not found"; exit 1; }
56-
elif [ "${{ matrix.os }}" = "macos-latest" ]; then
57-
test -d "dist/${{ matrix.executable }}" || { echo "Build failed: macOS app bundle not found"; exit 1; }
68+
echo "Contents of dist directory:"
69+
ls -la dist/
70+
echo "Contents of build directory (if exists):"
71+
if [ -d "build" ]; then
72+
ls -la build/
73+
else
74+
echo "build directory does not exist"
75+
fi
76+
echo "Contents of release directory (if exists):"
77+
if [ -d "release" ]; then
78+
ls -la release/
5879
else
59-
test -f "dist/${{ matrix.executable }}" || { echo "Build failed: Linux executable not found"; exit 1; }
80+
echo "release directory does not exist"
6081
fi
82+
echo "Contents of current directory:"
83+
ls -la
6184
62-
- name: List build output
85+
- name: Verify build output
6386
shell: bash
6487
run: |
65-
ls -la dist/
88+
if [ "${{ matrix.os }}" = "windows-latest" ]; then
89+
if [ -f "dist/${{ matrix.executable }}" ]; then
90+
echo "Windows executable found at dist/${{ matrix.executable }}"
91+
else
92+
echo "Windows executable not found at dist/${{ matrix.executable }}"
93+
echo "Searching for executable in dist directory:"
94+
find dist -type f -name "*.exe" || echo "No .exe files found"
95+
exit 1
96+
fi
97+
elif [ "${{ matrix.os }}" = "macos-latest" ]; then
98+
if [ -d "dist/${{ matrix.executable }}" ]; then
99+
echo "macOS app bundle found at dist/${{ matrix.executable }}"
100+
else
101+
echo "macOS app bundle not found at dist/${{ matrix.executable }}"
102+
echo "Searching for app bundle in dist directory:"
103+
find dist -type d -name "*.app" || echo "No .app bundles found"
104+
exit 1
105+
fi
106+
else
107+
if [ -f "dist/${{ matrix.executable }}" ]; then
108+
echo "Linux executable found at dist/${{ matrix.executable }}"
109+
else
110+
echo "Linux executable not found at dist/${{ matrix.executable }}"
111+
echo "Searching for executable in dist directory:"
112+
find dist -type f -executable || echo "No executable files found"
113+
exit 1
114+
fi
115+
fi
66116
67117
- name: Upload executable files
68118
uses: actions/upload-artifact@v4
69119
with:
70120
name: executables-${{ matrix.os }}
71-
path: |
72-
dist/${{ matrix.executable }}
73-
dist/VERSION.txt
74-
if-no-files-found: error
121+
path: dist/
122+
if-no-files-found: warn
75123
retention-days: 5
76124

77125
release:
@@ -96,8 +144,12 @@ jobs:
96144
- name: Display structure of downloaded files
97145
shell: bash
98146
run: |
99-
ls -R dist/
100-
find dist/ -type f
147+
echo "Contents of dist directory:"
148+
ls -la dist/
149+
echo "All files in dist directory (recursive):"
150+
find dist -type f | sort
151+
echo "All directories in dist directory:"
152+
find dist -type d | sort
101153
102154
- name: Get release notes
103155
id: get_release_notes

build.py

Lines changed: 110 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,29 @@ def build_executable():
3636
'--hidden-import=urllib.request',
3737
'--hidden-import=threading',
3838
'--hidden-import=validation', # Include the validation module
39-
'--add-data=validation.py:validation.py', # Include validation.py
40-
'--add-data=README.md:README.md', # Include README
41-
'--add-data=LICENSE:LICENSE', # Include LICENSE
42-
'--add-data=requirements.txt:requirements.txt', # Include requirements
4339
]
4440

41+
# Add data files
42+
data_files = [
43+
('validation.py', 'validation.py'),
44+
('README.md', 'README.md'),
45+
('LICENSE', 'LICENSE'),
46+
('requirements.txt', 'requirements.txt')
47+
]
48+
49+
for src, dest in data_files:
50+
if os.path.exists(src):
51+
cmd.append(f'--add-data={src}:{dest}')
52+
print(f"Including data file: {src}")
53+
else:
54+
print(f"Warning: Data file {src} not found, skipping")
55+
4556
# Add icon if it exists
4657
if sys.platform == 'darwin': # macOS
4758
icon_path = 'assets/icon.icns'
48-
else: # Windows/Linux
59+
elif sys.platform == 'win32': # Windows
60+
icon_path = 'assets/icon.ico'
61+
else: # Linux
4962
icon_path = 'assets/icon.ico'
5063

5164
if os.path.exists(icon_path):
@@ -56,14 +69,58 @@ def build_executable():
5669

5770
# Add assets directory if it exists
5871
if os.path.exists('assets'):
59-
cmd.append('--add-data=assets:assets')
72+
if sys.platform == 'win32': # Windows
73+
cmd.append('--add-data=assets;assets')
74+
else: # macOS and Linux
75+
cmd.append('--add-data=assets:assets')
6076
print("Including assets directory")
6177

6278
# Add the main script
6379
cmd.append('sd_formatter.py')
6480

6581
# Run PyInstaller
66-
subprocess.run(cmd, check=True)
82+
print(f"Running PyInstaller with command: {' '.join(cmd)}")
83+
result = subprocess.run(cmd, check=False, capture_output=True, text=True)
84+
85+
if result.returncode != 0:
86+
print(f"PyInstaller failed with return code {result.returncode}")
87+
print("STDOUT:")
88+
print(result.stdout)
89+
print("STDERR:")
90+
print(result.stderr)
91+
raise Exception("PyInstaller build failed")
92+
else:
93+
print("PyInstaller completed successfully")
94+
95+
# Verify the executable was created
96+
if sys.platform == 'darwin': # macOS
97+
expected_path = 'dist/PicoCalc-SD-Formatter.app'
98+
if os.path.isdir(expected_path):
99+
print(f"macOS app bundle created at: {expected_path}")
100+
else:
101+
print(f"Error: macOS app bundle not found at {expected_path}")
102+
print("Contents of dist directory:")
103+
print(os.listdir('dist'))
104+
raise FileNotFoundError(f"macOS app bundle not found at {expected_path}")
105+
elif sys.platform == 'win32': # Windows
106+
expected_path = 'dist/PicoCalc-SD-Formatter.exe'
107+
if os.path.isfile(expected_path):
108+
print(f"Windows executable created at: {expected_path}")
109+
else:
110+
print(f"Error: Windows executable not found at {expected_path}")
111+
print("Contents of dist directory:")
112+
print(os.listdir('dist'))
113+
raise FileNotFoundError(f"Windows executable not found at {expected_path}")
114+
else: # Linux
115+
expected_path = 'dist/PicoCalc-SD-Formatter'
116+
if os.path.isfile(expected_path):
117+
print(f"Linux executable created at: {expected_path}")
118+
else:
119+
print(f"Error: Linux executable not found at {expected_path}")
120+
print("Contents of dist directory:")
121+
print(os.listdir('dist'))
122+
raise FileNotFoundError(f"Linux executable not found at {expected_path}")
123+
67124
print("Build complete.")
68125

69126
def create_version_file():
@@ -92,30 +149,65 @@ def create_release_package():
92149
os.makedirs(release_dir)
93150

94151
# Copy executable and necessary files
95-
if sys.platform == 'darwin':
96-
shutil.copytree('dist/PicoCalc-SD-Formatter.app', os.path.join(release_dir, 'PicoCalc-SD-Formatter.app'))
152+
if sys.platform == 'darwin': # macOS
153+
if os.path.exists('dist/PicoCalc-SD-Formatter.app'):
154+
shutil.copytree('dist/PicoCalc-SD-Formatter.app', os.path.join(release_dir, 'PicoCalc-SD-Formatter.app'))
155+
else:
156+
print("Warning: macOS app bundle not found, skipping copy")
157+
elif sys.platform == 'win32': # Windows
158+
if os.path.exists('dist/PicoCalc-SD-Formatter.exe'):
159+
shutil.copy('dist/PicoCalc-SD-Formatter.exe', release_dir)
160+
else:
161+
print("Warning: Windows executable not found, skipping copy")
162+
else: # Linux
163+
if os.path.exists('dist/PicoCalc-SD-Formatter'):
164+
shutil.copy('dist/PicoCalc-SD-Formatter', release_dir)
165+
else:
166+
print("Warning: Linux executable not found, skipping copy")
167+
168+
# Copy version file
169+
if os.path.exists('dist/VERSION.txt'):
170+
shutil.copy('dist/VERSION.txt', release_dir)
97171
else:
98-
shutil.copy('dist/PicoCalc-SD-Formatter', release_dir)
172+
print("Warning: VERSION.txt not found, skipping copy")
99173

100-
shutil.copy('dist/VERSION.txt', release_dir)
101-
shutil.copy('README.md', release_dir)
174+
# Copy README
175+
if os.path.exists('README.md'):
176+
shutil.copy('README.md', release_dir)
177+
else:
178+
print("Warning: README.md not found, skipping copy")
102179

103180
# Create a zip file of the release
104-
shutil.make_archive(
105-
f'PicoCalc-SD-Formatter-v1.0.0-{sys.platform}',
106-
'zip',
107-
release_dir
108-
)
181+
platform_suffix = 'win' if sys.platform == 'win32' else ('mac' if sys.platform == 'darwin' else 'linux')
182+
zip_filename = f'PicoCalc-SD-Formatter-v1.0.0-{platform_suffix}'
109183

110-
print("Release package created.")
184+
try:
185+
shutil.make_archive(
186+
zip_filename,
187+
'zip',
188+
release_dir
189+
)
190+
print(f"Release package created: {zip_filename}.zip")
191+
except Exception as e:
192+
print(f"Error creating zip archive: {e}")
193+
194+
print("Release package creation complete.")
111195

112196
def main():
113197
"""Main build process"""
114198
try:
199+
print(f"Starting build process on platform: {sys.platform}")
200+
print(f"Python version: {sys.version}")
201+
print(f"Current directory: {os.getcwd()}")
202+
203+
# Create dist directory if it doesn't exist
204+
os.makedirs('dist', exist_ok=True)
205+
115206
clean_build()
116207
build_executable()
117208
create_version_file()
118209
create_release_package()
210+
119211
print("\nBuild process completed successfully!")
120212
print("\nNext steps:")
121213
print("1. Test the executable in the 'dist' directory")

0 commit comments

Comments
 (0)