name: Build and Release on: push: branches: - main permissions: contents: write jobs: build-and-release: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Check if version already released id: version-check env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | VERSION=$(grep '"version"' package.json | head -1 | sed 's/.*"version": *"\([^"]*\)".*/\1/') TAG="v$VERSION" echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT" echo "TAG=$TAG" >> "$GITHUB_OUTPUT" STATUS=$(curl -s -o /dev/null -w "%{http_code}" \ -H "Authorization: Bearer $GITHUB_TOKEN" \ "https://api.github.com/repos/${{ github.repository }}/releases/tags/$TAG") if [ "$STATUS" = "200" ]; then echo "Release $TAG already exists, skipping build" echo "SKIP=true" >> "$GITHUB_OUTPUT" else echo "No release for $TAG, proceeding with build" echo "SKIP=false" >> "$GITHUB_OUTPUT" fi - name: Setup Node.js if: steps.version-check.outputs.SKIP == 'false' uses: actions/setup-node@v4 with: node-version: '22' - name: Install Wine (for Windows cross-compilation) if: steps.version-check.outputs.SKIP == 'false' run: | sudo dpkg --add-architecture i386 sudo apt-get update -qq sudo apt-get install -y --no-install-recommends wine64 wine32 WINEDEBUG=-all wine wineboot --init || true - name: Install dependencies if: steps.version-check.outputs.SKIP == 'false' run: npm ci - name: Build source if: steps.version-check.outputs.SKIP == 'false' run: npm run build - name: Build Windows distributables if: steps.version-check.outputs.SKIP == 'false' env: WINEDEBUG: "-all" run: npx electron-builder --win -c.electronDist=node_modules/electron/dist-win --publish never - name: Build Linux distributables if: steps.version-check.outputs.SKIP == 'false' run: npx electron-builder --linux --publish never - name: List build output if: steps.version-check.outputs.SKIP == 'false' run: | echo "=== Build output ===" ls -lh out/ 2>/dev/null || echo "No out/ directory" - name: Create release and upload assets if: steps.version-check.outputs.SKIP == 'false' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} TAG: ${{ steps.version-check.outputs.TAG }} run: | API="https://api.github.com/repos/${{ github.repository }}" AUTH="Authorization: Bearer $GITHUB_TOKEN" # Create release RESPONSE=$(curl -s -X POST "$API/releases" \ -H "$AUTH" \ -H "Content-Type: application/json" \ -d "{ \"tag_name\": \"$TAG\", \"name\": \"$TAG\", \"body\": \"Automated build for $TAG\", \"draft\": false, \"prerelease\": false }") RELEASE_ID=$(echo "$RESPONSE" | jq -r '.id') UPLOAD_URL=$(echo "$RESPONSE" | jq -r '.upload_url' | sed 's/{?name,label}//') echo "Created release ID: $RELEASE_ID" if [ "$RELEASE_ID" = "null" ] || [ -z "$RELEASE_ID" ]; then echo "Failed to create release:" echo "$RESPONSE" exit 1 fi # Upload all built artifacts UPLOADED=0 for file in out/*.exe out/*.AppImage out/*.deb; do [ -f "$file" ] || continue FILENAME=$(basename "$file") echo "Uploading: $FILENAME ($(du -h "$file" | cut -f1))" curl -s -X POST "${UPLOAD_URL}?name=${FILENAME}" \ -H "$AUTH" \ -H "Content-Type: application/octet-stream" \ --data-binary "@$file" \ | jq -r '" -> \(.name) (\(.size) bytes)"' UPLOADED=$((UPLOADED + 1)) done if [ "$UPLOADED" -eq 0 ]; then echo "WARNING: No artifacts found in out/" ls -la out/ 2>/dev/null || true fi echo "Uploaded $UPLOADED assets"