Skip to content

Commit 7cf577e

Browse files
authored
using Nuitka for binary (NewFuture#456)
* nuitka package binary * update pipeline * update test * fix lint * update build * fix path * imageio * 兼容powershell * update build * update build * lowercase * fix build * fix versiob build * fix build
1 parent 430380c commit 7cf577e

7 files changed

Lines changed: 81 additions & 13 deletions

File tree

.build/icon-black.png

15.7 KB
Loading

.build/icon.png

19.7 KB
Loading

.build/nuitka.cmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nuitka --standalone --onefile --output-dir=./dist --output-filename=ddns --remove-output --include-module=dns.dnspod --include-module=dns.alidns --include-module=dns.dnspod_com --include-module=dns.dnscom --include-module=dns.cloudflare --include-module=dns.he --include-module=dns.huaweidns --include-module=dns.callback --macos-app-name="DDNS" --product-name=DDNS --file-description="DDNS Client 自动更新域名解析到本机IP" --company-name="New Future" --copyright="https://ddns.newfuture.cc" --windows-icon-from-ico="favicon.ico" --linux-icon=".build/icon.png" --macos-app-icon=".build/icon.png" --assume-yes-for-downloads run.py

.github/workflows/build.yml

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,55 @@ jobs:
9292
# Upload build result
9393
- uses: actions/upload-artifact@v4
9494
with:
95-
name: ${{ matrix.os }}-py${{ matrix.python-version }}
95+
name: PyInstaller-${{ matrix.os }}-py${{ matrix.python-version }}
96+
path: dist/
97+
retention-days: 7
98+
99+
nuitka:
100+
strategy:
101+
# fail-fast: false
102+
matrix:
103+
os: [windows-latest, windows-11-arm, ubuntu-latest, ubuntu-24.04-arm, macos-13, macos-latest]
104+
runs-on: ${{ matrix.os }}
105+
timeout-minutes: 10
106+
steps:
107+
- uses: actions/checkout@v4
108+
- name: Set up Python 3.x
109+
uses: actions/setup-python@v5
110+
with:
111+
python-version: 3.x
112+
- name: Install dependencies
113+
run: pip install nuitka
114+
115+
# Prepare build version and cert
116+
- name: Replace build version
117+
run: sed -i.tmp -e "s#\${BUILD_VERSION}#${{ github.ref_name }}#" -e "s/\${BUILD_DATE}/$(date --iso-8601=seconds)/" run.py && rm run.py.tmp
118+
shell: bash
119+
120+
- name: setup on Linux
121+
if: runner.os == 'Linux'
122+
run: |
123+
sudo apt-get update && sudo apt install -y patchelf ccache
124+
cp /etc/ssl/certs/ca-certificates.crt cert.pem && export SSL_CERT_FILE=${PWD}/cert.pem
125+
126+
- name: setup on macOS
127+
if: runner.os == 'macOS'
128+
run: |
129+
python3 -m pip install imageio
130+
131+
132+
- run: python ./run.py -h
133+
134+
- name: Package binary
135+
run: ./.build/nuitka.cmd
136+
137+
- run: ./dist/ddns || test -e config.json
138+
- run: ./dist/ddns -h
139+
140+
# Upload build result
141+
- uses: actions/upload-artifact@v4
142+
with:
143+
name: ddns-${{ runner.os }}-${{ runner.arch }}
96144
path: dist/
97145
retention-days: 7
98146

.github/workflows/publish.yml

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,31 +77,44 @@ jobs:
7777

7878
build-binary:
7979
strategy:
80+
# fail-fast: false
8081
matrix:
81-
os: [macos, ubuntu, windows]
82-
runs-on: ${{ matrix.os }}-latest
83-
timeout-minutes: 8
82+
os: [windows-latest, windows-11-arm, ubuntu-latest, ubuntu-24.04-arm, macos-13, macos-latest]
83+
runs-on: ${{ matrix.os }}
84+
timeout-minutes: 10
8485
steps:
8586
- uses: actions/checkout@v4
8687
- uses: actions/setup-python@v5
8788
with:
8889
python-version: "3.x"
8990
- name: Install dependencies
90-
run: pip install pyinstaller
91+
run: pip install nuitka
9192

9293
- name: Replace build version
9394
run: sed -i.tmp -e "s#\${BUILD_VERSION}#${{ github.ref_name }}#" -e "s/\${BUILD_DATE}/$(date --iso-8601=seconds)/" run.py && rm run.py.tmp
9495
shell: bash
95-
- name: Copy cert on ubuntu
96+
97+
- name: setup on Linux
9698
if: runner.os == 'Linux'
97-
run: cp /etc/ssl/certs/ca-certificates.crt cert.pem && export SSL_CERT_FILE=${PWD}/cert.pem
99+
run: |
100+
apt-get update && apt install -y patchelf ccache
101+
cp /etc/ssl/certs/ca-certificates.crt cert.pem && export SSL_CERT_FILE=${PWD}/cert.pem
102+
103+
- name: setup on macOS
104+
if: runner.os == 'macOS'
105+
run: |
106+
python3 -m pip install imageio
107+
108+
- name: Package binary
109+
run: ./.build/nuitka.cmd
98110

99-
- run: python -O -m PyInstaller --noconfirm --clean .build/ddns.spec
100111
- run: ./dist/ddns || test -e config.json
101112
- run: ./dist/ddns -h
102113

103-
- run: mv ./dist/ddns ./dist/ddns-osx
104-
if: runner.os == 'macOS'
114+
- name: Move and rename binary with lowercase OS and arch
115+
run: mv ./dist/ddns "./dist/ddns-$(echo ${{ runner.os }}-${{ runner.arch }} | tr '[:upper:]' '[:lower:]')"
116+
shell: bash
117+
105118
- uses: actions/upload-artifact@v4
106119
with:
107120
name: ${{ runner.os }}

favicon.ico

16.6 KB
Binary file not shown.

run.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
@author: New Future
66
@modified: rufengsuixing
77
"""
8+
# nuitka-project-if: {OS} == "Linux":
9+
# nuitka-project: --static-libpython=yes
10+
# nuitka-project-if: os.getenv("BUILD_VERSION") is not None:
11+
# nuitka-project: --product-version=${BUILD_VERSION}
12+
# nuitka-project-else:
13+
# nuitka-project: --product-version=0.0.0
14+
815
from __future__ import print_function
916
from time import ctime, asctime
1017
from os import path, environ, name as os_name
@@ -46,7 +53,7 @@ def get_ip(ip_type, index="default"):
4653
debug(f"get_ip({ip_type}, {index})")
4754
if index is False: # disabled
4855
return False
49-
elif type(index) is list: # 如果获取到的规则是列表,则依次判断列表中每一个规则,直到找到一个可以正确获取到的IP
56+
elif isinstance(index, list): # 如果获取到的规则是列表,则依次判断列表中每一个规则,直到找到一个可以正确获取到的IP
5057
for i in index:
5158
value = get_ip(ip_type, i)
5259
if value:
@@ -66,8 +73,7 @@ def get_ip(ip_type, index="default"):
6673
value = getattr(ip, index + "_v" + ip_type)()
6774
except Exception as e:
6875
error(e)
69-
finally:
70-
return value
76+
return value
7177

7278

7379
def change_dns_record(dns, proxy_list, **kw):

0 commit comments

Comments
 (0)