diff --git a/.github/workflows/update_Flash2MQTT.yml b/.github/workflows/update_Flash2MQTT.yml index 49cf789..4a77509 100644 --- a/.github/workflows/update_Flash2MQTT.yml +++ b/.github/workflows/update_Flash2MQTT.yml @@ -73,24 +73,46 @@ jobs: - name: Update variants.json and firmware_list.json run: | cd Flash2MQTT/firmware/${{ github.event.repository.name }} + firmware_name="${{ github.event.repository.name }}" ls *.bin > bin_files.txt - echo '[' > variants.json + # Initialize variables + total=0 count=0 - total=$(grep -vc '^$' bin_files.txt) + # Determine total number of desired variants + while read file; do + if [[ "$file" != *"OTA"* ]]; then + variant_name=$(echo "$file" | sed -E 's/^'"$firmware_name"'_//; s/(_[^_]*)?\.bin$//') + if [[ "$variant_name" == "d1_mini" || "$variant_name" == "esp01" ]]; then + total=$((total + 1)) + fi + fi + done < bin_files.txt + # Start building variants.json + echo '[' > variants.json + # Process files and create variants.json while read file; do if [[ "$file" != *"OTA"* ]]; then - # Variant Name korrekt extrahieren - variant_name=$(echo $file | sed -E 's/^[^_]+_(.*)_[^_]+\.bin$/\1/') - display_name=$(echo $variant_name | tr '_' ' ' | sed -e 's/\b\(.\)/\u\1/g') + variant_name=$(echo "$file" | sed -E 's/^'"$firmware_name"'_//; s/(_[^_]*)?\.bin$//') + case "$variant_name" in + "d1_mini") + display_name="D1 Mini" + ;; + "esp01") + display_name="ESP-01" + ;; + *) + # Skip unwanted variants + continue + ;; + esac + count=$((count + 1)) echo ' {' >> variants.json echo ' "displayName": "'"$display_name"'",' >> variants.json - echo ' "file": "https://all-solutions.github.io/Flash2MQTT/firmware/'"${{ github.event.repository.name }}"'/'"$file"'"' >> variants.json - echo -n ' }' >> variants.json - count=$((count + 1)) + echo ' "file": "https://all-solutions.github.io/Flash2MQTT/firmware/'"$firmware_name"'/'"$file"'"' >> variants.json if [ $count -lt $total ]; then - echo ',' >> variants.json + echo ' },' >> variants.json else - echo '' >> variants.json + echo ' }' >> variants.json fi fi done < bin_files.txt @@ -99,6 +121,10 @@ jobs: # Update firmware_list.json cd .. + # Install jq if not already installed + if ! command -v jq &> /dev/null; then + sudo apt-get update && sudo apt-get install -y jq + fi # Initialize firmware_list.json if it doesn't exist if [ ! -f firmware_list.json ]; then echo '[]' > firmware_list.json @@ -126,5 +152,3 @@ jobs: git commit -m "Update firmware for ${{ github.event.repository.name }} to version $version" git pull --rebase origin main git push https://all-solutions:${{ secrets.CENTRAL_REPO_TOKEN }}@github.com/all-solutions/Flash2MQTT.git HEAD:main - -