name: Gitea Release on: workflow_call: jobs: create-release: runs-on: ubuntu-latest 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: Build Firmware run: | VERSION=$(grep '^version = ' platformio.ini | cut -d'"' -f2) # 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/upgrade_filaman_firmware_v${VERSION}.bin # Create SPIFFS binary cp .pio/build/esp32dev/spiffs.bin .pio/build/esp32dev/upgrade_filaman_website_v${VERSION}.bin # Create full binary (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 Gitea Release env: GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} GITEA_API_URL: ${{ secrets.GITEA_API_URL }} GITEA_REPO: ${{ secrets.GITEA_REPO }} GITEA_OWNER: ${{ secrets.GITEA_OWNER }} run: | VERSION=${{ steps.get_version.outputs.VERSION }} cd .pio/build/esp32dev # Prepare files for upload FILES="" for file in upgrade_filaman_firmware_v${VERSION}.bin upgrade_filaman_website_v${VERSION}.bin filaman_full_${VERSION}.bin; do if [ -f "$file" ]; then FILES="$FILES -a $file" fi done # Check if tag exists if ! git rev-parse "v${VERSION}" >/dev/null 2>&1; then # Create tag if it doesn't exist git tag -a "v${VERSION}" -m "Release ${VERSION}" git push origin "v${VERSION}" fi # Create Gitea release using API RELEASE_DATA="{ \"tag_name\": \"v${VERSION}\", \"name\": \"v${VERSION}\", \"body\": \"${{ steps.changelog.outputs.CHANGES }}\" }" # Create release and capture HTTP status RESPONSE=$(curl -s -w "%{http_code}" -X POST \ -H "Authorization: token ${GITEA_TOKEN}" \ -H "Content-Type: application/json" \ -d "$RELEASE_DATA" \ "${GITEA_API_URL}/api/v1/repos/${GITEA_OWNER}/${GITEA_REPO}/releases") HTTP_STATUS=${RESPONSE: -3} RESPONSE_BODY=${RESPONSE:0:-3} if [ "$HTTP_STATUS" != "201" ]; then echo "Fehler beim Erstellen des Releases: $RESPONSE_BODY" exit 1 fi # Extract release ID from response RELEASE_ID=$(echo "$RESPONSE_BODY" | jq -r .id) # Upload assets for file in upgrade_filaman_firmware_v${VERSION}.bin upgrade_filaman_website_v${VERSION}.bin filaman_full_${VERSION}.bin; do if [ -f "$file" ]; then echo "Uploading $file..." UPLOAD_RESPONSE=$(curl -s -w "%{http_code}" -X POST \ -H "Authorization: token ${GITEA_TOKEN}" \ -H "Content-Type: application/octet-stream" \ --data-binary @"$file" \ "${GITEA_API_URL}/api/v1/repos/${GITEA_OWNER}/${GITEA_REPO}/releases/${RELEASE_ID}/assets?name=${file}") UPLOAD_STATUS=${UPLOAD_RESPONSE: -3} if [ "$UPLOAD_STATUS" != "201" ]; then echo "Fehler beim Upload von $file" exit 1 fi fi done