|
| 1 | +name: Build with Ruff Support |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: ['v*'] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +env: |
| 12 | + NODE_VERSION: 'v20.11.0' |
| 13 | + RUFF_VERSION: '0.14.3' |
| 14 | + |
| 15 | +jobs: |
| 16 | + linux: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + strategy: |
| 19 | + matrix: |
| 20 | + arch: [x64] |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v4 |
| 23 | + |
| 24 | + - uses: actions/setup-node@v4 |
| 25 | + with: |
| 26 | + node-version: '20' |
| 27 | + |
| 28 | + - name: Install dependencies |
| 29 | + run: npm install |
| 30 | + |
| 31 | + - name: Build for linux-${{ matrix.arch }} with Ruff |
| 32 | + run: | |
| 33 | + PLATFORM="linux-${{ matrix.arch }}" |
| 34 | + NODE_ARCH="linux-${{ matrix.arch }}" |
| 35 | + |
| 36 | + mkdir -p output/${PLATFORM} |
| 37 | + |
| 38 | + # Bundle TypeScript with esbuild |
| 39 | + npx esbuild index.ts \ |
| 40 | + --bundle \ |
| 41 | + --platform=node \ |
| 42 | + --target=node18 \ |
| 43 | + --format=esm \ |
| 44 | + --outfile=output/${PLATFORM}/bundle.js \ |
| 45 | + --external:ws \ |
| 46 | + --external:vscode-ws-jsonrpc \ |
| 47 | + --external:vscode-jsonrpc \ |
| 48 | + --external:dotenv |
| 49 | + |
| 50 | + # Download Node.js runtime |
| 51 | + NODE_PKG="node-${NODE_VERSION}-${NODE_ARCH}" |
| 52 | + NODE_URL="https://nodejs.org/dist/${NODE_VERSION}/${NODE_PKG}.tar.gz" |
| 53 | + curl -L "${NODE_URL}" -o /tmp/${NODE_PKG}.tar.gz |
| 54 | + tar -xzf /tmp/${NODE_PKG}.tar.gz -C /tmp/ |
| 55 | + mv /tmp/${NODE_PKG} output/${PLATFORM}/node |
| 56 | + |
| 57 | + # Strip unnecessary files from Node.js |
| 58 | + cd output/${PLATFORM}/node |
| 59 | + rm -rf lib/node_modules/npm lib/node_modules/corepack |
| 60 | + rm -f bin/npm bin/npx bin/corepack |
| 61 | + rm -rf share/doc share/man share/systemtap include |
| 62 | + rm -f README.md CHANGELOG.md LICENSE *.md |
| 63 | + strip bin/node 2>/dev/null || true |
| 64 | + cd ../../.. |
| 65 | + |
| 66 | + # Download Ruff for Linux |
| 67 | + echo "Downloading Ruff ${RUFF_VERSION} for linux-x64..." |
| 68 | + RUFF_URL="https://github.com/astral-sh/ruff/releases/download/${RUFF_VERSION}/ruff-x86_64-unknown-linux-gnu.tar.gz" |
| 69 | + mkdir -p output/${PLATFORM}/bin |
| 70 | + curl -L -A "Mozilla/5.0" "${RUFF_URL}" -o /tmp/ruff.tar.gz |
| 71 | + tar -xzf /tmp/ruff.tar.gz -C /tmp/ |
| 72 | + cp /tmp/ruff-x86_64-unknown-linux-gnu/ruff output/${PLATFORM}/bin/ruff |
| 73 | + chmod +x output/${PLATFORM}/bin/ruff |
| 74 | + |
| 75 | + # Install production dependencies |
| 76 | + cp package.json output/${PLATFORM}/ |
| 77 | + cd output/${PLATFORM} |
| 78 | + npm install --production --no-optional |
| 79 | + rm package-lock.json |
| 80 | + echo '{"type":"module"}' > package.json |
| 81 | + |
| 82 | + # Prune unnecessary files from node_modules |
| 83 | + find node_modules -type d -name "test" -exec rm -rf {} + 2>/dev/null || true |
| 84 | + find node_modules -type d -name "tests" -exec rm -rf {} + 2>/dev/null || true |
| 85 | + find node_modules -type d -name "docs" -exec rm -rf {} + 2>/dev/null || true |
| 86 | + find node_modules -type f -name "*.md" -delete 2>/dev/null || true |
| 87 | + find node_modules -type f -name "*.ts" ! -name "*.d.ts" -delete 2>/dev/null || true |
| 88 | + find node_modules -type f -name "*.map" -delete 2>/dev/null || true |
| 89 | + cd ../.. |
| 90 | + |
| 91 | + # Copy config template |
| 92 | + cp pyrightconfig.json output/${PLATFORM}/ |
| 93 | + |
| 94 | + # Create start script with RUFF_PATH |
| 95 | + cat > output/${PLATFORM}/start.sh << 'EOF' |
| 96 | + #!/bin/bash |
| 97 | + DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 98 | + export RUFF_PATH="${DIR}/bin/ruff" |
| 99 | + "${DIR}/node/bin/node" "${DIR}/bundle.js" "$@" |
| 100 | + EOF |
| 101 | + chmod +x output/${PLATFORM}/start.sh |
| 102 | + |
| 103 | + # Create compressed archive |
| 104 | + cd output |
| 105 | + tar -czf ${PLATFORM}.tar.gz ${PLATFORM}/ |
| 106 | + cd .. |
| 107 | + |
| 108 | + - name: Upload artifact |
| 109 | + uses: actions/upload-artifact@v4 |
| 110 | + with: |
| 111 | + name: linux-${{ matrix.arch }} |
| 112 | + path: output/linux-${{ matrix.arch }}.tar.gz |
| 113 | + |
| 114 | + macos: |
| 115 | + runs-on: macos-latest |
| 116 | + strategy: |
| 117 | + matrix: |
| 118 | + arch: [x64, arm64] |
| 119 | + steps: |
| 120 | + - uses: actions/checkout@v4 |
| 121 | + |
| 122 | + - uses: actions/setup-node@v4 |
| 123 | + with: |
| 124 | + node-version: '20' |
| 125 | + |
| 126 | + - name: Install dependencies |
| 127 | + run: npm install |
| 128 | + |
| 129 | + - name: Build for darwin-${{ matrix.arch }} with Ruff |
| 130 | + run: | |
| 131 | + PLATFORM="darwin-${{ matrix.arch }}" |
| 132 | + NODE_ARCH="darwin-${{ matrix.arch }}" |
| 133 | + |
| 134 | + mkdir -p output/${PLATFORM} |
| 135 | + |
| 136 | + # Bundle TypeScript with esbuild |
| 137 | + npx esbuild index.ts \ |
| 138 | + --bundle \ |
| 139 | + --platform=node \ |
| 140 | + --target=node18 \ |
| 141 | + --format=esm \ |
| 142 | + --outfile=output/${PLATFORM}/bundle.js \ |
| 143 | + --external:ws \ |
| 144 | + --external:vscode-ws-jsonrpc \ |
| 145 | + --external:vscode-jsonrpc \ |
| 146 | + --external:dotenv |
| 147 | + |
| 148 | + # Download Node.js runtime |
| 149 | + NODE_PKG="node-${NODE_VERSION}-${NODE_ARCH}" |
| 150 | + NODE_URL="https://nodejs.org/dist/${NODE_VERSION}/${NODE_PKG}.tar.gz" |
| 151 | + curl -L "${NODE_URL}" -o /tmp/${NODE_PKG}.tar.gz |
| 152 | + tar -xzf /tmp/${NODE_PKG}.tar.gz -C /tmp/ |
| 153 | + mv /tmp/${NODE_PKG} output/${PLATFORM}/node |
| 154 | + |
| 155 | + # Strip unnecessary files from Node.js (no strip on macOS binaries) |
| 156 | + cd output/${PLATFORM}/node |
| 157 | + rm -rf lib/node_modules/npm lib/node_modules/corepack |
| 158 | + rm -f bin/npm bin/npx bin/corepack |
| 159 | + rm -rf share/doc share/man share/systemtap include |
| 160 | + rm -f README.md CHANGELOG.md LICENSE *.md |
| 161 | + cd ../../.. |
| 162 | + |
| 163 | + # Download Ruff for macOS |
| 164 | + echo "Downloading Ruff ${RUFF_VERSION} for darwin-${{ matrix.arch }}..." |
| 165 | + if [ "${{ matrix.arch }}" = "x64" ]; then |
| 166 | + RUFF_ARCH="x86_64" |
| 167 | + else |
| 168 | + RUFF_ARCH="aarch64" |
| 169 | + fi |
| 170 | + RUFF_URL="https://github.com/astral-sh/ruff/releases/download/${RUFF_VERSION}/ruff-${RUFF_ARCH}-apple-darwin.tar.gz" |
| 171 | + mkdir -p output/${PLATFORM}/bin |
| 172 | + curl -L -A "Mozilla/5.0" "${RUFF_URL}" -o /tmp/ruff.tar.gz |
| 173 | + tar -xzf /tmp/ruff.tar.gz -C /tmp/ |
| 174 | + cp /tmp/ruff-${RUFF_ARCH}-apple-darwin/ruff output/${PLATFORM}/bin/ruff |
| 175 | + chmod +x output/${PLATFORM}/bin/ruff |
| 176 | + |
| 177 | + # Install production dependencies |
| 178 | + cp package.json output/${PLATFORM}/ |
| 179 | + cd output/${PLATFORM} |
| 180 | + npm install --production --no-optional |
| 181 | + rm package-lock.json |
| 182 | + echo '{"type":"module"}' > package.json |
| 183 | + |
| 184 | + # Prune unnecessary files from node_modules |
| 185 | + find node_modules -type d -name "test" -exec rm -rf {} + 2>/dev/null || true |
| 186 | + find node_modules -type d -name "tests" -exec rm -rf {} + 2>/dev/null || true |
| 187 | + find node_modules -type d -name "docs" -exec rm -rf {} + 2>/dev/null || true |
| 188 | + find node_modules -type f -name "*.md" -delete 2>/dev/null || true |
| 189 | + find node_modules -type f -name "*.ts" ! -name "*.d.ts" -delete 2>/dev/null || true |
| 190 | + find node_modules -type f -name "*.map" -delete 2>/dev/null || true |
| 191 | + cd ../.. |
| 192 | + |
| 193 | + # Copy config template |
| 194 | + cp pyrightconfig.json output/${PLATFORM}/ |
| 195 | + |
| 196 | + # Create start script with RUFF_PATH |
| 197 | + cat > output/${PLATFORM}/start.sh << 'EOF' |
| 198 | + #!/bin/bash |
| 199 | + DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 200 | + export RUFF_PATH="${DIR}/bin/ruff" |
| 201 | + "${DIR}/node/bin/node" "${DIR}/bundle.js" "$@" |
| 202 | + EOF |
| 203 | + chmod +x output/${PLATFORM}/start.sh |
| 204 | + |
| 205 | + # Create compressed archive |
| 206 | + cd output |
| 207 | + tar -czf ${PLATFORM}.tar.gz ${PLATFORM}/ |
| 208 | + cd .. |
| 209 | + |
| 210 | + - name: Upload artifact |
| 211 | + uses: actions/upload-artifact@v4 |
| 212 | + with: |
| 213 | + name: darwin-${{ matrix.arch }} |
| 214 | + path: output/darwin-${{ matrix.arch }}.tar.gz |
| 215 | + |
| 216 | + release: |
| 217 | + name: Create GitHub Release |
| 218 | + runs-on: ubuntu-latest |
| 219 | + needs: [linux, macos] |
| 220 | + if: startsWith(github.ref, 'refs/tags/v') |
| 221 | + |
| 222 | + steps: |
| 223 | + - name: Download all artifacts |
| 224 | + uses: actions/download-artifact@v4 |
| 225 | + with: |
| 226 | + path: artifacts |
| 227 | + merge-multiple: true |
| 228 | + |
| 229 | + - name: Create Release |
| 230 | + uses: softprops/action-gh-release@v1 |
| 231 | + with: |
| 232 | + files: artifacts/* |
| 233 | + draft: false |
| 234 | + prerelease: false |
| 235 | + generate_release_notes: true |
| 236 | + body: | |
| 237 | + ## Pyright LSP Bridge with Ruff Formatting Support |
| 238 | + |
| 239 | + This release includes Ruff formatter bundled with the language server. |
| 240 | + |
| 241 | + ### Platform Support |
| 242 | + - ✅ Linux x64 with Ruff |
| 243 | + - ✅ macOS Intel (x64) with Ruff |
| 244 | + - ✅ macOS Apple Silicon (arm64) with Ruff |
| 245 | + |
| 246 | + ### Features |
| 247 | + - Python language server (Pyright) |
| 248 | + - Code formatting (Ruff) |
| 249 | + - Cross-platform support |
| 250 | + - Bundled Node.js runtime |
| 251 | + |
| 252 | + ### Installation |
| 253 | + |
| 254 | + **Linux:** |
| 255 | + ```bash |
| 256 | + tar -xzf linux-x64-with-ruff.tar.gz |
| 257 | + cd linux-x64 |
| 258 | + ./start.sh --port 9011 --bot-root /path/to/bot --jesse-root /path/to/jesse |
| 259 | + ``` |
| 260 | + |
| 261 | + **macOS:** |
| 262 | + ```bash |
| 263 | + tar -xzf darwin-arm64-with-ruff.tar.gz # or darwin-x64-with-ruff.tar.gz |
| 264 | + cd darwin-arm64 # or darwin-x64 |
| 265 | + ./start.sh --port 9011 --bot-root /path/to/bot --jesse-root /path/to/jesse |
| 266 | + ``` |
| 267 | + env: |
| 268 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 269 | + |
0 commit comments