From c9135e06e1bd25029fc06ec075fa29d10c7e0ec0 Mon Sep 17 00:00:00 2001 From: lumapu Date: Sun, 7 Jan 2024 20:30:52 +0100 Subject: [PATCH] github action test --- .github/workflows/compile_development.yml | 23 +-- scripts/getVersion.py | 187 +++++----------------- 2 files changed, 50 insertions(+), 160 deletions(-) diff --git a/.github/workflows/compile_development.yml b/.github/workflows/compile_development.yml index 197d1e37..d20c4627 100644 --- a/.github/workflows/compile_development.yml +++ b/.github/workflows/compile_development.yml @@ -65,6 +65,9 @@ jobs: - name: Run PlatformIO run: pio run -d src -e ${{ matrix.variant }} + - name: Rename Firmware + run: python ../scripts/getVersion.py ${{ matrix.variant }} >> $GITHUB_OUTPUT + - name: Create Artifact uses: actions/upload-artifact@v3 with: @@ -123,12 +126,15 @@ jobs: - name: Run PlatformIO run: pio run -d src -e ${{ matrix.variant }} + - name: Rename Firmware + run: python ../scripts/getVersion.py ${{ matrix.variant }} >> $GITHUB_OUTPUT + - name: Create Artifact uses: actions/upload-artifact@v3 with: name: ahoydtu_dev path: | - src/firmware/* + firmware/* deploy: needs: [build-en, build-de] @@ -141,19 +147,18 @@ jobs: uses: actions/download-artifact@master with: name: ahoydtu_dev - path: src/firmware/* + path: firmware/* - - name: Rename Binary files - id: rename-binary-files - working-directory: src - run: python ../scripts/getVersion.py >> $GITHUB_OUTPUT + - name: Get Version from code + id: version_name + run: python ../scripts/getVersion.py ${{ matrix.variant }} >> $GITHUB_OUTPUT - name: Set Version uses: cschleiden/replace-tokens@v1 with: files: tools/esp8266/User_Manual.md env: - VERSION: ${{ steps.rename-binary-files.outputs.name }} + VERSION: ${{ steps.version_name.outputs.name }} # - name: Create Manifest # working-directory: src @@ -169,12 +174,12 @@ jobs: # src/install.html - name: Rename firmware directory - run: mv src/firmware src/${{ steps.rename-binary-files.outputs.name }} + run: mv src/firmware src/${{ steps.version_name.outputs.name }} - name: Deploy uses: nogsantos/scp-deploy@master with: - src: src/${{ steps.rename-binary-files.outputs.name }}/ + src: src/${{ steps.version_name.outputs.name }}/ host: ${{ secrets.FW_SSH_HOST }} remote: ${{ secrets.FW_SSH_DIR }}/dev port: ${{ secrets.FW_SSH_PORT }} diff --git a/scripts/getVersion.py b/scripts/getVersion.py index ce34d26e..8d6d1cf8 100644 --- a/scripts/getVersion.py +++ b/scripts/getVersion.py @@ -2,6 +2,7 @@ import os import shutil import gzip from datetime import date +import sys def genOtaBin(path): arr = [] @@ -32,8 +33,8 @@ def gzip_bin(bin_file, gzip_file): with gzip.open(gzip_file, "wb", compresslevel = 9) as f: shutil.copyfileobj(fp, f) -def readVersion(path, infile): - f = open(path + infile, "r") +def getVersion(path_define): + f = open(path_define, "r") lines = f.readlines() f.close() @@ -48,160 +49,44 @@ def readVersion(path, infile): if(p != -1): version += line[p+13:].rstrip() + "." versionnumber += line[p+13:].rstrip() + "." - - os.mkdir(path + "firmware/") - os.mkdir(path + "firmware/ESP8266/") - os.mkdir(path + "firmware/ESP8285/") - os.mkdir(path + "firmware/ESP32/") - os.mkdir(path + "firmware/ESP32-S2/") - os.mkdir(path + "firmware/ESP32-S3/") - os.mkdir(path + "firmware/ESP32-C3/") - os.mkdir(path + "firmware/ESP32-S3-ETH/") - sha = os.getenv("SHA",default="sha") -## ENGLISH VERSIONS - versionout = version[:-1] + "_" + sha + "_esp8266.bin" - src = path + ".pio/build/esp8266/firmware.bin" - dst = path + "firmware/ESP8266/" + versionout - os.rename(src, dst) + return [version, versionnumber] - versionout = version[:-1] + "_" + sha + "_esp8266_prometheus.bin" - src = path + ".pio/build/esp8266-prometheus/firmware.bin" - dst = path + "firmware/ESP8266/" + versionout - os.rename(src, dst) +def renameFw(path_define, env): + version = getVersion(path_define)[0] - versionout = version[:-1] + "_" + sha + "_esp8285.bin" - src = path + ".pio/build/esp8285/firmware.bin" - dst = path + "firmware/ESP8285/" + versionout - os.rename(src, dst) - gzip_bin(dst, dst + ".gz") - - versionout = version[:-1] + "_" + sha + "_esp32.bin" - src = path + ".pio/build/esp32-wroom32/firmware.bin" - dst = path + "firmware/ESP32/" + versionout - os.rename(src, dst) - - versionout = version[:-1] + "_" + sha + "_esp32_prometheus.bin" - src = path + ".pio/build/esp32-wroom32-prometheus/firmware.bin" - dst = path + "firmware/ESP32/" + versionout - os.rename(src, dst) - - versionout = version[:-1] + "_" + sha + "_esp32_ethernet.bin" - src = path + ".pio/build/esp32-wroom32-ethernet/firmware.bin" - dst = path + "firmware/ESP32/" + versionout - os.rename(src, dst) - - versionout = version[:-1] + "_" + sha + "_esp32s2-mini.bin" - src = path + ".pio/build/esp32-s2-mini/firmware.bin" - dst = path + "firmware/ESP32-S2/" + versionout - os.rename(src, dst) - - versionout = version[:-1] + "_" + sha + "_esp32c3-mini.bin" - src = path + ".pio/build/esp32-c3-mini/firmware.bin" - dst = path + "firmware/ESP32-C3/" + versionout - os.rename(src, dst) - - versionout = version[:-1] + "_" + sha + "_esp32s3.bin" - src = path + ".pio/build/opendtufusion/firmware.bin" - dst = path + "firmware/ESP32-S3/" + versionout - os.rename(src, dst) - - versionout = version[:-1] + "_" + sha + "_esp32s3_ethernet.bin" - src = path + ".pio/build/opendtufusion-ethernet/firmware.bin" - dst = path + "firmware/ESP32-S3-ETH/" + versionout - os.rename(src, dst) - -## GERMAN VERSIONS - versionout = version[:-1] + "_" + sha + "_esp8266-de.bin" - src = path + ".pio/build/esp8266-de/firmware.bin" - dst = path + "firmware/ESP8266/" + versionout - os.rename(src, dst) - - versionout = version[:-1] + "_" + sha + "_esp8266_prometheus-de.bin" - src = path + ".pio/build/esp8266-prometheus-de/firmware.bin" - dst = path + "firmware/ESP8266/" + versionout - os.rename(src, dst) - - versionout = version[:-1] + "_" + sha + "_esp8285-de.bin" - src = path + ".pio/build/esp8285-de/firmware.bin" - dst = path + "firmware/ESP8285/" + versionout - os.rename(src, dst) - gzip_bin(dst, dst + ".gz") - - versionout = version[:-1] + "_" + sha + "_esp32-de.bin" - src = path + ".pio/build/esp32-wroom32-de/firmware.bin" - dst = path + "firmware/ESP32/" + versionout - os.rename(src, dst) - - versionout = version[:-1] + "_" + sha + "_esp32_prometheus-de.bin" - src = path + ".pio/build/esp32-wroom32-prometheus-de/firmware.bin" - dst = path + "firmware/ESP32/" + versionout - os.rename(src, dst) - - versionout = version[:-1] + "_" + sha + "_esp32_ethernet-de.bin" - src = path + ".pio/build/esp32-wroom32-ethernet-de/firmware.bin" - dst = path + "firmware/ESP32/" + versionout - os.rename(src, dst) - - versionout = version[:-1] + "_" + sha + "_esp32s2-mini-de.bin" - src = path + ".pio/build/esp32-s2-mini-de/firmware.bin" - dst = path + "firmware/ESP32-S2/" + versionout - os.rename(src, dst) - - versionout = version[:-1] + "_" + sha + "_esp32c3-mini-de.bin" - src = path + ".pio/build/esp32-c3-mini-de/firmware.bin" - dst = path + "firmware/ESP32-C3/" + versionout - os.rename(src, dst) - - versionout = version[:-1] + "_" + sha + "_esp32s3-de.bin" - src = path + ".pio/build/opendtufusion-de/firmware.bin" - dst = path + "firmware/ESP32-S3/" + versionout - os.rename(src, dst) - - versionout = version[:-1] + "_" + sha + "_esp32s3_ethernet-de.bin" - src = path + ".pio/build/opendtufusion-ethernet-de/firmware.bin" - dst = path + "firmware/ESP32-S3-ETH/" + versionout - os.rename(src, dst) - -## BOOTLOADER AND PARTITIONS - # other ESP32 bin files - src = path + ".pio/build/esp32-wroom32/" - dst = path + "firmware/ESP32/" - os.rename(src + "bootloader.bin", dst + "bootloader.bin") - os.rename(src + "partitions.bin", dst + "partitions.bin") - genOtaBin(dst) - - # other ESP32-S2 bin files - src = path + ".pio/build/esp32-s2-mini/" - dst = path + "firmware/ESP32-S2/" - os.rename(src + "bootloader.bin", dst + "bootloader.bin") - os.rename(src + "partitions.bin", dst + "partitions.bin") - genOtaBin(dst) + os.mkdir("firmware/") + fwDir = "" + if env[:7] == "esp8266": + fwDir = "ESP8266/" + elif env[:7] == "esp8285": + fwDir = "ESP8285/" + elif env[:7] == "esp32-w": + fwDir = "ESP32/" + elif env[:8] == "esp32-s2": + fwDir = "ESP32-S2/" + elif env[:4] == "open": + fwDir = "ESP32-S3/" + elif env[:8] == "esp32-c3": + fwDir = "ESP32-C3/" + os.mkdir("firmware/" + fwDir) + sha = os.getenv("SHA",default="sha") - # other ESP32-C3 bin files - src = path + ".pio/build/esp32-c3-mini/" - dst = path + "firmware/ESP32-C3/" - os.rename(src + "bootloader.bin", dst + "bootloader.bin") - os.rename(src + "partitions.bin", dst + "partitions.bin") - genOtaBin(dst) + dst = "firmware/" + fwDir + fname = version[:-1] + "_" + sha + "_" + env + ".bin" - # other ESP32-S3 bin files - src = path + ".pio/build/opendtufusion/" - dst = path + "firmware/ESP32-S3/" - os.rename(src + "bootloader.bin", dst + "bootloader.bin") - os.rename(src + "partitions.bin", dst + "partitions.bin") - genOtaBin(dst) + os.rename(".pio/build/" + env + "/firmware.bin", dst + fname) - # other ESP32-S3-Eth bin files - src = path + ".pio/build/opendtufusion-ethernet/" - dst = path + "firmware/ESP32-S3-ETH/" - os.rename(src + "bootloader.bin", dst + "bootloader.bin") - os.rename(src + "partitions.bin", dst + "partitions.bin") - genOtaBin(dst) + if env[:5] == "esp32": + os.rename(".pio/build/" + env + "/bootloader.bin", dst + "bootloader.bin") + os.rename(".pio/build/" + env + "/partitions.bin", dst + "partitions.bin") + genOtaBin(dst) - os.rename("../scripts/gh-action-dev-build-flash.html", path + "install.html") + if env[:7] == "esp8285": + gzip_bin(dst + fname, dst + fname[:-4] + ".gz") - print("name=" + versionnumber[:-1] ) - - -readVersion("", "defines.h") +if len(sys.argv) == 1: + print("name=" + getVersion("src/defines.h")[1][:-1]) +else: + # arg1: environment + renameFw("src/defines.h", sys.argv[1])