1
0

build-windows.mjs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env node
  2. /* eslint-disable @typescript-eslint/prefer-nullish-coalescing */
  3. import { build as builder } from 'electron-builder'
  4. import * as vars from './vars.mjs'
  5. import { execSync } from 'child_process'
  6. const isTag = (process.env.GITHUB_REF || process.env.BUILD_SOURCEBRANCH || '').startsWith('refs/tags/')
  7. const keypair = process.env.SM_KEYPAIR_ALIAS
  8. process.env.ARCH = process.env.ARCH || process.arch
  9. console.log('Signing enabled:', !!keypair)
  10. builder({
  11. dir: true,
  12. win: ['nsis', 'zip'],
  13. arm64: process.env.ARCH === 'arm64',
  14. config: {
  15. extraMetadata: {
  16. version: vars.version,
  17. },
  18. publish: process.env.KEYGEN_TOKEN ? [
  19. vars.keygenConfig,
  20. {
  21. provider: 'github',
  22. channel: `latest-${process.env.ARCH}`,
  23. },
  24. ] : undefined,
  25. forceCodeSigning: !!keypair,
  26. win: {
  27. signtoolOptions: {
  28. certificateSha1: process.env.SM_CODE_SIGNING_CERT_SHA1_HASH,
  29. publisherName: process.env.SM_PUBLISHER_NAME,
  30. signingHashAlgorithms: ['sha256'],
  31. sign: keypair ? async function (configuration) {
  32. console.log('Signing', configuration)
  33. if (configuration.path) {
  34. try {
  35. const cmd = `smctl sign --keypair-alias=${keypair} --input "${String(configuration.path)}"`
  36. console.log(cmd)
  37. const out = execSync(cmd)
  38. if (out.toString().includes('FAILED')) {
  39. throw new Error(out.toString())
  40. }
  41. console.log(out.toString())
  42. } catch (e) {
  43. console.error(`Failed to sign ${configuration.path}`)
  44. if (e.stdout) {
  45. console.error('stdout:', e.stdout.toString())
  46. }
  47. if (e.stderr) {
  48. console.error('stderr:', e.stderr.toString())
  49. }
  50. console.error(e)
  51. process.exit(1)
  52. }
  53. }
  54. } : undefined,
  55. },
  56. },
  57. },
  58. publish: (process.env.KEYGEN_TOKEN && isTag) ? 'always' : 'never',
  59. }).catch(e => {
  60. console.error(e)
  61. process.exit(1)
  62. })