|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const TEST_BUILD = true; // set true if you would like to test on your local machince |
| 4 | + |
| 5 | +if (!process.env.CI && !TEST_BUILD) { |
| 6 | + console.error('Create release only on CI server') |
| 7 | + process.exit(1) |
| 8 | +} |
| 9 | + |
| 10 | +let branchName = '' |
| 11 | +let pullRequestNr = '' |
| 12 | +let gitTag = '' |
| 13 | +let repoName = '' |
| 14 | + |
| 15 | +if (process.env.TRAVIS) { |
| 16 | + branchName = process.env.TRAVIS_BRANCH |
| 17 | + pullRequestNr = process.env.TRAVIS_PULL_REQUEST |
| 18 | + gitTag = process.env.TRAVIS_TAG |
| 19 | + repoName = process.env.TRAVIS_REPO_SLUG |
| 20 | +} else if (process.env.APPVEYOR) { |
| 21 | + branchName = process.env.APPVEYOR_REPO_BRANCH |
| 22 | + pullRequestNr = process.env.APPVEYOR_PULL_REQUEST_NUMBER |
| 23 | + gitTag = process.env.APPVEYOR_REPO_TAG_NAME |
| 24 | + repoName = process.env.APPVEYOR_REPO_NAME |
| 25 | +} |
| 26 | + |
| 27 | +console.log({ branchName, pullRequestNr, gitTag, repoName }) |
| 28 | + |
| 29 | +// TODO(Robi): Remove the comment after success tests |
| 30 | +const isReleaseCommit = TEST_BUILD || branchName === gitTag //&& repoName === 'ert78gb/electron-playground' |
| 31 | + |
| 32 | +if (!isReleaseCommit) { |
| 33 | + console.log('It is not a release task. Skipping publish.') |
| 34 | + process.exit(0) |
| 35 | +} |
| 36 | + |
| 37 | + |
| 38 | +const fs = require('fs-extra') |
| 39 | +const cp = require('child_process') |
| 40 | +const path = require('path') |
| 41 | +const builder = require("electron-builder") |
| 42 | +const Platform = builder.Platform |
| 43 | + |
| 44 | +let sha = '' |
| 45 | +if (process.env.TRAVIS) { |
| 46 | + sha = process.env.TRAVIS_COMMIT |
| 47 | +} else if (process.env.APPVEYOR) { |
| 48 | + sha = process.env.APPVEYOR_REPO_COMMIT |
| 49 | +} |
| 50 | + |
| 51 | +let target = '' |
| 52 | + |
| 53 | +if (process.platform === 'darwin') { |
| 54 | + target = Platform.MAC.createTarget() |
| 55 | +} else if (process.platform === 'win32') { |
| 56 | + target = Platform.WINDOWS.createTarget() |
| 57 | +} else if (process.platform === 'linux') { |
| 58 | + target = Platform.LINUX.createTarget() |
| 59 | +} else { |
| 60 | + console.error(`I dunno how to publish a release for ${process.platform} :(`) |
| 61 | + process.exit(1) |
| 62 | +} |
| 63 | + |
| 64 | +if (process.platform === 'darwin') { |
| 65 | + // TODO: Remove comment when macOS certificates boughted and exported |
| 66 | + //require('./setup-macos-keychain').registerKeyChain() |
| 67 | +} |
| 68 | + |
| 69 | +let version = '' |
| 70 | +if (TEST_BUILD || gitTag) { |
| 71 | + version = gitTag |
| 72 | + |
| 73 | + builder.build({ |
| 74 | + dir: true, |
| 75 | + targets: target, |
| 76 | + appMetadata: { |
| 77 | + main: 'electron/dist/electron-main.js', |
| 78 | + name: 'UHK Agent', |
| 79 | + author: { |
| 80 | + name: 'Ultimate Gaget Laboratories' |
| 81 | + }, |
| 82 | + }, |
| 83 | + config: { |
| 84 | + appId: 'com.ultimategadgetlabs.uhk.agent', |
| 85 | + productName: 'UHK Agent', |
| 86 | + mac: { |
| 87 | + category: 'public.app-category.utilities', |
| 88 | + }, |
| 89 | + publish: 'github', |
| 90 | + files: [ |
| 91 | + '!**/*', |
| 92 | + 'electron/dist/**/*', |
| 93 | + 'node_modules/**/*' |
| 94 | + ] |
| 95 | + |
| 96 | + }, |
| 97 | + }) |
| 98 | + .then(() => { |
| 99 | + console.log('Packing success.') |
| 100 | + }) |
| 101 | + .catch((error) => { |
| 102 | + console.error(`${error}`) |
| 103 | + process.exit(1) |
| 104 | + }) |
| 105 | +} |
| 106 | +else { |
| 107 | + console.log('No git tag') |
| 108 | + // TODO: Need it? |
| 109 | + version = sha.substr(0, 8) |
| 110 | + process.exit(1) |
| 111 | +} |
0 commit comments