Skip to content

Commit 988eb3f

Browse files
committed
Add workflow to build executables from python scripts
1 parent f798eb3 commit 988eb3f

File tree

4 files changed

+163
-2
lines changed

4 files changed

+163
-2
lines changed

Diff for: .github/pytools/Sign-File.ps1

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
[CmdletBinding()]
2+
param (
3+
[Parameter()]
4+
[String]
5+
$Path
6+
)
7+
8+
9+
function FindSignTool {
10+
$SignTool = "signtool.exe"
11+
if (Get-Command $SignTool -ErrorAction SilentlyContinue) {
12+
return $SignTool
13+
}
14+
$SignTool = "${env:ProgramFiles(x86)}\Windows Kits\10\bin\x64\signtool.exe"
15+
if (Test-Path -Path $SignTool -PathType Leaf) {
16+
return $SignTool
17+
}
18+
$SignTool = "${env:ProgramFiles(x86)}\Windows Kits\10\bin\x86\signtool.exe"
19+
if (Test-Path -Path $SignTool -PathType Leaf) {
20+
return $SignTool
21+
}
22+
$sdkVers = "10.0.22000.0", "10.0.20348.0", "10.0.19041.0", "10.0.17763.0"
23+
Foreach ($ver in $sdkVers)
24+
{
25+
$SignTool = "${env:ProgramFiles(x86)}\Windows Kits\10\bin\${ver}\x64\signtool.exe"
26+
if (Test-Path -Path $SignTool -PathType Leaf) {
27+
return $SignTool
28+
}
29+
}
30+
"signtool.exe not found"
31+
Exit 1
32+
}
33+
34+
function SignEsptool {
35+
param(
36+
[Parameter()]
37+
[String]
38+
$Path
39+
)
40+
41+
$SignTool = FindSignTool
42+
"Using: $SignTool"
43+
$CertificateFile = [system.io.path]::GetTempPath() + "certificate.pfx"
44+
45+
if ($null -eq $env:CERTIFICATE) {
46+
"CERTIFICATE variable not set, unable to sign the file"
47+
Exit 1
48+
}
49+
50+
if ("" -eq $env:CERTIFICATE) {
51+
"CERTIFICATE variable is empty, unable to sign the file"
52+
Exit 1
53+
}
54+
55+
$SignParameters = @("sign", "/tr", 'http://timestamp.digicert.com', "/td", "SHA256", "/f", $CertificateFile, "/fd", "SHA256")
56+
if ($env:CERTIFICATE_PASSWORD) {
57+
"CERTIFICATE_PASSWORD detected, using the password"
58+
$SignParameters += "/p"
59+
$SignParameters += $env:CERTIFICATE_PASSWORD
60+
}
61+
$SignParameters += $Path
62+
63+
[byte[]]$CertificateBytes = [convert]::FromBase64String($env:CERTIFICATE)
64+
[IO.File]::WriteAllBytes($CertificateFile, $CertificateBytes)
65+
66+
&$SignTool $SignParameters
67+
68+
if (0 -eq $LASTEXITCODE) {
69+
Remove-Item $CertificateFile
70+
} else {
71+
Remove-Item $CertificateFile
72+
"Signing failed"
73+
Exit 1
74+
}
75+
76+
}
77+
78+
SignEsptool ${Path}

Diff for: .github/pytools/espressif.ico

115 KB
Binary file not shown.

