Skip to content

Commit 4ad0666

Browse files
author
Stefan Träger
committed
Renamed directory and added macos step
1 parent a02d2ea commit 4ad0666

File tree

3 files changed

+178
-196
lines changed

3 files changed

+178
-196
lines changed

.github/workflows/build.yml

Lines changed: 60 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -56,68 +56,58 @@ jobs:
5656
path: dist/windows/PlantUML2DrawIO/**
5757
if-no-files-found: error
5858

59-
#build-macos:
60-
# runs-on: macos-latest
61-
# steps:
62-
# - uses: actions/checkout@v4
63-
64-
# - name: Set up Python
65-
# uses: actions/setup-python@v5
66-
# with:
67-
# python-version: '3.11'
68-
69-
# - name: Install dependencies
70-
# run: |
71-
# python -m pip install --upgrade pip
72-
# pip install -r requirements-build.txt
73-
74-
# - name: Update version numbers
75-
# shell: python
76-
# run: |
77-
# import re
78-
# import os
79-
# from datetime import datetime
80-
81-
# # Get version from git tag
82-
# version = os.environ['GITHUB_REF'].split('/')[-1].replace('v', '')
83-
84-
# Update version in files
85-
# files_to_update = [
86-
# 'src/plantuml2drawio/app.py',
87-
# 'src/plantuml2drawio/config.py',
88-
# 'src/plantuml2drawio/__init__.py',
89-
# 'setup.py'
90-
# ]
91-
92-
# for file_path in files_to_update:
93-
# with open(file_path, 'r', encoding='utf-8') as f:
94-
# content = f.read()
95-
96-
# Update version strings
97-
# content = re.sub(r'VERSION = "[^"]*"', f'VERSION = "{version}"', content)
98-
# content = re.sub(r'__version__ = "[^"]*"', f'__version__ = "{version}"', content)
99-
# content = re.sub(r'version="[^"]*"', f'version="{version}"', content)
100-
101-
# Update version date in config.py
102-
# if 'config.py' in file_path:
103-
# today = datetime.now().strftime('%Y-%m-%d')
104-
# content = re.sub(r'VERSION_DATE = "[^"]*"', f'VERSION_DATE = "{today}"', content)
105-
106-
# with open(file_path, 'w', encoding='utf-8') as f:
107-
# f.write(content)
108-
109-
# - name: Build macOS app
110-
# run: python -m PyInstaller --clean p2d.spec
111-
112-
# - name: Upload macOS artifact
113-
# uses: actions/upload-artifact@v4
114-
# with:
115-
# name: p2d-macos
116-
# path: dist/p2d.app
59+
build-macos:
60+
runs-on: macos-latest
61+
steps:
62+
- uses: actions/checkout@v4
63+
64+
- name: Set up Python
65+
uses: actions/setup-python@v5
66+
with:
67+
python-version: '3.11'
68+
69+
- name: Install dependencies
70+
run: |
71+
python -m pip install --upgrade pip
72+
pip install -r requirements-build.txt
73+
74+
- name: Update version numbers
75+
shell: python
76+
run: |
77+
import re, os
78+
from datetime import datetime
79+
version = os.environ['GITHUB_REF'].split('/')[-1].replace('v', '')
80+
files_to_update = [
81+
'src/plantuml2drawio/app.py',
82+
'src/plantuml2drawio/config.py',
83+
'src/plantuml2drawio/__init__.py',
84+
'setup.py'
85+
]
86+
for path in files_to_update:
87+
txt = open(path, encoding='utf-8').read()
88+
txt = re.sub(r'VERSION = "[^"]*"', f'VERSION = "{version}"', txt)
89+
txt = re.sub(r'__version__ = "[^"]*"', f'__version__ = "{version}"', txt)
90+
txt = re.sub(r'version="[^"]*"', f'version="{version}"', txt)
91+
if path.endswith('config.py'):
92+
txt = re.sub(r'VERSION_DATE = "[^"]*"', f'VERSION_DATE = "{datetime.now():%Y-%m-%d}"', txt)
93+
open(path, 'w', encoding='utf-8').write(txt)
94+
95+
- name: Build macOS app
96+
run: |
97+
python build_mac.py
98+
working-directory: build-scripts
99+
100+
- name: Upload macOS artifact
101+
uses: actions/upload-artifact@v4
102+
with:
103+
name: p2d-macos
104+
path: dist/mac/**
105+
if-no-files-found: error
117106

118107
create-release:
119-
needs: [build-windows]
108+
needs: [build-windows, build-macos]
120109
runs-on: ubuntu-latest
110+
if: startsWith(github.ref, 'refs/tags/')
121111

122112
steps:
123113
- uses: actions/download-artifact@v4
@@ -131,17 +121,22 @@ jobs:
131121
zip -r ../p2d-windows.zip .
132122
cd ..
133123
134-
#- name: Create macOS ZIP
135-
# run: |
136-
# cd p2d-macos
137-
# zip -r ../p2d-macos.zip p2d.app
138-
# cd ..
124+
- uses: actions/download-artifact@v4
125+
with:
126+
name: p2d-mac
127+
path: mac
128+
129+
- name: Create macOS ZIP
130+
run: |
131+
cd mac
132+
zip -r ../p2d-macos.zip .
133+
cd ..
139134
140135
- name: Create Release
141136
uses: softprops/action-gh-release@v1
142137
with:
143138
files: |
144139
p2d-windows.zip
145-
# p2d-macos.zip
140+
p2d-macos.zip
146141
env:
147142
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build-Scripts/build_windows.py

Lines changed: 0 additions & 131 deletions
This file was deleted.

build-scripts/build_mac.py

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Build script for creating amacOS (.app) bundle
4+
Run this *on macOS* - PyInstaller cannot cross-compile
5+
"""
6+
import subprocess
7+
import sys
8+
import os
9+
import platform
10+
from pathlib import Path
11+
import argparse
12+
import shutil
13+
import tempfile
14+
15+
def build_mac(codesign=False, identity=None, entitlements=None, notarize=False, team_id=None, apple_id=None, asc_password=None):
16+
project_root = Path(__file__).parent.parent
17+
os.chdir(project_root)
18+
19+
dist_dir = project_root / "dist" / "mac"
20+
build_dir = project_root / "build" / "mac"
21+
22+
shutil.rmtree(dist_dir, ignore_errors=True)
23+
shutil.rmtree(build_dir, ignore_errors=True)
24+
25+
cmd = [
26+
"python", "-m", "PyInstaller",
27+
"--name=PlantUML2DrawIO",
28+
"--windowed",
29+
"--onedir",
30+
"--clean",
31+
"--noconfirm",
32+
"--paths=src",
33+
"--add-data=src/plantuml2drawio:plantuml2drawio",
34+
"--hidden-import=plantuml2drawio",
35+
"--icon=resources/icons/p2d_icon.icns",
36+
f"--distpath={dist_dir}",
37+
f"--workpath={build_dir}",
38+
"src/plantuml2drawio/app.py"
39+
]
40+
41+
print("Building macOS application bundle…")
42+
print("Command:", " ".join(cmd))
43+
44+
try:
45+
subprocess.run(cmd, check=True)
46+
app_path = dist_dir / "PlantUML2DrawIO.app"
47+
print(f"Built: {app_path}")
48+
49+
if codesign:
50+
sign_app(app_path, identity, entitlements)
51+
if notarize:
52+
notarize_app(app_path, team_id, apple_id, asc_password)
53+
54+
except subprocess.CalledProcessError as e:
55+
print("Build failed")
56+
print(e.stdout or "", e.stderr or "")
57+
sys.exit(1)
58+
59+
def sign_app(app_path, identity, entitlements=None):
60+
"""Code-sign the .app so Gatekeeper lets it run on other Macs."""
61+
if not identity:
62+
print("--codesign supplied but no --identity given; skipping codesign.")
63+
return
64+
cmd = [
65+
"codesign", "--deep", "--force",
66+
"--options", "runtime",
67+
"--sign", identity,
68+
str(app_path)
69+
]
70+
if entitlements:
71+
cmd.extend(["--entitlements", str(entitlements)])
72+
73+
print("Signing…")
74+
subprocess.run(cmd, check=True)
75+
print("Signed")
76+
77+
def notarize_app(app_path, team_id, apple_id, asc_password):
78+
"""Submit the .app (zipped) to Apple notarization and staple the ticket."""
79+
if not (team_id and apple_id and asc_password):
80+
print("⚠️ --notarize needs --team-id, --apple-id and --asc-password.")
81+
return
82+
83+
zip_path = Path(tempfile.gettempdir()) / (app_path.stem + ".zip")
84+
shutil.make_archive(zip_path.with_suffix(""), 'zip', root_dir=app_path)
85+
print("Uploading to Apple notarization service…")
86+
87+
submit = [
88+
"xcrun", "notarytool",
89+
"submit", str(zip_path),
90+
"--team-id", team_id,
91+
"--apple-id", apple_id,
92+
"--password", asc_password,
93+
"--wait" # waits until approval / failure
94+
]
95+
subprocess.run(submit, check=True)
96+
97+
print("Stapling ticket…")
98+
subprocess.run(["xcrun", "stapler", "staple", str(app_path)], check=True)
99+
print("Notarized & stapled")
100+
101+
if __name__ == "__main__":
102+
if platform.system() != "Darwin":
103+
sys.exit("⚠️ This script must be run on macOS (Darwin).")
104+
105+
p = argparse.ArgumentParser(description="Build macOS .app bundle")
106+
p.add_argument("--codesign", action="store_true",
107+
help="Code-sign the resulting .app")
108+
p.add_argument("--identity", help="Developer ID Application identity")
109+
p.add_argument("--entitlements", help="Path to entitlements.plist")
110+
p.add_argument("--notarize", action="store_true",
111+
help="After signing, notarize the app with Apple")
112+
p.add_argument("--team-id", help="Apple Team ID (10 chars)")
113+
p.add_argument("--apple-id", help="Apple ID used for notarization")
114+
p.add_argument("--asc-password",help="App-specific password or keychain item")
115+
116+
args = p.parse_args()
117+
build_mac(args.codesign, args.identity, args.entitlements,
118+
args.notarize, args.team_id, args.apple_id, args.asc_password)

0 commit comments

Comments
 (0)