diff --git a/.github/workflows/update-binaries-esp32.yaml b/.github/workflows/update-binaries-esp32.yaml new file mode 100644 index 0000000..6600084 --- /dev/null +++ b/.github/workflows/update-binaries-esp32.yaml @@ -0,0 +1,50 @@ +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: 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 add ./manifests/* + git commit -m "Add ESPHome Firmware: ${{ github.event.inputs.esphome_release_tag }}" + git push + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/update-binaries-xmos.yaml b/.github/workflows/update-binaries-xmos.yaml new file mode 100644 index 0000000..3e67305 --- /dev/null +++ b/.github/workflows/update-binaries-xmos.yaml @@ -0,0 +1,44 @@ +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 + permissions: + contents: write + 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.GITHUB_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