name: GitHub Release on: workflow_call: secrets: RELEASE_TOKEN: description: 'GitHub token for release creation' required: true permissions: contents: write 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 Data changes id: check_data run: | git fetch --unshallow || true CHANGED_FILES=$(git diff --name-only HEAD^..HEAD) if echo "$CHANGED_FILES" | grep -q "^data/"; then echo "DATA_CHANGED=true" >> $GITHUB_OUTPUT else echo "DATA_CHANGED=false" >> $GITHUB_OUTPUT fi - 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: | VERSION=$(grep '^version = ' platformio.ini | cut -d'"' -f2) # Always build firmware and SPIFFS echo "Building firmware and SPIFFS..." pio run -e esp32dev pio run -t buildfs # Copy firmware binary cp .pio/build/esp32dev/firmware.bin .pio/build/esp32dev/filaman_${VERSION}.bin # Always create SPIFFS binary cp .pio/build/esp32dev/spiffs.bin .pio/build/esp32dev/webpage_${VERSION}.bin # Create full binary (always) (cd .pio/build/esp32dev && esptool.py --chip esp32 merge_bin \ --fill-flash-size 4MB \ --flash_mode dio \ --flash_freq 40m \ --flash_size 4MB \ -o filaman_full_${VERSION}.bin \ 0x1000 bootloader.bin \ 0x8000 partitions.bin \ 0x10000 firmware.bin \ 0x390000 spiffs.bin) # Verify file sizes echo "File sizes:" (cd .pio/build/esp32dev && ls -lh *.bin) - name: Get version from platformio.ini id: get_version run: | VERSION=$(grep '^version = ' platformio.ini | cut -d'"' -f2) echo "VERSION=$VERSION" >> $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<> $GITHUB_OUTPUT echo "$CHANGELOG" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT - name: Create GitHub Release env: GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} run: | VERSION=${{ steps.get_version.outputs.VERSION }} cd .pio/build/esp32dev # Create the release first RELEASE_JSON=$(curl -L \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer $GITHUB_TOKEN" \ -H "X-GitHub-Api-Version: 2022-11-28" \ "https://api.github.com/repos/$GITHUB_REPOSITORY/releases" \ -d "{ \"tag_name\":\"v${VERSION}\", \"name\":\"Release ${VERSION}\", \"body\":\"${{ steps.changelog.outputs.CHANGES }}\", \"draft\":false, \"prerelease\":false }") # Extract the upload URL from the response UPLOAD_URL=$(echo "$RELEASE_JSON" | jq -r .upload_url | sed 's/{?name,label}//') # Upload the binary files for file in filaman_${VERSION}.bin webpage_${VERSION}.bin filaman_full_${VERSION}.bin; do if [ -f "$file" ]; then echo "Uploading $file..." curl -L \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer $GITHUB_TOKEN" \ -H "X-GitHub-Api-Version: 2022-11-28" \ -H "Content-Type: application/octet-stream" \ "${UPLOAD_URL}?name=${file}" \ --data-binary "@${file}" fi done