name: Mirror Release to KCC on: release: types: [published] jobs: mirror-release: runs-on: ubuntu-latest steps: - name: Mirror release and assets env: BASE: https://gitea.crjlab.net/api/v1 SOURCE_REPO: bigjakk/krunker-civilian-client DEST_REPO: bigjakk/KPC TOKEN: ${{ secrets.DEST_GITEA_TOKEN }} run: | TAG="${{ github.event.release.tag_name }}" NAME="${{ github.event.release.name }}" BODY=$(echo '${{ toJson(github.event.release.body) }}') # Create tag on KPC pointing to latest main commit SHA=$(curl -s "$BASE/repos/$DEST_REPO/branches/main" \ -H "Authorization: token $TOKEN" | jq -r '.commit.id') echo "Creating tag $TAG on KPC at $SHA" curl -s -X POST "$BASE/repos/$DEST_REPO/tags" \ -H "Authorization: token $TOKEN" \ -H "Content-Type: application/json" \ -d "{\"tag_name\": \"$TAG\", \"message\": \"$TAG\", \"target\": \"$SHA\"}" # Create release on KPC RESPONSE=$(curl -s -X POST "$BASE/repos/$DEST_REPO/releases" \ -H "Authorization: token $TOKEN" \ -H "Content-Type: application/json" \ -d "{ \"tag_name\": \"$TAG\", \"name\": \"$NAME\", \"body\": $BODY, \"draft\": ${{ github.event.release.draft }}, \"prerelease\": ${{ github.event.release.prerelease }} }") RELEASE_ID=$(echo "$RESPONSE" | jq -r '.id') echo "Created KPC release ID: $RELEASE_ID" if [ "$RELEASE_ID" = "null" ] || [ -z "$RELEASE_ID" ]; then echo "Failed to create release" exit 1 fi # Poll source release until assets appear (30s intervals, up to ~6 min) echo "Waiting for source assets..." for ATTEMPT in $(seq 1 12); do RELEASE_INFO=$(curl -s "$BASE/repos/$SOURCE_REPO/releases/tags/$TAG" \ -H "Authorization: token $TOKEN") ASSET_COUNT=$(echo "$RELEASE_INFO" | jq '.assets | length') echo "Attempt $ATTEMPT/12: $ASSET_COUNT asset(s)" [ "$ASSET_COUNT" -gt 0 ] && break [ "$ATTEMPT" -lt 12 ] && sleep 30 done if [ "$ASSET_COUNT" -eq 0 ]; then echo "No assets found after 12 attempts. Aborting." exit 1 fi # Download and re-upload each asset to KPC echo "$RELEASE_INFO" | jq -c '.assets[]' | while read -r asset; do ASSET_NAME=$(echo "$asset" | jq -r '.name') ASSET_URL=$(echo "$asset" | jq -r '.browser_download_url') echo "Mirroring: $ASSET_NAME" curl -sL "$ASSET_URL" -o "/tmp/$ASSET_NAME" -H "Authorization: token $TOKEN" curl -s -X POST "$BASE/repos/$DEST_REPO/releases/$RELEASE_ID/assets?name=$ASSET_NAME" \ -H "Authorization: token $TOKEN" \ -F "attachment=@/tmp/$ASSET_NAME" | jq -r '" -> \(.name) (\(.size) bytes)"' rm "/tmp/$ASSET_NAME" done