diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 40df5b13b5..d9fb720ff3 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -184,152 +184,49 @@ jobs: # Create checksum cd dist && sha256sum "${OUTPUT}" > "${OUTPUT}.sha256" - - name: Upload artifacts - uses: actions/upload-artifact@v4 - with: - name: gitea-${{ matrix.goos }}-${{ matrix.goarch }} - path: dist/gitea-* - retention-days: 7 - - # Docker build job - disabled until Docker is available on runner - docker: - name: Build Docker Image - runs-on: ubuntu-latest - needs: lint-test - if: false # Disabled - runner doesn't have Docker - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Get version - id: version + - name: Upload to release + if: startsWith(github.ref, 'refs/tags/v') run: | - if [[ $GITHUB_REF == refs/tags/* ]]; then - VERSION=${GITHUB_REF#refs/tags/} - else - VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo "dev") - fi - echo "version=${VERSION}" >> $GITHUB_OUTPUT + VERSION=$(git describe --tags --always 2>/dev/null || echo "dev") + echo "Uploading binaries for $VERSION" - - name: Build Docker image - uses: docker/build-push-action@v5 - with: - context: . - platforms: linux/amd64,linux/arm64 - push: false - tags: | - gitea/gitea:${{ steps.version.outputs.version }} - gitea/gitea:latest - cache-from: type=gha - cache-to: type=gha,mode=max - - # Release job - only runs on tags - release: - name: Create Release - runs-on: ubuntu-latest - needs: build - if: startsWith(github.ref, 'refs/tags/v') - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Download all artifacts - uses: actions/download-artifact@v4 - with: - path: dist - merge-multiple: true - - - name: List artifacts - run: ls -la dist/ - - - name: Get version - id: version - run: | - VERSION=${GITHUB_REF#refs/tags/} - echo "version=${VERSION}" >> $GITHUB_OUTPUT - - - name: Generate changelog - id: changelog - run: | - # Get commits since last tag - PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") - if [ -n "$PREV_TAG" ]; then - CHANGELOG=$(git log --pretty=format:"- %s (%h)" ${PREV_TAG}..HEAD) - else - CHANGELOG=$(git log --pretty=format:"- %s (%h)" -20) - fi - - # Escape for GitHub Actions - CHANGELOG="${CHANGELOG//'%'/'%25'}" - CHANGELOG="${CHANGELOG//$'\n'/'%0A'}" - CHANGELOG="${CHANGELOG//$'\r'/'%0D'}" - - echo "changelog=${CHANGELOG}" >> $GITHUB_OUTPUT - - - name: Create Release - run: | - VERSION="${{ steps.version.outputs.version }}" - IS_PRERELEASE="false" - if [[ "$VERSION" == *"-rc"* ]] || [[ "$VERSION" == *"-beta"* ]] || [[ "$VERSION" == *"-alpha"* ]]; then - IS_PRERELEASE="true" - fi - - RELEASE_BODY="## Changes in ${VERSION} - - ${{ steps.changelog.outputs.changelog }} - - ## Downloads - - | Platform | Architecture | Download | - |----------|--------------|----------| - | Linux | amd64 | gitea-${VERSION}-linux-amd64 | - | Linux | arm64 | gitea-${VERSION}-linux-arm64 | - | macOS | amd64 | gitea-${VERSION}-darwin-amd64 | - | macOS | arm64 | gitea-${VERSION}-darwin-arm64 | - | Windows | amd64 | gitea-${VERSION}-windows-amd64.exe | - - ## Checksums - - SHA256 checksums are provided in .sha256 files alongside each binary." - - # Create release via Gitea API - RELEASE_DATA=$(jq -n \ - --arg tag "$VERSION" \ - --arg name "Gitea $VERSION" \ - --arg body "$RELEASE_BODY" \ - --argjson prerelease "$IS_PRERELEASE" \ - '{tag_name: $tag, name: $name, body: $body, draft: false, prerelease: $prerelease}') - - RESPONSE=$(curl -s -X POST \ + # Get or create release + TAG="${{ github.ref_name }}" + EXISTING=$(curl -s \ -H "Authorization: token ${{ secrets.RELEASE_TOKEN }}" \ - -H "Content-Type: application/json" \ - -d "$RELEASE_DATA" \ - "${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases") + "${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/tags/$TAG") - echo "Release response: $RESPONSE" - RELEASE_ID=$(echo "$RESPONSE" | jq -r '.id') - echo "Created release with ID: $RELEASE_ID" + if echo "$EXISTING" | grep -q '"id":[0-9]'; then + RELEASE_ID=$(echo "$EXISTING" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2) + echo "Found existing release: $RELEASE_ID" + else + echo "Creating release..." + RESPONSE=$(curl -s -X POST \ + -H "Authorization: token ${{ secrets.RELEASE_TOKEN }}" \ + -H "Content-Type: application/json" \ + -d '{"tag_name":"'"$TAG"'","name":"Gitea '"$TAG"'","body":"Official release.","draft":false,"prerelease":false}' \ + "${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases") + RELEASE_ID=$(echo "$RESPONSE" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2) + echo "Created release: $RELEASE_ID" + fi - # Upload assets + # Upload files for file in dist/*; do if [ -f "$file" ]; then filename=$(basename "$file") + # Delete existing asset if present + ASSETS=$(curl -s -H "Authorization: token ${{ secrets.RELEASE_TOKEN }}" \ + "${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/$RELEASE_ID") + ASSET_ID=$(echo "$ASSETS" | grep -o "\"id\":[0-9]*,\"name\":\"$filename\"" | grep -o '"id":[0-9]*' | cut -d: -f2) + if [ -n "$ASSET_ID" ]; then + echo "Deleting existing $filename" + curl -s -X DELETE -H "Authorization: token ${{ secrets.RELEASE_TOKEN }}" \ + "${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/$RELEASE_ID/assets/$ASSET_ID" + fi echo "Uploading $filename..." curl -s -X POST \ -H "Authorization: token ${{ secrets.RELEASE_TOKEN }}" \ - -H "Content-Type: multipart/form-data" \ -F "attachment=@$file" \ "${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/$RELEASE_ID/assets?name=$filename" - echo "Uploaded $filename" fi done