From 774a55418486aa97b01239eae70866bbc97c0929 Mon Sep 17 00:00:00 2001 From: Kunal Bansal Date: Sun, 15 Sep 2024 15:40:24 -0500 Subject: [PATCH 1/4] add acction and script to dynamically create manifests for each version --- .github/workflows/update-binaries.yaml | 58 +++++++++++++++++++ create_manifest.sh | 77 ++++++++++++++++++++++++++ 2 files changed, 135 insertions(+) create mode 100644 .github/workflows/update-binaries.yaml create mode 100755 create_manifest.sh diff --git a/.github/workflows/update-binaries.yaml b/.github/workflows/update-binaries.yaml new file mode 100644 index 0000000..254febd --- /dev/null +++ b/.github/workflows/update-binaries.yaml @@ -0,0 +1,58 @@ +name: Download and Commit Release from XMOS and ESPHome Repos + +on: + workflow_dispatch: # Allows manual trigger of the workflow + inputs: + xmos_release_tag: + description: 'Tag of the XMOS release firmware to download' + required: true + esphome_release_tag: + description: 'Tag of the ESPHome release firmware to download' + required: true +env: + esphome_repo: FutureProofHomes/Satellite1-ESPHome + xmos_repo: FutureProofHomes/Satellite1-XMOS +jobs: + download-release: + runs-on: ubuntu-latest + + steps: + - name: Checkout current repository + uses: actions/checkout@v4 + + - name: Authenticate with GitHub CLI + run: | + echo "${{ secrets.PAT_TOKEN }}" | gh auth login --with-token + + - name: Download ESPHome release asset + run: | + mkdir -p ./assets/firmware/esphome/${{ github.event.inputs.esphome_release_tag }} + gh release download ${{ github.event.inputs.esphome_release_tag }} \ + --repo ${{ env.esphome_repo }} \ + --dir ./assets/firmware/esphome/${{ github.event.inputs.esphome_release_tag }} + env: + GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} + + - name: Download XMOS release asset + run: | + mkdir -p ./assets/firmware/xmos/${{ github.event.inputs.xmos_release_tag }} + gh release download ${{ github.event.inputs.xmos_release_tag }} \ + --repo ${{ env.xmos_repo }} \ + --dir ./assets/firmware/xmos/${{ github.event.inputs.xmos_release_tag }} + env: + GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} + + - name: Create manifest files for each hardware revision + run: | + chmod +x ./create_manifest.sh + ./create_manifest.sh ${{ github.event.inputs.esphome_release_tag }} ${{ env.esphome_repo }} + + - name: Add and commit release assets to the current repository + run: | + git config --global user.name 'GitHub Actions Bot' + git config --global user.email 'actions@github.com' + git add ./assets/* + git commit -m "Add XMOS (Tag: ${{ github.event.inputs.xmos_release_tag }}) and ESPHome (Tag: ${{ github.event.inputs.esphome_release_tag }}) firmware" + git push + env: + GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} diff --git a/create_manifest.sh b/create_manifest.sh new file mode 100755 index 0000000..224999a --- /dev/null +++ b/create_manifest.sh @@ -0,0 +1,77 @@ +#!/bin/bash + +# Exit immediately if any command exits with a non-zero status +set -e + +# Function to print an error message and exit +error_exit() { + echo "$1" 1>&2 + exit 1 +} + +# Check if at least two parameters are passed +if [ $# -lt 2 ]; then + error_exit "Usage: $0 " +fi + +# Assign input parameters to variables +release_tag="$1" +esphome_firmware_repository="$2" + +# Check if the firmware directory exists +FIRMWARE_DIR="./assets/firmware/esphome/$release_tag" +if [ ! -d "$FIRMWARE_DIR" ]; then + error_exit "Firmware directory '$FIRMWARE_DIR' does not exist." +fi + +# Create the manifest directory if it doesn't exist +mkdir -p ./manifests/$release_tag + +# Find all .bin and .ota.bin files and process them in pairs +for OTA_FILE in $(ls $FIRMWARE_DIR/*.ota.bin 2>/dev/null); do + # Derive the base name by stripping the .ota.bin extension + BASE_NAME=$(basename "$OTA_FILE" .ota.bin) + + # Find the corresponding full .bin file + BIN_FILE="$FIRMWARE_DIR/${BASE_NAME}.bin" + + # Check if both files exist + if [ -f "$OTA_FILE" ] && [ -f "$BIN_FILE" ]; then + # Create a manifest file for this hardware revision + MANIFEST_FILE="./manifests/${release_tag}/${BASE_NAME}.manifest.json" + + cat < "$MANIFEST_FILE" +{ + "name": "ESPHome Firmware for $BASE_NAME", + "version": "$release_tag", + "new_install_prompt_erase": true, + "builds": [ + { + "chipFamily": "esp32", + "ota": { + "path": "$(basename $OTA_FILE)", + "md5": "$(md5sum $OTA_FILE | cut -d' ' -f1)", + "summary": "ESPHome Firmware for $BASE_NAME", + "release_url": "https://github.com/$esphome_firmware_repository/releases/tag/$release_tag/" + }, + "parts": [ + { + "path": "$(basename $BIN_FILE)", + "offset": 0 + } + ] + } + ] +} +EOF + + echo "Created manifest for hardware revision: $BASE_NAME" + else + echo "Warning: Matching .bin file not found for OTA file $OTA_FILE." + fi +done + +# Check if no OTA files were found +if [ -z "$(ls $FIRMWARE_DIR/*.ota.bin 2>/dev/null)" ]; then + echo "No .ota.bin files found in the directory '$FIRMWARE_DIR'." +fi From 0bc4b87121324df575ab2665a4f36b9d9894f4a0 Mon Sep 17 00:00:00 2001 From: Kunal Bansal Date: Sun, 15 Sep 2024 15:42:23 -0500 Subject: [PATCH 2/4] add manifests to the git commit --- .github/workflows/update-binaries.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/update-binaries.yaml b/.github/workflows/update-binaries.yaml index 254febd..d55225d 100644 --- a/.github/workflows/update-binaries.yaml +++ b/.github/workflows/update-binaries.yaml @@ -52,6 +52,7 @@ jobs: git config --global user.name 'GitHub Actions Bot' git config --global user.email 'actions@github.com' git add ./assets/* + git add ./manifests/* git commit -m "Add XMOS (Tag: ${{ github.event.inputs.xmos_release_tag }}) and ESPHome (Tag: ${{ github.event.inputs.esphome_release_tag }}) firmware" git push env: From 68f88a6ec949b92ea01e6f3b4cdfab718d281168 Mon Sep 17 00:00:00 2001 From: Kunal Bansal Date: Mon, 16 Sep 2024 13:57:40 -0500 Subject: [PATCH 3/4] split update binaries to separate workflows --- ...naries.yaml => update-binaries-esp32.yaml} | 11 +---- .github/workflows/update-binaries-xmos.yaml | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+), 10 deletions(-) rename .github/workflows/{update-binaries.yaml => update-binaries-esp32.yaml} (75%) create mode 100644 .github/workflows/update-binaries-xmos.yaml diff --git a/.github/workflows/update-binaries.yaml b/.github/workflows/update-binaries-esp32.yaml similarity index 75% rename from .github/workflows/update-binaries.yaml rename to .github/workflows/update-binaries-esp32.yaml index d55225d..fb3fe4b 100644 --- a/.github/workflows/update-binaries.yaml +++ b/.github/workflows/update-binaries-esp32.yaml @@ -33,15 +33,6 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} - - name: Download XMOS release asset - run: | - mkdir -p ./assets/firmware/xmos/${{ github.event.inputs.xmos_release_tag }} - gh release download ${{ github.event.inputs.xmos_release_tag }} \ - --repo ${{ env.xmos_repo }} \ - --dir ./assets/firmware/xmos/${{ github.event.inputs.xmos_release_tag }} - env: - GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} - - name: Create manifest files for each hardware revision run: | chmod +x ./create_manifest.sh @@ -53,7 +44,7 @@ jobs: git config --global user.email 'actions@github.com' git add ./assets/* git add ./manifests/* - git commit -m "Add XMOS (Tag: ${{ github.event.inputs.xmos_release_tag }}) and ESPHome (Tag: ${{ github.event.inputs.esphome_release_tag }}) firmware" + git commit -m "Add ESPHome Firmware: ${{ github.event.inputs.esphome_release_tag }}" git push env: GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} diff --git a/.github/workflows/update-binaries-xmos.yaml b/.github/workflows/update-binaries-xmos.yaml new file mode 100644 index 0000000..45d18a1 --- /dev/null +++ b/.github/workflows/update-binaries-xmos.yaml @@ -0,0 +1,42 @@ +name: Download and Commit Release from XMOS and ESPHome Repos + +on: + workflow_dispatch: # Allows manual trigger of the workflow + inputs: + xmos_release_tag: + description: 'Tag of the XMOS release firmware to download' + required: true +env: + esphome_repo: FutureProofHomes/Satellite1-ESPHome + xmos_repo: FutureProofHomes/Satellite1-XMOS +jobs: + download-release: + runs-on: ubuntu-latest + + steps: + - name: Checkout current repository + uses: actions/checkout@v4 + + - name: Authenticate with GitHub CLI + run: | + echo "${{ secrets.PAT_TOKEN }}" | gh auth login --with-token + + - name: Download XMOS release asset + run: | + mkdir -p ./assets/firmware/xmos/${{ github.event.inputs.xmos_release_tag }} + gh release download ${{ github.event.inputs.xmos_release_tag }} \ + --repo ${{ env.xmos_repo }} \ + --dir ./assets/firmware/xmos/${{ github.event.inputs.xmos_release_tag }} + env: + GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} + + - name: Add and commit release assets to the current repository + run: | + git config --global user.name 'GitHub Actions Bot' + git config --global user.email 'actions@github.com' + git add ./assets/* + git add ./manifests/* + git commit -m "Add XMOS Firmware: ${{ github.event.inputs.xmos_release_tag }}" + git push + env: + GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} From 0a23a1f25d8a150a7b49541d1ea03b02f596e4a7 Mon Sep 17 00:00:00 2001 From: Kunal Bansal Date: Thu, 19 Sep 2024 14:16:18 -0500 Subject: [PATCH 4/4] update workflow to use github token for the self commit --- .github/workflows/update-binaries-esp32.yaml | 2 +- .github/workflows/update-binaries-xmos.yaml | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/update-binaries-esp32.yaml b/.github/workflows/update-binaries-esp32.yaml index fb3fe4b..6600084 100644 --- a/.github/workflows/update-binaries-esp32.yaml +++ b/.github/workflows/update-binaries-esp32.yaml @@ -47,4 +47,4 @@ jobs: git commit -m "Add ESPHome Firmware: ${{ github.event.inputs.esphome_release_tag }}" git push env: - GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/update-binaries-xmos.yaml b/.github/workflows/update-binaries-xmos.yaml index 45d18a1..3e67305 100644 --- a/.github/workflows/update-binaries-xmos.yaml +++ b/.github/workflows/update-binaries-xmos.yaml @@ -12,7 +12,8 @@ env: jobs: download-release: runs-on: ubuntu-latest - + permissions: + contents: write steps: - name: Checkout current repository uses: actions/checkout@v4 @@ -39,4 +40,5 @@ jobs: git commit -m "Add XMOS Firmware: ${{ github.event.inputs.xmos_release_tag }}" git push env: - GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +