diff --git a/.gitea/workflows/multi-platform.yml b/.gitea/workflows/multi-platform.yml index 0930bb1..789a211 100644 --- a/.gitea/workflows/multi-platform.yml +++ b/.gitea/workflows/multi-platform.yml @@ -48,4 +48,125 @@ jobs: # The target is passed to the reusable workflow target: ${{ matrix.target }} upload-artifacts: true - package-only: true \ No newline at end of file + package-only: true + + # Create GitHub release with all artifacts + create-release: + if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main') + needs: [package] + runs-on: ubuntu-22.04 + name: Create GitHub Release + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Fetch full history for release notes generation + + - name: Download all artifacts + uses: https://github.com/christopherHX/gitea-download-artifact@v4 + with: + path: artifacts/ + + - name: Extract version from Cargo.toml + id: version + run: | + VERSION=$(sed -n 's/^version\s*=\s*"\([^"]\+\)"/\1/p' Cargo.toml | head -n1) + echo "version=v$VERSION" >> $GITHUB_OUTPUT + echo "Version: v$VERSION" + + - name: Get last release tag + id: last_tag + run: | + LAST_TAG=$(git describe --tags --abbrev=0 HEAD~1 2>/dev/null || echo "") + if [ -z "$LAST_TAG" ]; then + LAST_TAG=$(git rev-list --max-parents=0 HEAD) + fi + echo "last_tag=$LAST_TAG" >> $GITHUB_OUTPUT + echo "Last tag/commit: $LAST_TAG" + + - name: Generate release notes with GPT-5 + id: release_notes + env: + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + run: | + # Get git log since last release + if [ -n "${{ steps.last_tag.outputs.last_tag }}" ]; then + GIT_LOG=$(git log --pretty=format:"- %s (%an)" ${{ steps.last_tag.outputs.last_tag }}..HEAD) + else + GIT_LOG=$(git log --pretty=format:"- %s (%an)" HEAD~10..HEAD) + fi + + # Create a temporary file for the API request + cat > request.json << EOF + { + "model": "gpt-4o", + "messages": [ + { + "role": "system", + "content": "You are a technical writer creating GitHub release notes. Generate professional, concise release notes based on git commit history. Focus on user-facing changes and improvements. Use proper markdown formatting with sections like ## What's New, ## Improvements, ## Bug Fixes, etc. Keep it under 500 words." + }, + { + "role": "user", + "content": "Generate release notes for version ${{ steps.version.outputs.version }} based on these commits:\\n\\n$GIT_LOG" + } + ], + "max_tokens": 1000, + "temperature": 0.3 + } + EOF + + # Make API request to OpenAI + RESPONSE=$(curl -s -X POST "https://api.openai.com/v1/chat/completions" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d @request.json) + + # Extract the content and save to file + echo "$RESPONSE" | jq -r '.choices[0].message.content' > release_notes.md + + # Set output for use in release creation + { + echo 'notes<> $GITHUB_OUTPUT + + - name: Prepare release assets + run: | + mkdir -p release_assets + find artifacts/ -name "*.tar.gz" -o -name "*.zip" | while read file; do + cp "$file" release_assets/ + done + ls -la release_assets/ + + - name: Create Gitea Release + run: | + # Create the release using Gitea API + curl -X POST \ + -H "Authorization: token ${{ secrets.RELEASE_TOKEN }}" \ + -H "Content-Type: application/json" \ + -d '{ + "tag_name": "${{ steps.version.outputs.version }}", + "name": "Release ${{ steps.version.outputs.version }}", + "body": "'"$(cat release_notes.md | sed 's/"/\\"/g' | tr '\n' '\\n')"'", + "draft": false, + "prerelease": false + }' \ + "${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases" + + - name: Upload release assets + run: | + # Get the release ID from the created release + RELEASE_ID=$(curl -s -H "Authorization: token ${{ secrets.RELEASE_TOKEN }}" \ + "${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/tags/${{ steps.version.outputs.version }}" | \ + jq -r '.id') + + # Upload each asset + for file in release_assets/*; do + filename=$(basename "$file") + echo "Uploading $filename..." + curl -X POST \ + -H "Authorization: token ${{ secrets.RELEASE_TOKEN }}" \ + -H "Content-Type: application/octet-stream" \ + --data-binary @"$file" \ + "${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/$RELEASE_ID/assets?name=$filename" + done \ No newline at end of file