Skip to content

Update Central Firmware Repository #3

Update Central Firmware Repository

Update Central Firmware Repository #3

name: Update Central Firmware Repository
on:
release:
types: [published]
jobs:
update-central-repo:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Set up Git
run: |
git config --global user.name 'GitHub Actions'
git config --global user.email '[email protected]'
- name: Clone Central Repository
run: |
git clone https://$GITHUB_ACTOR:${{ secrets.CENTRAL_REPO_TOKEN }}@github.com/all-solutions/Flash2MQTT.git central_repo
- name: Copy Firmware Files
run: |
mkdir -p central_repo/firmware/${{ github.event.repository.name }}
cp *.bin central_repo/firmware/${{ github.event.repository.name }}/
- name: Update variants.json
run: |
cd central_repo/firmware/${{ github.event.repository.name }}
ls *.bin > bin_files.txt
echo '[' > variants.json
count=0
total=$(wc -l < bin_files.txt)
while read file; do
if [[ "$file" != *"OTA"* ]]; then
variant_name=$(echo $file | sed -e 's/.*_\([^_]*\)\.bin/\1/')
display_name=$(echo $variant_name | tr '_' ' ' | sed -e 's/\b\(.\)/\u\1/g')
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))
if [ $count -lt $total ]; then
echo ',' >> variants.json
else
echo '' >> variants.json
fi
fi
done < bin_files.txt
echo ']' >> variants.json
rm bin_files.txt
- name: Commit and Push Changes
run: |
cd central_repo
git add firmware/${{ github.event.repository.name }}
git commit -m "Update firmware for ${{ github.event.repository.name }} to version ${{ github.event.release.tag_name }}"
git push origin HEAD:master
- name: Update firmware_list.json
run: |
cd central_repo/firmware
# Update the version in firmware_list.json
tmpfile=$(mktemp)
jq --arg name "${{ github.event.repository.name }}" --arg version "${{ github.event.release.tag_name }}" \
'(.[] | select(.name == $name) | .version) = $version' firmware_list.json > "$tmpfile" && mv "$tmpfile" firmware_list.json
git add firmware_list.json
git commit -m "Update firmware_list.json with new version of ${{ github.event.repository.name }}"
git push