From fcd7c0262c1e3ef6077c5ecb1b688a0acc125716 Mon Sep 17 00:00:00 2001 From: "yutian.yz" Date: Fri, 4 Mar 2022 10:03:09 +0800 Subject: [PATCH] feat: remove auto release --- .github/workflows/release.yml | 51 +++++----------------- scripts/rebuild-native.js | 79 ++++------------------------------- 2 files changed, 20 insertions(+), 110 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 06eca581..c27ddac8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,49 +3,23 @@ name: RELEASE on: push: tags: - - 'v*' + - "v*" workflow_dispatch: jobs: - windows-build: - runs-on: windows-latest + release: + name: Publish for ${{ matrix.os }} + runs-on: ${{ matrix.os }} strategy: matrix: node_version: [14.x] + include: + - os: windows-latest + TARGET_PLATFORMS: win32 - steps: - - uses: actions/checkout@v2 - - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - - name: Package Electron - run: | - npm i - npm run rebuild-native - npm run pack - env: - TARGET_PLATFORMS: win32 - - - - uses: 'marvinpinto/action-automatic-releases@latest' - with: - repo_token: '${{ secrets.GITHUB_TOKEN }}' - prerelease: true - files: | - LICENSE - out/*.dmg - out/*.exe - - macos-build: - runs-on: macos-latest - - strategy: - matrix: - node_version: [14.x] + - os: macos-latest + TARGET_PLATFORMS: darwin steps: - uses: actions/checkout@v2 @@ -60,13 +34,10 @@ jobs: npm i npm run rebuild-native npm run pack - env: - TARGET_PLATFORMS: darwin - - - uses: 'marvinpinto/action-automatic-releases@latest' + - uses: "marvinpinto/action-automatic-releases@latest" with: - repo_token: '${{ secrets.GITHUB_TOKEN }}' + repo_token: "${{ secrets.GITHUB_TOKEN }}" prerelease: true files: | LICENSE diff --git a/scripts/rebuild-native.js b/scripts/rebuild-native.js index 3a64d78b..8522b131 100644 --- a/scripts/rebuild-native.js +++ b/scripts/rebuild-native.js @@ -1,76 +1,15 @@ -const os = require('os'); -const { join } = require('path'); -const { execSync } = require('child_process'); -const { pathExistsSync, copySync, removeSync } = require('fs-extra'); +const path = require('path'); const argv = require('yargs').argv; +const electronRebuild = require('electron-rebuild'); -const nativeModules = [ - join(__dirname, '../node_modules/node-pty'), - join(__dirname, '../node_modules/nsfw'), - join(__dirname, '../node_modules/spdlog') -] +const electronVersion = argv.electronVersion || require('electron/package.json').version; -let commands; +console.log('rebuilding native for electron version ' + electronVersion); +const force = argv['force-rebuild'] === 'true'; +const buildPath = path.resolve(__dirname, '..'); -const target = argv.target || 'node'; -const arch = argv.arch || os.arch(); -let version; - -if (target === 'electron') { - - version = argv.electronVersion || require('electron/package.json').version; - - console.log('rebuilding native for electron version ' + version); - - commands = [ - `npm_config_arch=${arch}`, - `npm_config_target_arch=${arch}`, - os.platform() === 'win32' - ? 'set HOME=~/.electron-gyp' - : 'HOME=~/.electron-gyp', - - os.platform() === 'win32' - ? join(__dirname, '..\\node_modules\\.bin\\electron-rebuild.cmd') - : join(__dirname, '../node_modules/.bin/electron-rebuild'), - ]; - -} else if (target === 'node') { - - console.log('rebuilding native for node version ' + process.version); - - version = process.version; - - commands = ['node-gyp', 'rebuild'] - -} - -function rebuildModule(modulePath, type, version) { - const info = require(join(modulePath, './package.json')); - console.log('rebuilding ' + info.name) - const cache = getBuildCacheDir(modulePath, type, version, target); - if (pathExistsSync(cache) && !argv['force-rebuild']) { - console.log('cache found for ' + info.name) - copySync(cache, join(modulePath, 'build')); - } - else { - const command = commands.join(' '); - console.log(command); - execSync(command, { - cwd: modulePath, - HOME: target === 'electron' ? '~/.electron-gyp' : undefined - }); - removeSync(cache); - copySync(join(modulePath, 'build'), cache); - } - -} - -function getBuildCacheDir(modulePath, type, version, target) { - const info = require(join(modulePath, './package.json')); - return join(require('os').tmpdir(), 'ide_build_cache', target, info.name + '-' + info.version, type + '-' + version); +if (force) { + console.log('Force rebuild flag enabled.'); } - -nativeModules.forEach(path => { - rebuildModule(path, target, version); -}) +electronRebuild.rebuild({ buildPath, electronVersion, force })