From 77d90bbe8394c01e77bddac4e8802d828d5a1977 Mon Sep 17 00:00:00 2001 From: Manuel Weiser Date: Wed, 19 Feb 2025 10:24:43 +0100 Subject: [PATCH] feat: add build and release workflows for Gitea and GitHub, increment version to 1.2.28 --- .github/workflows/providers/build.yml | 87 +++++++++++ .github/workflows/providers/gitea-release.yml | 143 ++++++++++-------- .../workflows/providers/github-release.yml | 87 +++-------- platformio.ini | 2 +- 4 files changed, 181 insertions(+), 138 deletions(-) create mode 100644 .github/workflows/providers/build.yml diff --git a/.github/workflows/providers/build.yml b/.github/workflows/providers/build.yml new file mode 100644 index 0000000..ca75e3b --- /dev/null +++ b/.github/workflows/providers/build.yml @@ -0,0 +1,87 @@ +name: Build Firmware + +on: + workflow_call: + outputs: + version: + description: "The version from the tag" + value: ${{ jobs.build.outputs.version }} + changelog: + description: "The changelog for the current version" + value: ${{ jobs.build.outputs.changelog }} + +jobs: + build: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.get_version.outputs.VERSION }} + changelog: ${{ steps.changelog.outputs.CHANGES }} + 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 + + - name: Build Firmware + run: | + pio run -t buildfs # Build SPIFFS + pio run # Build firmware + + - name: Install esptool + run: | + pip install esptool + + - name: Merge firmware and SPIFFS + run: | + esptool.py --chip esp32 merge_bin \ + --flash_mode dio \ + --flash_freq 40m \ + --flash_size 4MB \ + -o .pio/build/esp32dev/filaman_full.bin \ + 0x1000 .pio/build/esp32dev/bootloader.bin \ + 0x8000 .pio/build/esp32dev/partitions.bin \ + 0x10000 .pio/build/esp32dev/firmware.bin \ + 0x290000 .pio/build/esp32dev/spiffs.bin + + - name: Prepare OTA firmware + run: | + cp .pio/build/esp32dev/firmware.bin .pio/build/esp32dev/filaman_ota.bin + + - name: Get version from tag + id: get_version + run: | + if [ -n "$GITEA_REF" ]; then + echo "VERSION=${GITEA_REF#refs/tags/v}" >> $GITEA_OUTPUT + else + echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT + fi + + - 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) + if [ -n "$GITEA_OUTPUT" ]; then + echo "CHANGES<> $GITEA_OUTPUT + echo "$CHANGELOG" >> $GITEA_OUTPUT + echo "EOF" >> $GITEA_OUTPUT + else + echo "CHANGES<> $GITHUB_OUTPUT + echo "$CHANGELOG" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + fi + + - name: Upload artifacts + uses: actions/upload-artifact@v3 + with: + name: firmware + path: | + .pio/build/esp32dev/filaman_full.bin + .pio/build/esp32dev/filaman_ota.bin \ No newline at end of file diff --git a/.github/workflows/providers/gitea-release.yml b/.github/workflows/providers/gitea-release.yml index 391912a..51f93f3 100644 --- a/.github/workflows/providers/gitea-release.yml +++ b/.github/workflows/providers/gitea-release.yml @@ -1,80 +1,89 @@ name: Gitea Release on: - workflow_call: # This ensures the workflow can only be called from another workflow + workflow_call: jobs: build: + uses: ./.github/workflows/providers/build.yml + + create-release: + needs: build runs-on: ubuntu-latest permissions: - contents: write # Required for creating releases - issues: read # Required for reading changelog - pull-requests: read # Required for reading changelog + contents: write steps: - - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v4 + - name: Download artifacts + uses: actions/download-artifact@v3 with: - python-version: '3.x' - - - name: Install PlatformIO - run: | - python -m pip install --upgrade pip - pip install --upgrade platformio - - - name: Build Firmware - run: | - pio run -t buildfs # Build SPIFFS - pio run # Build firmware - - - name: Install esptool - run: | - pip install esptool - - - name: Merge firmware and SPIFFS - run: | - esptool.py --chip esp32 merge_bin \ - --flash_mode dio \ - --flash_freq 40m \ - --flash_size 4MB \ - -o .pio/build/esp32dev/filaman_full.bin \ - 0x1000 .pio/build/esp32dev/bootloader.bin \ - 0x8000 .pio/build/esp32dev/partitions.bin \ - 0x10000 .pio/build/esp32dev/firmware.bin \ - 0x290000 .pio/build/esp32dev/spiffs.bin + name: firmware + path: firmware - - name: Prepare OTA firmware - run: | - # Use PlatformIO to create a proper OTA image - cp .pio/build/esp32dev/firmware.bin .pio/build/esp32dev/filaman_ota.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: | - CHANGELOG=$(awk "/## \\[${{ steps.get_version.outputs.VERSION }}\\]/{p=1;print;next} /## \\[/{p=0} p" CHANGELOG.md) - echo "CHANGES<> $GITHUB_OUTPUT - echo "$CHANGELOG" >> $GITHUB_OUTPUT - echo "EOF" >> $GITHUB_OUTPUT - - - name: Install and Configure GitHub CLI - run: | - curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \ - && sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \ - && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \ - && sudo apt update \ - && sudo apt install gh -y - - - name: Create Release with GitHub CLI + - name: Create Gitea Release env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} run: | - gh release create "${{ github.ref_name }}" \ - --title "Release ${{ steps.get_version.outputs.VERSION }}" \ - --notes "${{ steps.changelog.outputs.CHANGES }}" \ - ".pio/build/esp32dev/filaman_full.bin#filaman_full.bin" \ - ".pio/build/esp32dev/filaman_ota.bin#filaman_ota.bin" \ No newline at end of file + # Determine API URL if not set + API_URL="${GITEA_API_URL:-${GITEA_SERVER_URL}/api/v1}" + REPO="${GITEA_REPOSITORY}" + TAG="${GITEA_REF_NAME}" + + if [ -z "$API_URL" ] || [ -z "$REPO" ] || [ -z "$TAG" ]; then + echo "Error: Required Gitea environment variables are not set" + env + exit 1 + fi + + # Escape changelog content for JSON + CHANGELOG_ESCAPED=$(echo '${{ needs.build.outputs.changelog }}' | jq -sR .) + + echo "Creating release for tag: $TAG" + echo "Using API URL: $API_URL" + echo "Repository: $REPO" + + # Create release using Gitea API + RELEASE_DATA=$(cat < /dev/null; then + echo "Successfully uploaded $file" + else + echo "Failed to upload $file" + echo "Response: $RESPONSE" + exit 1 + fi + done \ No newline at end of file diff --git a/.github/workflows/providers/github-release.yml b/.github/workflows/providers/github-release.yml index 56cce6e..26c2caf 100644 --- a/.github/workflows/providers/github-release.yml +++ b/.github/workflows/providers/github-release.yml @@ -1,83 +1,30 @@ -name: Github Release +name: GitHub Release on: - workflow_call: # This ensures the workflow can only be called from another workflow - -permissions: - contents: write # Required for creating releases - issues: read # Required for reading changelog - pull-requests: read # Required for reading changelog + workflow_call: jobs: build: + uses: ./.github/workflows/providers/build.yml + + create-release: + needs: build runs-on: ubuntu-latest permissions: - contents: write # Required for creating releases at job level + contents: write steps: - - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v4 + - name: Download artifacts + uses: actions/download-artifact@v3 with: - python-version: '3.x' - - - name: Install PlatformIO - run: | - python -m pip install --upgrade pip - pip install --upgrade platformio - - - name: Build Firmware - run: | - pio run -t buildfs # Build SPIFFS - pio run # Build firmware - - - name: Install esptool - run: | - pip install esptool - - - name: Merge firmware and SPIFFS - run: | - esptool.py --chip esp32 merge_bin \ - --flash_mode dio \ - --flash_freq 40m \ - --flash_size 4MB \ - -o .pio/build/esp32dev/filaman_full.bin \ - 0x1000 .pio/build/esp32dev/bootloader.bin \ - 0x8000 .pio/build/esp32dev/partitions.bin \ - 0x10000 .pio/build/esp32dev/firmware.bin \ - 0x290000 .pio/build/esp32dev/spiffs.bin + name: firmware + path: firmware - - name: Prepare OTA firmware - run: | - # Use PlatformIO to create a proper OTA image - cp .pio/build/esp32dev/firmware.bin .pio/build/esp32dev/filaman_ota.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: | - CHANGELOG=$(awk "/## \\[${{ steps.get_version.outputs.VERSION }}\\]/{p=1;print;next} /## \\[/{p=0} p" CHANGELOG.md) - echo "CHANGES<> $GITHUB_OUTPUT - echo "$CHANGELOG" >> $GITHUB_OUTPUT - echo "EOF" >> $GITHUB_OUTPUT - - - name: Install and Configure GitHub CLI - run: | - curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \ - && sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \ - && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \ - && sudo apt update \ - && sudo apt install gh -y - - - name: Create Release with GitHub CLI + - name: Create GitHub Release env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ github.token }} run: | gh release create "${{ github.ref_name }}" \ - --title "Release ${{ steps.get_version.outputs.VERSION }}" \ - --notes "${{ steps.changelog.outputs.CHANGES }}" \ - ".pio/build/esp32dev/filaman_full.bin#filaman_full.bin" \ - ".pio/build/esp32dev/filaman_ota.bin#filaman_ota.bin" \ No newline at end of file + --title "Release ${{ needs.build.outputs.version }}" \ + --notes "${{ needs.build.outputs.changelog }}" \ + firmware/filaman_full.bin \ + firmware/filaman_ota.bin \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 400b7b1..9d2e9cd 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,7 @@ ; https://docs.platformio.org/page/projectconf.html [common] -version = "1.2.27" +version = "1.2.28" [env:esp32dev] platform = espressif32