166 lines
5.7 KiB
YAML
166 lines
5.7 KiB
YAML
name: Gitea Release
|
|
|
|
on:
|
|
workflow_call:
|
|
secrets:
|
|
GITEA_TOKEN:
|
|
description: 'Token für Gitea API-Zugriff'
|
|
required: true
|
|
|
|
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<<EOF" >> $GITHUB_OUTPUT
|
|
echo "$CHANGELOG" >> $GITHUB_OUTPUT
|
|
echo "EOF" >> $GITHUB_OUTPUT
|
|
|
|
- name: Determine Gitea URL
|
|
id: gitea_url
|
|
run: |
|
|
echo "Debug Environment:"
|
|
echo "GITHUB_SERVER_URL=${GITHUB_SERVER_URL:-not set}"
|
|
echo "GITEA_SERVER_URL=${GITEA_SERVER_URL:-not set}"
|
|
echo "GITHUB_REPOSITORY=${GITHUB_REPOSITORY:-not set}"
|
|
echo "GITEA_REPOSITORY=${GITEA_REPOSITORY:-not set}"
|
|
echo "RUNNER_NAME=${RUNNER_NAME:-not set}"
|
|
|
|
# Set API URL based on environment
|
|
if [ -n "${GITEA_ACTIONS}" ] || [ -n "${GITEA_REPOSITORY}" ] || [[ "${RUNNER_NAME}" == *"gitea"* ]]; then
|
|
GITEA_API_URL="${GITHUB_SERVER_URL}"
|
|
GITEA_REPO=$(echo "${GITHUB_REPOSITORY}" | cut -d'/' -f2)
|
|
GITEA_OWNER=$(echo "${GITHUB_REPOSITORY}" | cut -d'/' -f1)
|
|
else
|
|
echo "Error: This workflow is only for Gitea"
|
|
exit 1
|
|
fi
|
|
|
|
echo "GITEA_API_URL=${GITEA_API_URL}" >> $GITHUB_OUTPUT
|
|
echo "GITEA_REPO=${GITEA_REPO}" >> $GITHUB_OUTPUT
|
|
echo "GITEA_OWNER=${GITEA_OWNER}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Create Gitea Release
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
GITEA_API_URL: ${{ steps.gitea_url.outputs.GITEA_API_URL }}
|
|
GITEA_REPO: ${{ steps.gitea_url.outputs.GITEA_REPO }}
|
|
GITEA_OWNER: ${{ steps.gitea_url.outputs.GITEA_OWNER }}
|
|
run: |
|
|
# Debug Token (nur Länge ausgeben für Sicherheit)
|
|
echo "Debug: Token length: ${#GITEA_TOKEN}"
|
|
if [ -z "$GITEA_TOKEN" ]; then
|
|
echo "Error: GITEA_TOKEN is empty"
|
|
exit 1
|
|
fi
|
|
|
|
VERSION=${{ steps.get_version.outputs.VERSION }}
|
|
cd .pio/build/esp32dev
|
|
|
|
# Debug-Ausgaben
|
|
echo "Debug: API URL: ${GITEA_API_URL}"
|
|
echo "Debug: Repository: ${GITEA_OWNER}/${GITEA_REPO}"
|
|
|
|
# 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 -F \"attach[]=@$file\""
|
|
echo "Debug: Found file: $file"
|
|
fi
|
|
done
|
|
|
|
# Test API connection with explicit token header
|
|
echo "Debug: Testing API connection..."
|
|
TEST_RESPONSE=$(curl -s -w "\n%{http_code}" \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
"${GITEA_API_URL}/api/v1/version")
|
|
TEST_STATUS=$(echo "$TEST_RESPONSE" | tail -n1)
|
|
if [ "$TEST_STATUS" != "200" ]; then
|
|
echo "Error: Cannot connect to Gitea API"
|
|
echo "Response: $TEST_RESPONSE"
|
|
exit 1
|
|
fi
|
|
|
|
# Create release using API
|
|
echo "Debug: Creating release..."
|
|
RELEASE_DATA="{\"tag_name\":\"v${VERSION}\",\"name\":\"v${VERSION}\",\"body\":\"${{ steps.changelog.outputs.CHANGES }}\"}"
|
|
|
|
# Create release with explicit token header and file uploads
|
|
CURL_CMD="curl -s -w \"\n%{http_code}\" \
|
|
-X POST \
|
|
-H \"Authorization: token ${GITEA_TOKEN}\" \
|
|
-H \"Content-Type: application/json\" \
|
|
-d '${RELEASE_DATA}' \
|
|
${FILES} \
|
|
\"${GITEA_API_URL}/api/v1/repos/${GITEA_OWNER}/${GITEA_REPO}/releases\""
|
|
|
|
RESPONSE=$(eval $CURL_CMD)
|
|
|
|
HTTP_STATUS=$(echo "$RESPONSE" | tail -n1)
|
|
RESPONSE_BODY=$(echo "$RESPONSE" | head -n -1)
|
|
|
|
echo "Debug: HTTP Status: $HTTP_STATUS"
|
|
if [ "$HTTP_STATUS" != "201" ]; then
|
|
echo "Error: Failed to create release"
|
|
echo "Response: $RESPONSE_BODY"
|
|
exit 1 |