Diff for: .github/workflows/build_py_tools.yml

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Build Python Tools
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'tools/get.py'
7+
8+
jobs:
9+
build-pytools-binaries:
10+
name: Build python tools binaries for ${{ matrix.os }}
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
os: [windows-latest, macos-latest, ubuntu-20.04, ARM, ARM64]
16+
include:
17+
- os: windows-latest
18+
TARGET: win64
19+
EXTEN: .exe
20+
SEPARATOR: ';'
21+
- os: macos-latest
22+
TARGET: macos
23+
SEPARATOR: ':'
24+
- os: ubuntu-20.04
25+
TARGET: linux-amd64
26+
SEPARATOR: ':'
27+
- os: ARM
28+
CONTAINER: python:3.8-bullseye
29+
TARGET: arm
30+
SEPARATOR: ':'
31+
- os: ARM64
32+
CONTAINER: python:3.8-bullseye
33+
TARGET: arm64
34+
SEPARATOR: ':'
35+
container: ${{ matrix.CONTAINER }} # use python container on ARM
36+
env:
37+
DISTPATH: pytools-${{ matrix.TARGET }}
38+
PIP_EXTRA_INDEX_URL: "https://dl.espressif.com/pypi"
39+
steps:
40+
- name: Checkout repository
41+
uses: actions/checkout@master
42+
- name: Set up Python 3.8
43+
# Skip setting python on ARM because of missing compatibility: https://github.com/actions/setup-python/issues/108
44+
if: matrix.os != 'ARM' && matrix.os != 'ARM64'
45+
uses: actions/setup-python@master
46+
with:
47+
python-version: 3.8
48+
- name: Install dependencies
49+
run: |
50+
python -m pip install --upgrade pip
51+
pip install pyinstaller requests
52+
- name: Build with PyInstaller
53+
run: |
54+
pyinstaller --distpath ./${{ env.DISTPATH }} -F --icon=.github/pytools/espressif.ico tools/get.py
55+
# - name: Sign binaries
56+
# if: matrix.os == 'windows-latest'
57+
# env:
58+
# CERTIFICATE: ${{ secrets.CERTIFICATE }}
59+
# CERTIFICATE_PASSWORD: ${{ secrets.CERTIFICATE_PASSWORD }}
60+
# shell: pwsh
61+
# run: |
62+
# ./.github/pytools/Sign-File.ps1 -Path ./${{ env.DISTPATH }}/get.exe
63+
- name: Test binaries
64+
shell: bash
65+
run: |
66+
./${{ env.DISTPATH }}/get${{ matrix.EXTEN }} -h
67+
- name: Archive artifact
68+
uses: actions/upload-artifact@master
69+
with:
70+
name: ${{ env.DISTPATH }}
71+
path: ${{ env.DISTPATH }}

Diff for: tools/get.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@
3535
if 'Windows' in platform.system():
3636
import requests
3737

38-
current_dir = os.path.dirname(os.path.realpath(unicode(__file__)))
38+
# determine if application is a script file or frozen exe
39+
if getattr(sys, 'frozen', False):
40+
current_dir = os.path.dirname(os.path.realpath(unicode(sys.executable)))
41+
elif __file__:
42+
current_dir = os.path.dirname(os.path.realpath(unicode(__file__)))
43+
44+
#current_dir = os.path.dirname(os.path.realpath(unicode(__file__)))
3945
dist_dir = current_dir + '/dist/'
4046

4147
def sha256sum(filename, blocksize=65536):
@@ -88,6 +94,8 @@ def unpack(filename, destination):
8894

8995
# a little trick to rename tool directories so they don't contain version number
9096
rename_to = re.match(r'^([a-z][^\-]*\-*)+', dirname).group(0).strip('-')
97+
if rename_to == dirname and dirname.startswith('esp32-arduino-libs-'):
98+
rename_to = 'esp32-arduino-libs'
9199
if rename_to != dirname:
92100
print('Renaming {0} to {1} ...'.format(dirname, rename_to))
93101
if os.path.isdir(rename_to):
@@ -220,7 +228,11 @@ def identify_platform():
220228
identified_platform = identify_platform()
221229
print('Platform: {0}'.format(identified_platform))
222230
tools_to_download = load_tools_list(current_dir + '/../package/package_esp32_index.template.json', identified_platform)
231+
is_test = (len(sys.argv) > 1 and sys.argv[1] == '-h')
223232
mkdir_p(dist_dir)
224233
for tool in tools_to_download:
225-
get_tool(tool)
234+
if is_test:
235+
print('Install: {0}'.format(tool['archiveFileName']))
236+
else:
237+
get_tool(tool)
226238
print('Platform Tools Installed')

0 commit comments

Comments
 (0)