feat: enhance GitHub and Gitea release workflows with Python setup and binary preparation
This commit is contained in:
parent
306c517da7
commit
e224e72e41
182
.github/workflows/release.yml
vendored
182
.github/workflows/release.yml
vendored
@ -51,20 +51,186 @@ jobs:
|
||||
if [ "${{ needs.route.outputs.provider }}" = "unknown" ]; then
|
||||
echo "::error::Failed to detect CI provider!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
github-release:
|
||||
needs: [route, verify-provider]
|
||||
if: needs.route.outputs.provider == 'github'
|
||||
uses: ./.github/workflows/providers/github-release.yml
|
||||
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)
|
||||
echo "Building firmware and SPIFFS..."
|
||||
pio run -e esp32dev
|
||||
pio run -t buildfs
|
||||
cp .pio/build/esp32dev/firmware.bin .pio/build/esp32dev/filaman_${VERSION}.bin
|
||||
cp .pio/build/esp32dev/spiffs.bin .pio/build/esp32dev/webpage_${VERSION}.bin
|
||||
(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)
|
||||
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: Create GitHub Release
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
run: |
|
||||
VERSION=${{ steps.get_version.outputs.VERSION }}
|
||||
cd .pio/build/esp32dev
|
||||
FILES_TO_UPLOAD=""
|
||||
if [ -f "filaman_${VERSION}.bin" ]; then
|
||||
FILES_TO_UPLOAD="$FILES_TO_UPLOAD filaman_${VERSION}.bin"
|
||||
fi
|
||||
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
|
||||
if [ -n "$FILES_TO_UPLOAD" ]; then
|
||||
gh release create "v${VERSION}" --title "Release ${VERSION}" --notes "${{ steps.changelog.outputs.CHANGES }}" $FILES_TO_UPLOAD
|
||||
else
|
||||
echo "Error: No files found to upload"
|
||||
exit 1
|
||||
|
||||
gitea-release:
|
||||
needs: [route, verify-provider]
|
||||
if: needs.route.outputs.provider == 'gitea'
|
||||
uses: ./.github/workflows/providers/gitea-release.yml
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
gitea_ref_name: ${{ needs.route.outputs.gitea_ref_name }}
|
||||
gitea_server_url: ${{ needs.route.outputs.gitea_server_url }}
|
||||
gitea_repository: ${{ needs.route.outputs.gitea_repository }}
|
||||
secrets:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
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: 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: Get version from platformio.ini
|
||||
id: get_version
|
||||
run: |
|
||||
VERSION=$(grep '^version = ' platformio.ini | cut -d'"' -f2)
|
||||
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
|
||||
- name: Build Firmware
|
||||
run: |
|
||||
VERSION=${{ steps.get_version.outputs.VERSION }}
|
||||
echo "Building firmware and SPIFFS..."
|
||||
pio run -e esp32dev
|
||||
pio run -t buildfs
|
||||
cp .pio/build/esp32dev/firmware.bin .pio/build/esp32dev/filaman_${VERSION}.bin
|
||||
cp .pio/build/esp32dev/spiffs.bin .pio/build/esp32dev/webpage_${VERSION}.bin
|
||||
(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)
|
||||
echo "File sizes:"
|
||||
(cd .pio/build/esp32dev && ls -lh *.bin)
|
||||
- name: Prepare binaries
|
||||
run: |
|
||||
VERSION=${{ steps.get_version.outputs.VERSION }}
|
||||
if [[ "${{ steps.check_spiffs.outputs.SPIFFS_CHANGED }}" == "true" ]]; then
|
||||
echo "Creating 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 0x0000 bootloader.bin 0x8000 partitions.bin 0x10000 firmware.bin 0x390000 spiffs.bin
|
||||
fi
|
||||
echo "File sizes:"
|
||||
cd .pio/build/esp32dev && ls -lh *.bin
|
||||
- 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 Release
|
||||
env:
|
||||
TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
run: |
|
||||
API_URL="${{ needs.route.outputs.gitea_server_url }}/api/v1"
|
||||
REPO="${{ needs.route.outputs.gitea_repository }}"
|
||||
VERSION=${{ steps.get_version.outputs.VERSION }}
|
||||
RESPONSE=$(curl -k -s -X POST -H "Authorization: token ${TOKEN}" -H "Content-Type: application/json" -d "{\"tag_name\":\"v${VERSION}\",\"name\":\"Release ${VERSION}\",\"body\":\"${{ steps.changelog.outputs.CHANGES }}\"}" "${API_URL}/repos/${REPO}/releases")
|
||||
RELEASE_ID=$(echo "$RESPONSE" | grep -o '"id":[0-9]*' | cut -d':' -f2 | head -n1)
|
||||
if [ -n "$RELEASE_ID" ]; then
|
||||
echo "Release created with ID: $RELEASE_ID"
|
||||
for file in filaman_${VERSION}.bin filaman_full_${VERSION}.bin; do
|
||||
if [ -f ".pio/build/esp32dev/$file" ]; then
|
||||
echo "Uploading $file..."
|
||||
curl -k -s -X POST -H "Authorization: token ${TOKEN}" -H "Content-Type: application/octet-stream" --data-binary "@.pio/build/esp32dev/$file" "${API_URL}/repos/${REPO}/releases/${RELEASE_ID}/assets?name=$file"
|
||||
fi
|
||||
done
|
||||
if [ -f ".pio/build/esp32dev/webpage_${VERSION}.bin" ]; then
|
||||
echo "Uploading webpage binary..."
|
||||
curl -k -s -X POST -H "Authorization: token ${TOKEN}" -H "Content-Type: application/octet-stream" --data-binary "@.pio/build/esp32dev/webpage_${VERSION}.bin" "${API_URL}/repos/${REPO}/releases/${RELEASE_ID}/assets?name=webpage_${VERSION}.bin"
|
||||
fi
|
||||
else
|
||||
echo "Failed to create release. Response:"
|
||||
echo "$RESPONSE"
|
||||
exit 1
|
Loading…
x
Reference in New Issue
Block a user