-
Notifications
You must be signed in to change notification settings - Fork 11
142 lines (136 loc) · 4.95 KB
/
release.yml
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: release
on:
push:
tags:
- v[0-9]+.[0-9]+.?[0-9]*
jobs:
build:
strategy:
matrix:
include:
- os: linux
arch: x86_64
runs: ubuntu-latest
ext: ""
- os: windows
arch: x86_64
runs: windows-latest
ext: ".exe"
- os: macos
arch: x86_64
runs: macos-12
ext: ""
- os: macos
arch: arm64
runs: macos-14
ext: ""
runs-on: ${{ matrix.runs }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: "3.11"
architecture: x64 # Otherwise the runner will try to download Python arm64, which is not available. x64 has support for both archs (universal2).
- name: Install latest stable
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: Build
run: |
python -m pip install --upgrade pip
pip install "pyinstaller>=5.12"
pip install certifi
pip install maturin
pip install .[fast]
bash -c "rm -rf /tmp/orjson"
bash scripts/install_patched_orjson.sh
pyinstaller src/fig2sketch.py -y --onefile --target-arch ${{ matrix.arch }}
- name: Rename binary
run: mv dist/fig2sketch${{ matrix.ext }} dist/fig2sketch-${{ github.ref_name }}${{ matrix.ext }}
- name: zip release
uses: thedoctor0/zip-release@main
with:
type: "zip"
filename: "fig2sketch-${{ matrix.os }}-${{ matrix.arch }}.zip"
directory: "dist"
path: "*"
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: builds
path: dist/fig2sketch-${{ matrix.os }}-${{ matrix.arch }}.zip
build-macos-universal:
needs: [build]
runs-on: macos-latest
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: builds
- name: Create universal binary with lipo
# Why are we patching the binary?
# Both binaries are generated by pyinstaller. This works by archiving the python interpreter and .py files
# and then adding a binary that unarchives the content and runs them (similar to a self-extracting zip).
# The problem is that it locates the start of the archive inside the binary by looking for a specific magic value.
# Both binaries (x86_64 and arm64) use the same magic value, so after bundling in a universal binary, the bootloader
# will always find the first archive, even if it's the wrong architecture. Thus, only one architecture works.
# The binary patch applied below changes the magic value for only one of the binaries, so we have a different
# magic value to search for each architecture, which solves the problem.
# We need to re-sign the binary afterwards since the signature becomes invalid when tweaking the bytes
run: |
mkdir x86_64
mkdir arm64
mkdir -p dist
unzip fig2sketch-macos-x86_64.zip -d x86_64/
unzip fig2sketch-macos-arm64.zip -d arm64/
hexdump -ve '1/1 "%.2X"' x86_64/fig2sketch-${{ github.ref_name }} | sed "s/4D45490\([0C]\)0B0A0B0E/4D45490\10B0A0B0F/g" | xxd -r -p > x86_64/fig2sketch.patched
codesign --remove x86_64/fig2sketch.patched
codesign -s - x86_64/fig2sketch.patched
lipo -create x86_64/fig2sketch.patched arm64/fig2sketch-${{ github.ref_name }} -output dist/fig2sketch-${{ github.ref_name }}
- name: zip release
uses: thedoctor0/zip-release@main
with:
type: "zip"
filename: "fig2sketch-macos-universal.zip"
directory: "dist"
path: "*"
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: builds
path: dist/fig2sketch-macos-universal.zip
create-release:
needs: [build, build-macos-universal]
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: builds
- uses: ncipollo/release-action@v1
with:
artifacts: "fig2sketch-*.zip"
generateReleaseNotes: true
publish-to-pypi:
name: Build and publish to PyPi
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.11"
- name: Install build tools
run: pip install build
- name: Build source distribution
run: python -m build --sdist
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}