Skip to content

Commit

Permalink
Update update_Flash2MQTT.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
all-solutions authored Oct 14, 2024
1 parent 80c0d91 commit a5a7abb
Showing 1 changed file with 36 additions and 12 deletions.
48 changes: 36 additions & 12 deletions .github/workflows/update_Flash2MQTT.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

0 comments on commit a5a7abb

Please sign in to comment.