ci(tools): Fix tools workflows (#9846)

* ci(tools): Remove ARM64 runner and use get.exe

* ci(tools): Optimize get.py and verify extraction

* change(tools): Push generated binaries to PR

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Lucas Saavedra Vaz 2024-06-19 03:55:37 -03:00 committed by GitHub
parent 99750cd37e
commit 96c2c71cb3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 58 additions and 47 deletions

View file

@ -28,7 +28,11 @@ if [ ! -d "$ARDUINO_ESP32_PATH" ]; then
#git submodule update --init --recursive > /dev/null 2>&1 #git submodule update --init --recursive > /dev/null 2>&1
echo "Installing Platform Tools ..." echo "Installing Platform Tools ..."
if [ "$OS_IS_WINDOWS" == "1" ]; then
cd tools && ./get.exe
else
cd tools && python get.py cd tools && python get.py
fi
cd $script_init_path cd $script_init_path
echo "ESP32 Arduino has been installed in '$ARDUINO_ESP32_PATH'" echo "ESP32 Arduino has been installed in '$ARDUINO_ESP32_PATH'"

View file

@ -3,6 +3,7 @@ name: Build Python Tools
on: on:
pull_request: pull_request:
paths: paths:
- '.github/workflows/build_py_tools.yml'
- 'tools/get.py' - 'tools/get.py'
- 'tools/espota.py' - 'tools/espota.py'
- 'tools/gen_esp32part.py' - 'tools/gen_esp32part.py'
@ -21,6 +22,13 @@ jobs:
with: with:
fetch-depth: 2 fetch-depth: 2
ref: ${{ github.event.pull_request.head.ref }} ref: ${{ github.event.pull_request.head.ref }}
- name: Check if checkout failed
if: failure()
run: |
echo "Checkout failed."
echo "Make sure you are using a branch inside the repository and not a fork."
- name: Verify Python Tools Changed - name: Verify Python Tools Changed
uses: tj-actions/changed-files@v41 uses: tj-actions/changed-files@v41
id: verify-changed-files id: verify-changed-files
@ -47,7 +55,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [windows-latest, macos-latest, ubuntu-20.04, ARM, ARM64] os: [windows-latest, macos-latest, ubuntu-20.04, ARM]
include: include:
- os: windows-latest - os: windows-latest
TARGET: win64 TARGET: win64
@ -63,10 +71,6 @@ jobs:
CONTAINER: python:3.8-bullseye CONTAINER: python:3.8-bullseye
TARGET: arm TARGET: arm
SEPARATOR: ':' SEPARATOR: ':'
- os: ARM64
CONTAINER: python:3.8-bullseye
TARGET: arm64
SEPARATOR: ':'
container: ${{ matrix.CONTAINER }} # use python container on ARM container: ${{ matrix.CONTAINER }} # use python container on ARM
env: env:
DISTPATH: pytools-${{ matrix.TARGET }} DISTPATH: pytools-${{ matrix.TARGET }}
@ -93,7 +97,7 @@ jobs:
ref: ${{ github.event.pull_request.head.ref }} ref: ${{ github.event.pull_request.head.ref }}
- name: Set up Python 3.8 - name: Set up Python 3.8
# Skip setting python on ARM because of missing compatibility: https://github.com/actions/setup-python/issues/108 # Skip setting python on ARM because of missing compatibility: https://github.com/actions/setup-python/issues/108
if: matrix.os != 'ARM' && matrix.os != 'ARM64' if: matrix.os != 'ARM'
uses: actions/setup-python@master uses: actions/setup-python@master
with: with:
python-version: 3.8 python-version: 3.8
@ -108,7 +112,7 @@ jobs:
pyinstaller --distpath ./${{ env.DISTPATH }} -F --icon=.github/pytools/espressif.ico tools/$tool.py pyinstaller --distpath ./${{ env.DISTPATH }} -F --icon=.github/pytools/espressif.ico tools/$tool.py
done done
- name: Sign binaries - name: Sign binaries
if: matrix.os == 'windows-latest' && env.CERTIFICATE != '' && env.CERTIFICATE_PASSWORD != '' if: matrix.os == 'windows-latest'
env: env:
CERTIFICATE: ${{ secrets.CERTIFICATE }} CERTIFICATE: ${{ secrets.CERTIFICATE }}
CERTIFICATE_PASSWORD: ${{ secrets.CERTIFICATE_PASSWORD }} CERTIFICATE_PASSWORD: ${{ secrets.CERTIFICATE_PASSWORD }}

Binary file not shown.

View file

@ -101,52 +101,46 @@ def verify_files(filename, destination, rename_to):
t1 = time.time() t1 = time.time()
if filename.endswith(".zip"): if filename.endswith(".zip"):
try: try:
with zipfile.ZipFile(filename, "r") as archive: archive = zipfile.ZipFile(filename, "r")
first_dir = archive.namelist()[0].split("/")[0] file_list = archive.namelist()
total_files = len(archive.namelist())
for i, zipped_file in enumerate(archive.namelist(), 1):
local_path = os.path.join(extracted_dir_path, zipped_file.replace(first_dir, rename_to, 1))
if not os.path.exists(local_path):
print(f"\nMissing {zipped_file} on location: {extracted_dir_path}")
print(f"Verification failed; aborted in {format_time(time.time() - t1)}")
return False
print_verification_progress(total_files, i, t1)
except zipfile.BadZipFile: except zipfile.BadZipFile:
if verbose:
print(f"Verification failed; aborted in {format_time(time.time() - t1)}") print(f"Verification failed; aborted in {format_time(time.time() - t1)}")
return False return False
elif filename.endswith(".tar.gz"): elif filename.endswith(".tar.gz"):
try: try:
with tarfile.open(filename, "r:gz") as archive: archive = tarfile.open(filename, "r:gz")
first_dir = archive.getnames()[0].split("/")[0] file_list = archive.getnames()
total_files = len(archive.getnames())
for i, zipped_file in enumerate(archive.getnames(), 1):
local_path = os.path.join(extracted_dir_path, zipped_file.replace(first_dir, rename_to, 1))
if not os.path.exists(local_path):
print(f"\nMissing {zipped_file} on location: {extracted_dir_path}")
print(f"Verification failed; aborted in {format_time(time.time() - t1)}")
return False
print_verification_progress(total_files, i, t1)
except tarfile.ReadError: except tarfile.ReadError:
if verbose:
print(f"Verification failed; aborted in {format_time(time.time() - t1)}") print(f"Verification failed; aborted in {format_time(time.time() - t1)}")
return False return False
elif filename.endswith(".tar.xz"): elif filename.endswith(".tar.xz"):
try: try:
with tarfile.open(filename, "r:xz") as archive: archive = tarfile.open(filename, "r:xz")
first_dir = archive.getnames()[0].split("/")[0] file_list = archive.getnames()
total_files = len(archive.getnames())
for i, zipped_file in enumerate(archive.getnames(), 1):
local_path = os.path.join(extracted_dir_path, zipped_file.replace(first_dir, rename_to, 1))
if not os.path.exists(local_path):
print(f"\nMissing {zipped_file} on location: {extracted_dir_path}")
print(f"Verification failed; aborted in {format_time(time.time() - t1)}")
return False
print_verification_progress(total_files, i, t1)
except tarfile.ReadError: except tarfile.ReadError:
if verbose:
print(f"Verification failed; aborted in {format_time(time.time() - t1)}") print(f"Verification failed; aborted in {format_time(time.time() - t1)}")
return False return False
else: else:
raise NotImplementedError("Unsupported archive type") raise NotImplementedError("Unsupported archive type")
try:
first_dir = file_list[0].split("/")[0]
total_files = len(file_list)
for i, zipped_file in enumerate(file_list, 1):
local_path = os.path.join(extracted_dir_path, zipped_file.replace(first_dir, rename_to, 1))
if not os.path.exists(local_path):
if verbose:
print(f"\nMissing {zipped_file} on location: {extracted_dir_path}")
print(f"Verification failed; aborted in {format_time(time.time() - t1)}")
return False
print_verification_progress(total_files, i, t1)
except Exception as e:
print(f"\nError: {e}")
return False
if verbose: if verbose:
print(f"\nVerification passed; completed in {format_time(time.time() - t1)}") print(f"\nVerification passed; completed in {format_time(time.time() - t1)}")
@ -231,7 +225,12 @@ def unpack(filename, destination, force_extract): # noqa: C901
shutil.rmtree(rename_to) shutil.rmtree(rename_to)
shutil.move(dirname, rename_to) shutil.move(dirname, rename_to)
if verify_files(filename, destination, rename_to):
print(" Files extracted successfully.")
return True return True
else:
print(" Failed to extract files.")
return False
def download_file_with_progress(url, filename, start_time): def download_file_with_progress(url, filename, start_time):
@ -291,6 +290,7 @@ def get_tool(tool, force_download, force_extract):
local_path = dist_dir + archive_name local_path = dist_dir + archive_name
url = tool["url"] url = tool["url"]
start_time = time.time() start_time = time.time()
print("")
if not os.path.isfile(local_path) or force_download: if not os.path.isfile(local_path) or force_download:
if verbose: if verbose:
print("Downloading '" + archive_name + "' to '" + local_path + "'") print("Downloading '" + archive_name + "' to '" + local_path + "'")
@ -421,6 +421,9 @@ if __name__ == "__main__":
current_dir + "/../package/package_esp32_index.template.json", identified_platform current_dir + "/../package/package_esp32_index.template.json", identified_platform
) )
mkdir_p(dist_dir) mkdir_p(dist_dir)
print("\nDownloading and extracting tools...")
for tool in tools_to_download: for tool in tools_to_download:
if is_test: if is_test:
print("Would install: {0}".format(tool["archiveFileName"])) print("Would install: {0}".format(tool["archiveFileName"]))
@ -432,4 +435,4 @@ if __name__ == "__main__":
print(f"Tool {tool['archiveFileName']} was corrupted, but re-downloading did not help!\n") print(f"Tool {tool['archiveFileName']} was corrupted, but re-downloading did not help!\n")
sys.exit(1) sys.exit(1)
print("Platform Tools Installed") print("\nPlatform Tools Installed")