Filaman/.github/workflows/providers/github-release.yml

124 lines
3.8 KiB
YAML

name: GitHub Release
on:
workflow_call:
jobs:
create-release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install PlatformIO
run: |
python -m pip install --upgrade pip
pip install --upgrade platformio esptool
- name: Install xxd
run: |
sudo apt-get update
sudo apt-get install xxd
- name: Check for SPIFFS changes
id: check_spiffs
run: |
git fetch --unshallow || true
CHANGED_FILES=$(git diff --name-only HEAD^..HEAD)
if echo "$CHANGED_FILES" | grep -q "^data/\|^html/"; then
echo "SPIFFS_CHANGED=true" >> $GITHUB_OUTPUT
else
echo "SPIFFS_CHANGED=false" >> $GITHUB_OUTPUT
fi
- name: Build Firmware
run: |
# Get version from platformio.ini
VERSION=$(grep '^version = ' platformio.ini | cut -d'"' -f2)
# Always build firmware
pio run -e esp32dev
cp .pio/build/esp32dev/firmware.bin .pio/build/esp32dev/filaman_${VERSION}.bin
# Only build SPIFFS if changed
if [[ "${{ steps.check_spiffs.outputs.SPIFFS_CHANGED }}" == "true" ]]; then
echo "Building SPIFFS due to changes..."
cp .pio/build/esp32dev/spiffs.bin .pio/build/esp32dev/webpage_${VERSION}.bin
fi
- name: Prepare binaries
run: |
cd .pio/build/esp32dev
VERSION=$(grep '^version = ' ../../platformio.ini | cut -d'"' -f2)
# Create full binary only if SPIFFS changed
if [[ "${{ steps.check_spiffs.outputs.SPIFFS_CHANGED }}" == "true" ]]; then
echo "Creating full binary..."
esptool.py --chip esp32 merge_bin \
--fill-flash-size 4MB \
--flash_mode dio \
--flash_freq 40m \
--flash_size 4MB \
-o filaman_full_${VERSION}.bin \
0x0000 bootloader.bin \
0x8000 partitions.bin \
0x10000 firmware.bin \
0x390000 spiffs.bin
fi
# Verify file sizes
echo "File sizes:"
ls -lh *.bin
- name: Get version from tag
id: get_version
run: |
echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Read CHANGELOG.md
id: changelog
run: |
VERSION=${{ steps.get_version.outputs.VERSION }}
CHANGELOG=$(awk "/## \\[$VERSION\\]/{p=1;print;next} /## \\[/{p=0} p" CHANGELOG.md)
echo "CHANGES<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
run: |
cd .pio/build/esp32dev
VERSION=$(grep '^version = ' ../../platformio.ini | cut -d'"' -f2)
FILES_TO_UPLOAD=""
# Always add firmware
if [ -f "filaman_${VERSION}.bin" ]; then
FILES_TO_UPLOAD="$FILES_TO_UPLOAD filaman_${VERSION}.bin"
fi
# Add SPIFFS and full binary only if they exist
if [ -f "webpage_${VERSION}.bin" ]; then
FILES_TO_UPLOAD="$FILES_TO_UPLOAD webpage_${VERSION}.bin"
fi
if [ -f "filaman_full_${VERSION}.bin" ]; then
FILES_TO_UPLOAD="$FILES_TO_UPLOAD filaman_full_${VERSION}.bin"
fi
# Create release with available files
if [ -n "$FILES_TO_UPLOAD" ]; then
gh release create "${{ github.ref_name }}" \
--title "Release ${{ steps.get_version.outputs.VERSION }}" \
--notes "${{ steps.changelog.outputs.CHANGES }}" \
$FILES_TO_UPLOAD
else
echo "Error: No files found to upload"
exit 1
fi