From da1fc7678f5804da22c771e01342b0e7eb12c3a1 Mon Sep 17 00:00:00 2001 From: Manuel Weiser Date: Fri, 21 Feb 2025 22:34:18 +0100 Subject: [PATCH] workflow: enhance Gitea release process with API integration and token management --- .github/workflows/gitea-release.yml | 38 ++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/.github/workflows/gitea-release.yml b/.github/workflows/gitea-release.yml index d9bf611..19634aa 100644 --- a/.github/workflows/gitea-release.yml +++ b/.github/workflows/gitea-release.yml @@ -72,6 +72,9 @@ jobs: echo "EOF" >> $GITHUB_OUTPUT - name: Create Gitea Release + env: + GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} + GITEA_API_URL: ${{ secrets.GITEA_API_URL }} run: | VERSION=${{ steps.get_version.outputs.VERSION }} cd .pio/build/esp32dev @@ -84,6 +87,35 @@ jobs: fi done - # Create release using git command - git tag -a "v${VERSION}" -m "Release ${VERSION}" - git push origin "v${VERSION}" \ No newline at end of file + # 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 + RESPONSE=$(curl -X POST \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -H "Content-Type: application/json" \ + -d "$RELEASE_DATA" \ + "${GITEA_API_URL}/repos/owner/repo/releases") + + # Upload assets + RELEASE_ID=$(echo $RESPONSE | jq -r .id) + for file in upgrade_filaman_firmware_v${VERSION}.bin upgrade_filaman_website_v${VERSION}.bin filaman_full_${VERSION}.bin; do + if [ -f "$file" ]; then + curl -X POST \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -H "Content-Type: application/octet-stream" \ + --data-binary @"$file" \ + "${GITEA_API_URL}/repos/owner/repo/releases/${RELEASE_ID}/assets?name=${file}" + fi + done \ No newline at end of file