Skip to content

Instantly share code, notes, and snippets.

@nwittwer
Last active May 19, 2021 07:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nwittwer/60aef18c9b4e9506534bdcc0e4a7c3f5 to your computer and use it in GitHub Desktop.
Save nwittwer/60aef18c9b4e9506534bdcc0e4a7c3f5 to your computer and use it in GitHub Desktop.
Electron-Nuxt: TravisCI + Electron-Builder -> Github Releases
language: node_js
node_js: "10"
os: osx
osx_image: xcode10.2
before_cache:
- rm -rf $HOME/.cache/electron-builder/wine
cache:
yarn: true
directories:
- node_modules
- $HOME/.cache/electron
- $HOME/.cache/electron-builder
jobs:
include:
- stage: Test
script:
- yarn test
- stage: Build Mac and Deploy to Github Release
script:
- yarn run build
before_cache:
- rm -rf $HOME/.cache/electron-builder/wine
branches:
except:
- "/^v\\d+\\.\\d+\\.\\d+$/"

Electron-Nuxt: TravisCI + Electron-Builder -> Github Releases

This guide will help you setup your config files and services, so that you can easily create Github Releases from TravisCI—using Electron-Nuxt.

NOTE: This guide only covers building for MacOS. But with some modifications to the Travis setup, you could probably get Windows and Linux builds too.

There's three environment variables you'll need, that this guide will explain:

  • CSC_LINK
  • (Optional) CSC_KEY_PASSWORD
  • GH_TOKEN

Export Xcode Certificate (.p12)

This will allow you to codesign your Mac application.

  1. Open Xcode > Accounts
  2. Manage Certificates...
  3. Find "Developer ID Application"
  4. Right-click, select "Export". This exports a .p12 file. NOTE: Remember if you set a password at this step.
  5. Choose destination
  6. Open Terminal,
  7. Run base64 path/to/the/p12/file
  8. Copy the all the encoded text

TravisCI: Codesign Mac

Now you need to set up the environment variables for codesigning your Mac application.

  1. Open the Settings menu for your repository
  2. Create a new Environment Variable called CSC_LINK, and paste your base64 encoded text into the value field
  3. (Optional—if you set a password) Create a new Environment Variable called CSC_KEY_PASSWORD, and paste your password into the value field

Github: Create token for Release access

  1. Create a Github token https://github.com/settings/tokens and copy the value

TravisCI: Configure Github

  1. Open the Settings menu for your repository
  2. Create a new Environment Variable called GH_TOKEN, and paste your Github token into the value field

Resources

https://www.electron.build/code-signing https://www.electron.build/configuration/publish https://studiolacosanostra.github.io/2019/03/26/Automate-electron-app-release-build-on-github-with-Travis-CI/

// I'm using this file with Electron-Nuxt https://github.com/michalzaq12/electron-nuxt
// But you might use a electron-builder.yml instead
const ICONS_DIR = 'build/icons/'
const windowsOS = {
win: {
icon: ICONS_DIR + 'icon.ico',
target: 'nsis'
},
nsis: {
differentialPackage: true
}
}
const linuxOS = {
linux: {
icon: ICONS_DIR,
target: 'deb'
}
}
const macOS = {
mac: {
target: 'dmg',
icon: ICONS_DIR + 'icon.icns',
publish: ['github']
},
dmg: {
contents: [{
x: 410,
y: 150,
type: 'link',
path: '/Applications'
},
{
x: 130,
y: 150,
type: 'file'
}
]
}
}
module.exports = {
asar: true,
productName: require('./package.json').productName,
appId: 'com.yourapp.app',
artifactName: 'yourapp-${version}.${ext}',
directories: {
output: 'build'
},
// default files: https://www.electron.build/configuration/contents
files: [
'package.json',
{
from: 'dist/main/',
to: 'dist/main/'
},
{
from: 'dist/renderer',
to: 'dist/renderer/'
}
],
...windowsOS,
...linuxOS,
...macOS
}
@benemohamed
Copy link

wow .... Thanks for this! 👍👍👍👍👍👍👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment