|
| 1 | +name: Build and Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: ['v*'] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + linux: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + strategy: |
| 15 | + matrix: |
| 16 | + arch: [x64, arm64] |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - uses: actions/setup-node@v4 |
| 21 | + with: |
| 22 | + node-version: '20' |
| 23 | + |
| 24 | + - name: Install dependencies |
| 25 | + run: npm install |
| 26 | + |
| 27 | + - name: Build for linux-${{ matrix.arch }} |
| 28 | + run: | |
| 29 | + PLATFORM="linux-${{ matrix.arch }}" |
| 30 | + NODE_VERSION="v20.11.0" |
| 31 | + NODE_ARCH="linux-${{ matrix.arch }}" |
| 32 | + |
| 33 | + mkdir -p output/${PLATFORM} |
| 34 | + |
| 35 | + # Bundle TypeScript with esbuild |
| 36 | + npx esbuild index.ts \ |
| 37 | + --bundle \ |
| 38 | + --platform=node \ |
| 39 | + --target=node18 \ |
| 40 | + --format=esm \ |
| 41 | + --outfile=output/${PLATFORM}/bundle.js \ |
| 42 | + --external:ws \ |
| 43 | + --external:vscode-ws-jsonrpc \ |
| 44 | + --external:vscode-jsonrpc \ |
| 45 | + --external:dotenv |
| 46 | + |
| 47 | + # Download Node.js runtime |
| 48 | + NODE_PKG="node-${NODE_VERSION}-${NODE_ARCH}" |
| 49 | + NODE_URL="https://nodejs.org/dist/${NODE_VERSION}/${NODE_PKG}.tar.gz" |
| 50 | + curl -L "${NODE_URL}" -o /tmp/${NODE_PKG}.tar.gz |
| 51 | + tar -xzf /tmp/${NODE_PKG}.tar.gz -C /tmp/ |
| 52 | + mv /tmp/${NODE_PKG} output/${PLATFORM}/node |
| 53 | + |
| 54 | + # Strip unnecessary files from Node.js |
| 55 | + cd output/${PLATFORM}/node |
| 56 | + rm -rf lib/node_modules/npm lib/node_modules/corepack |
| 57 | + rm -f bin/npm bin/npx bin/corepack |
| 58 | + rm -rf share/doc share/man share/systemtap include |
| 59 | + rm -f README.md CHANGELOG.md LICENSE *.md |
| 60 | + if command -v strip &> /dev/null; then |
| 61 | + strip bin/node 2>/dev/null || true |
| 62 | + fi |
| 63 | + cd ../../.. |
| 64 | + |
| 65 | + # Install production dependencies |
| 66 | + cp package.json output/${PLATFORM}/ |
| 67 | + cd output/${PLATFORM} |
| 68 | + npm install --production --no-optional |
| 69 | + rm package.json package-lock.json |
| 70 | + |
| 71 | + # Prune unnecessary files from node_modules |
| 72 | + find node_modules -type d -name "test" -exec rm -rf {} + 2>/dev/null || true |
| 73 | + find node_modules -type d -name "tests" -exec rm -rf {} + 2>/dev/null || true |
| 74 | + find node_modules -type d -name "docs" -exec rm -rf {} + 2>/dev/null || true |
| 75 | + find node_modules -type d -name "examples" -exec rm -rf {} + 2>/dev/null || true |
| 76 | + find node_modules -type d -name "example" -exec rm -rf {} + 2>/dev/null || true |
| 77 | + find node_modules -type d -name ".github" -exec rm -rf {} + 2>/dev/null || true |
| 78 | + find node_modules -type d -name "coverage" -exec rm -rf {} + 2>/dev/null || true |
| 79 | + find node_modules -type d -name "benchmark" -exec rm -rf {} + 2>/dev/null || true |
| 80 | + find node_modules -type f -name "*.md" -delete 2>/dev/null || true |
| 81 | + find node_modules -type f -name "*.ts" ! -name "*.d.ts" -delete 2>/dev/null || true |
| 82 | + find node_modules -type f -name "*.map" -delete 2>/dev/null || true |
| 83 | + find node_modules -type f -name "LICENSE*" -delete 2>/dev/null || true |
| 84 | + find node_modules -type f -name "CHANGELOG*" -delete 2>/dev/null || true |
| 85 | + find node_modules -type f -name ".npmignore" -delete 2>/dev/null || true |
| 86 | + find node_modules -type f -name ".eslintrc*" -delete 2>/dev/null || true |
| 87 | + find node_modules -type f -name ".prettierrc*" -delete 2>/dev/null || true |
| 88 | + find node_modules -type f -name "tsconfig.json" -delete 2>/dev/null || true |
| 89 | + cd ../.. |
| 90 | + |
| 91 | + # Copy config template |
| 92 | + cp pyrightconfig.json output/${PLATFORM}/ |
| 93 | + |
| 94 | + # Create start script |
| 95 | + cat > output/${PLATFORM}/start.sh << 'EOF' |
| 96 | + #!/bin/bash |
| 97 | + DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 98 | + "${DIR}/node/bin/node" "${DIR}/bundle.js" "$@" |
| 99 | + EOF |
| 100 | + chmod +x output/${PLATFORM}/start.sh |
| 101 | + |
| 102 | + # Create compressed archive |
| 103 | + cd output |
| 104 | + tar -czf ${PLATFORM}.tar.gz ${PLATFORM}/ |
| 105 | + cd .. |
| 106 | + |
| 107 | + - name: Upload artifact |
| 108 | + uses: actions/upload-artifact@v4 |
| 109 | + with: |
| 110 | + name: linux-${{ matrix.arch }} |
| 111 | + path: output/linux-${{ matrix.arch }}.tar.gz |
| 112 | + |
| 113 | + macos: |
| 114 | + runs-on: macos-latest |
| 115 | + strategy: |
| 116 | + matrix: |
| 117 | + arch: [x64, arm64] |
| 118 | + steps: |
| 119 | + - uses: actions/checkout@v4 |
| 120 | + |
| 121 | + - uses: actions/setup-node@v4 |
| 122 | + with: |
| 123 | + node-version: '20' |
| 124 | + |
| 125 | + - name: Install dependencies |
| 126 | + run: npm install |
| 127 | + |
| 128 | + - name: Build for darwin-${{ matrix.arch }} |
| 129 | + run: | |
| 130 | + PLATFORM="darwin-${{ matrix.arch }}" |
| 131 | + NODE_VERSION="v20.11.0" |
| 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 |
| 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 | + if command -v strip &> /dev/null; then |
| 162 | + strip bin/node 2>/dev/null || true |
| 163 | + fi |
| 164 | + cd ../../.. |
| 165 | + |
| 166 | + # Install production dependencies |
| 167 | + cp package.json output/${PLATFORM}/ |
| 168 | + cd output/${PLATFORM} |
| 169 | + npm install --production --no-optional |
| 170 | + rm package.json package-lock.json |
| 171 | + |
| 172 | + # Prune unnecessary files from node_modules |
| 173 | + find node_modules -type d -name "test" -exec rm -rf {} + 2>/dev/null || true |
| 174 | + find node_modules -type d -name "tests" -exec rm -rf {} + 2>/dev/null || true |
| 175 | + find node_modules -type d -name "docs" -exec rm -rf {} + 2>/dev/null || true |
| 176 | + find node_modules -type d -name "examples" -exec rm -rf {} + 2>/dev/null || true |
| 177 | + find node_modules -type d -name "example" -exec rm -rf {} + 2>/dev/null || true |
| 178 | + find node_modules -type d -name ".github" -exec rm -rf {} + 2>/dev/null || true |
| 179 | + find node_modules -type d -name "coverage" -exec rm -rf {} + 2>/dev/null || true |
| 180 | + find node_modules -type d -name "benchmark" -exec rm -rf {} + 2>/dev/null || true |
| 181 | + find node_modules -type f -name "*.md" -delete 2>/dev/null || true |
| 182 | + find node_modules -type f -name "*.ts" ! -name "*.d.ts" -delete 2>/dev/null || true |
| 183 | + find node_modules -type f -name "*.map" -delete 2>/dev/null || true |
| 184 | + find node_modules -type f -name "LICENSE*" -delete 2>/dev/null || true |
| 185 | + find node_modules -type f -name "CHANGELOG*" -delete 2>/dev/null || true |
| 186 | + find node_modules -type f -name ".npmignore" -delete 2>/dev/null || true |
| 187 | + find node_modules -type f -name ".eslintrc*" -delete 2>/dev/null || true |
| 188 | + find node_modules -type f -name ".prettierrc*" -delete 2>/dev/null || true |
| 189 | + find node_modules -type f -name "tsconfig.json" -delete 2>/dev/null || true |
| 190 | + cd ../.. |
| 191 | + |
| 192 | + # Copy config template |
| 193 | + cp pyrightconfig.json output/${PLATFORM}/ |
| 194 | + |
| 195 | + # Create start script |
| 196 | + cat > output/${PLATFORM}/start.sh << 'EOF' |
| 197 | + #!/bin/bash |
| 198 | + DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 199 | + "${DIR}/node/bin/node" "${DIR}/bundle.js" "$@" |
| 200 | + EOF |
| 201 | + chmod +x output/${PLATFORM}/start.sh |
| 202 | + |
| 203 | + # Create compressed archive |
| 204 | + cd output |
| 205 | + tar -czf ${PLATFORM}.tar.gz ${PLATFORM}/ |
| 206 | + cd .. |
| 207 | + |
| 208 | + - name: Upload artifact |
| 209 | + uses: actions/upload-artifact@v4 |
| 210 | + with: |
| 211 | + name: darwin-${{ matrix.arch }} |
| 212 | + path: output/darwin-${{ matrix.arch }}.tar.gz |
| 213 | + |
| 214 | + windows: |
| 215 | + runs-on: windows-latest |
| 216 | + steps: |
| 217 | + - uses: actions/checkout@v4 |
| 218 | + |
| 219 | + - uses: actions/setup-node@v4 |
| 220 | + with: |
| 221 | + node-version: '20' |
| 222 | + |
| 223 | + - name: Install dependencies |
| 224 | + run: npm install |
| 225 | + |
| 226 | + - name: Build for win32-x64 |
| 227 | + shell: bash |
| 228 | + run: | |
| 229 | + PLATFORM="win32-x64" |
| 230 | + NODE_VERSION="v20.11.0" |
| 231 | + NODE_ARCH="win32-x64" |
| 232 | + |
| 233 | + mkdir -p output/${PLATFORM} |
| 234 | + |
| 235 | + # Bundle TypeScript with esbuild |
| 236 | + npx esbuild index.ts \ |
| 237 | + --bundle \ |
| 238 | + --platform=node \ |
| 239 | + --target=node18 \ |
| 240 | + --format=esm \ |
| 241 | + --outfile=output/${PLATFORM}/bundle.js \ |
| 242 | + --external:ws \ |
| 243 | + --external:vscode-ws-jsonrpc \ |
| 244 | + --external:vscode-jsonrpc \ |
| 245 | + --external:dotenv |
| 246 | + |
| 247 | + # Download Node.js runtime |
| 248 | + NODE_PKG="node-${NODE_VERSION}-${NODE_ARCH}" |
| 249 | + NODE_URL="https://nodejs.org/dist/${NODE_VERSION}/${NODE_PKG}.zip" |
| 250 | + curl -L "${NODE_URL}" -o /tmp/${NODE_PKG}.zip |
| 251 | + unzip -q /tmp/${NODE_PKG}.zip -d /tmp/ |
| 252 | + mv /tmp/${NODE_PKG} output/${PLATFORM}/node |
| 253 | + |
| 254 | + # Strip unnecessary files from Node.js |
| 255 | + cd output/${PLATFORM}/node |
| 256 | + rm -rf lib/node_modules/npm lib/node_modules/corepack node_modules/npm node_modules/corepack |
| 257 | + rm -f npm npm.cmd npx npx.cmd corepack corepack.cmd |
| 258 | + rm -f README.md CHANGELOG.md LICENSE *.md |
| 259 | + cd ../../.. |
| 260 | + |
| 261 | + # Install production dependencies |
| 262 | + cp package.json output/${PLATFORM}/ |
| 263 | + cd output/${PLATFORM} |
| 264 | + npm install --production --no-optional |
| 265 | + rm package.json package-lock.json |
| 266 | + |
| 267 | + # Prune unnecessary files from node_modules |
| 268 | + find node_modules -type d -name "test" -exec rm -rf {} + 2>/dev/null || true |
| 269 | + find node_modules -type d -name "tests" -exec rm -rf {} + 2>/dev/null || true |
| 270 | + find node_modules -type d -name "docs" -exec rm -rf {} + 2>/dev/null || true |
| 271 | + find node_modules -type d -name "examples" -exec rm -rf {} + 2>/dev/null || true |
| 272 | + find node_modules -type d -name "example" -exec rm -rf {} + 2>/dev/null || true |
| 273 | + find node_modules -type d -name ".github" -exec rm -rf {} + 2>/dev/null || true |
| 274 | + find node_modules -type d -name "coverage" -exec rm -rf {} + 2>/dev/null || true |
| 275 | + find node_modules -type d -name "benchmark" -exec rm -rf {} + 2>/dev/null || true |
| 276 | + find node_modules -type f -name "*.md" -delete 2>/dev/null || true |
| 277 | + find node_modules -type f -name "*.ts" ! -name "*.d.ts" -delete 2>/dev/null || true |
| 278 | + find node_modules -type f -name "*.map" -delete 2>/dev/null || true |
| 279 | + find node_modules -type f -name "LICENSE*" -delete 2>/dev/null || true |
| 280 | + find node_modules -type f -name "CHANGELOG*" -delete 2>/dev/null || true |
| 281 | + find node_modules -type f -name ".npmignore" -delete 2>/dev/null || true |
| 282 | + find node_modules -type f -name ".eslintrc*" -delete 2>/dev/null || true |
| 283 | + find node_modules -type f -name ".prettierrc*" -delete 2>/dev/null || true |
| 284 | + find node_modules -type f -name "tsconfig.json" -delete 2>/dev/null || true |
| 285 | + cd ../.. |
| 286 | + |
| 287 | + # Copy config template |
| 288 | + cp pyrightconfig.json output/${PLATFORM}/ |
| 289 | + |
| 290 | + # Create start script |
| 291 | + cat > output/${PLATFORM}/start.bat << 'EOF' |
| 292 | + @echo off |
| 293 | + set DIR=%~dp0 |
| 294 | + "%DIR%node\node.exe" "%DIR%bundle.js" %* |
| 295 | + EOF |
| 296 | + |
| 297 | + # Create compressed archive |
| 298 | + cd output |
| 299 | + powershell Compress-Archive -Path ${PLATFORM} -DestinationPath ${PLATFORM}.zip |
| 300 | + cd .. |
| 301 | + |
| 302 | + - name: Upload artifact |
| 303 | + uses: actions/upload-artifact@v4 |
| 304 | + with: |
| 305 | + name: win32-x64 |
| 306 | + path: output/win32-x64.zip |
| 307 | + |
| 308 | + release: |
| 309 | + name: Create GitHub Release |
| 310 | + runs-on: ubuntu-latest |
| 311 | + needs: [linux, macos, windows] |
| 312 | + if: startsWith(github.ref, 'refs/tags/v') |
| 313 | + |
| 314 | + steps: |
| 315 | + - name: Download all artifacts |
| 316 | + uses: actions/download-artifact@v4 |
| 317 | + with: |
| 318 | + path: artifacts |
| 319 | + merge-multiple: true |
| 320 | + |
| 321 | + - name: Create Release |
| 322 | + uses: softprops/action-gh-release@v1 |
| 323 | + with: |
| 324 | + files: artifacts/* |
| 325 | + draft: false |
| 326 | + prerelease: false |
| 327 | + generate_release_notes: true |
| 328 | + env: |
| 329 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 330 | + |
0 commit comments