Skip to content

Commit

Permalink
Merge pull request #6 from FutureProofHomes/feature/32-release-action
Browse files Browse the repository at this point in the history
add acction and script to dynamically create manifests for each version
  • Loading branch information
qnlbnsl authored Sep 19, 2024
2 parents fa9f141 + 0a23a1f commit d7aecc2
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 0 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/update-binaries-esp32.yaml
Original file line number Diff line number Diff line change
@@ -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 '[email protected]'
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 }}
44 changes: 44 additions & 0 deletions .github/workflows/update-binaries-xmos.yaml
Original file line number Diff line number Diff line change
@@ -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 '[email protected]'
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 }}

77 changes: 77 additions & 0 deletions create_manifest.sh
Original file line number Diff line number Diff line change
@@ -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 <release_tag> <esphome_firmware_repository>"
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 <<EOF > "$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

0 comments on commit d7aecc2

Please sign in to comment.