Skip to content

Commit

Permalink
fix: update snapcraft requirements, fix ci
Browse files Browse the repository at this point in the history
  • Loading branch information
VerteDinde committed Mar 31, 2022
1 parent eb0998b commit d46342c
Show file tree
Hide file tree
Showing 14 changed files with 125 additions and 45 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ name: CI

on:
push:
branches:
- master
tags:
- v[0-9]+.[0-9]+.[0-9]+*
branches: [master]
tags: [v[0-9]+.[0-9]+.[0-9]+*]
pull_request:

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x, 14.x, 16.x]
node-version: [12.x, 14.x, 16.x]

steps:
- uses: actions/checkout@v2
Expand Down
41 changes: 34 additions & 7 deletions ci/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,48 @@
name: electron-app
name: electronApp
version: '1.0.0'
summary: App summary
description: |
App description
base: core18
base: core20
confinement: strict
grade: devel
confinement: devmode

apps:
electronApp:
extensions: [gnome-3-34]
plugs:
- alsa
- browser-support
- desktop
- desktop-legacy
- gsettings
- home
- network
- opengl
- pulseaudio
- unity7
- wayland
- x11
environment:
DISABLE_WAYLAND: "1"
TMPDIR: $XDG_RUNTIME_DIR

parts:
electron-deps:
plugin: nil
after:
- desktop-gtk3
electronApp:
source: .
plugin: dump
stage-packages:
- libnotify4
- libnss3
- libpcre3
- libuuid1
- libxss1
- libxtst6

electron-launch:
plugin: dump
source: .
override-build: |
snapcraftctl build
chmod +x bin/electron-launch
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
},
"dependencies": {
"@malept/cross-spawn-promise": "^1.0.0",
"debug": "^4.1.1",
"debug": "^4.3.4",
"electron-installer-common": "^0.10.2",
"fs-extra": "^9.0.0",
"js-yaml": "^3.10.0",
Expand Down
File renamed without changes.
7 changes: 4 additions & 3 deletions resources/snapcraft.yaml → resources/classic/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ apps:
TMPDIR: $XDG_RUNTIME_DIR

parts:
electronApp:
electron-deps:
source: .
plugin: dump
plugin: nil
stage-packages:
- libnotify4
- libnss3
- libpcre3
- libuuid1
- libxss1
- libxtst6
after:
- desktop-gtk2
- desktop-gtk3
3 changes: 3 additions & 0 deletions resources/desktop-launcher.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

exec "$@" --executed-from="$(pwd)" --pid=$$
44 changes: 44 additions & 0 deletions resources/strict/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: electronApp
version: '1.0.0'
summary: App summary
description: |
App description
base: core18
confinement: strict
grade: devel

apps:
electronApp:
extensions: [gnome-3-34]
plugs:
- browser-support
- desktop
- desktop-legacy
- gsettings
- home
- network
- unity7
- wayland
- x11
environment:
DISABLE_WAYLAND: "1"
TMPDIR: $XDG_RUNTIME_DIR

parts:
electronApp:
source: .
plugin: dump
stage-packages:
- libnotify4
- libnss3
- libpcre3
- libxss1
- libxtst6

electron-launch:
plugin: dump
source: .
override-build: |
snapcraftctl build
chmod +x bin/electron-launch
23 changes: 16 additions & 7 deletions src/launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,33 @@ limitations under the License.
const fs = require('fs-extra')
const path = require('path')

function getBrowserSandboxFlag (data) {
if (data.apps) {
const plugs = data.apps[`${data.name}`].plugs
return plugs.includes('browser-sandbox') ? '' : '--no-sandbox'
}
return ''
}

async function copyLauncher (snapDir, config) {
const binDir = path.join(snapDir, 'bin')
let launcherPath = path.resolve(__dirname, '..', 'resources', 'desktop-launcher.sh')
if (config.confinement === 'classic') {
const binDir = path.join(snapDir, 'bin')
const launcherPath = path.resolve(__dirname, '..', 'resources', 'classic-launcher.sh')
await fs.mkdirs(binDir)
await fs.copy(launcherPath, path.join(binDir, 'electron-launch'))
launcherPath = path.resolve(__dirname, '..', 'resources', 'classic', 'classic-launcher.sh')
}
await fs.mkdirs(binDir)
await fs.copy(launcherPath, path.join(binDir, 'electron-launch'))
}

function createDesktopLaunchCommand (data) {
const executableName = data.executableName || data.productName
const executableName = data.executableName || data.productName || data.name

delete data.executableName
delete data.productName

const launcher = data.confinement === 'classic' ? 'bin/electron-launch' : 'desktop-launch'
const sandboxFlag = getBrowserSandboxFlag(data)

return `${launcher} '$SNAP/${data.name}/${executableName}'`
return `bin/electron-launch $SNAP/${data.name}/${executableName} ${sandboxFlag}`
}

module.exports = {
Expand Down
5 changes: 5 additions & 0 deletions src/snapcraft.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ class Snapcraft {
args.push(`--${flag}`)
}
}
args.push('--destructive-mode')
/* istanbul ignore if */
if (debug.enabled) {
args.push('--debug')
}

if (extraArgs) {
Array.prototype.push.apply(args, extraArgs)
Expand Down
9 changes: 7 additions & 2 deletions src/yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ class SnapcraftYAML {
}

updateDependencies () {
this.parts.after[0] = common.getGTKDepends(this.electronVersion, DEPENDENCY_MAP)
this.parts['stage-packages'] = this.parts['stage-packages']
.concat(common.getATSPIDepends(this.electronVersion, DEPENDENCY_MAP))
.concat(common.getDRMDepends(this.electronVersion, DEPENDENCY_MAP))
Expand All @@ -210,6 +209,10 @@ class SnapcraftYAML {
.concat(common.getUUIDDepends(this.electronVersion, DEPENDENCY_MAP))
.concat(common.getXcbDri3Depends(this.electronVersion, DEPENDENCY_MAP))

if (this.data.confinement === 'classic') {
this.parts.after[0] = common.getGTKDepends(this.electronVersion, DEPENDENCY_MAP)
}

return this.data
}

Expand Down Expand Up @@ -255,7 +258,9 @@ class SnapcraftYAML {
}

module.exports = async function createYamlFromTemplate (snapDir, packageDir, userSupplied) {
const templateFilename = path.resolve(__dirname, '..', 'resources', 'snapcraft.yaml')
const templateFilename = (userSupplied.confinement && userSupplied.confinement === 'classic')
? path.resolve(__dirname, '..', 'resources', 'classic', 'snapcraft.yaml')
: path.resolve(__dirname, '..', 'resources', 'strict', 'snapcraft.yaml')
delete userSupplied.snapcraft

const yamlData = new SnapcraftYAML()
Expand Down
4 changes: 1 addition & 3 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ test('snap name has no letters', t => {
t.throws(() => creator.sanitizeName('0-9'), { message: /needs to have at least one letter/ })
})

// TODO: These are currently failing in CI, due to GH Actions not working with multipass.
// Configure this with a custom Docker image or LXD to get these working in CI again.
if (!process.env.FAST_TESTS_ONLY && !process.env.CI) {
if (!process.env.FAST_TESTS_ONLY) {
test.serial('creates a snap', async t => {
const snapPath = await snap({ src: path.join(__dirname, 'fixtures', 'app-with-asar') })
t.truthy(snapPath, 'snap returns a truthy value')
Expand Down
12 changes: 6 additions & 6 deletions test/launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@ require('./_util')

test('desktop-launch command uses productName by default', t => {
const command = launcher.createDesktopLaunchCommand({ name: 'app-name', productName: 'App Name' })
t.true(command.startsWith('desktop-launch'), 'Command uses desktop-launch')
t.true(command.endsWith("/App Name'"), 'Command uses exe-name')
t.true(command.startsWith('bin/electron-launch'), 'Command uses electron-launch')
t.true(command.includes('App Name'), 'Command uses productName')
})

test('desktop-launch command uses executableName if specified', t => {
const command = launcher.createDesktopLaunchCommand({ name: 'app-name', productName: 'App Name', executableName: 'exe-name' })
t.true(command.startsWith('desktop-launch'), 'Command uses desktop-launch')
t.true(command.endsWith("/exe-name'"), 'Command uses exe-name')
t.true(command.startsWith('bin/electron-launch'), 'Command uses electron-launch')
t.true(command.includes('exe-name'), 'Command uses exe-name')
})

test('launcher is classic launcher in classic confinement', t => {
const command = launcher.createDesktopLaunchCommand({ productName: 'App Name', confinement: 'classic' })
t.true(command.startsWith('bin/electron-launch'), 'Command uses electron-launch')
})

test('no custom launcher is copied to bin folder in non-classic confinement', async t => {
test('custom launcher is copied to bin folder in non-classic confinement', async t => {
await launcher.copyLauncher(t.context.tempDir.name, { confinement: 'strict' })
t.false(await fs.pathExists(path.join(t.context.tempDir.name, 'bin', 'electron-launch')), 'launcher does not exist')
t.true(await fs.pathExists(path.join(t.context.tempDir.name, 'bin', 'electron-launch')), 'launcher exists')
})

test('custom launcher is copied to bin folder in classic confinement', async t => {
Expand Down
2 changes: 1 addition & 1 deletion test/snapcraft.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ test('generateArgs flags and options', t => {
const snapcraft = new Snapcraft()
const args = snapcraft.generateArgs('nonexistent', { a: 1, b: null }, ['foo', 'bar'])

t.deepEqual(args, ['nonexistent', '--a=1', '--b', 'foo', 'bar'], 'generated args')
t.deepEqual(args, ['nonexistent', '--a=1', '--b', '--destructive-mode', 'foo', 'bar'], 'generated args')
})
10 changes: 0 additions & 10 deletions test/yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,6 @@ test('custom app config', async t => {
t.true(apps.electronAppName.daemon, 'daemon is set in app')
})

test('Electron < 2 apps use desktop-gtk2', async t => {
const { parts } = await createYaml(t, { name: 'electronAppName' }, '1.8.2')
t.deepEqual(parts.electronAppName.after, ['desktop-gtk2'])
})

test('Electron 2 apps use desktop-gtk3', async t => {
const { parts } = await createYaml(t, { name: 'electronAppName' }, '2.0.0-beta.1')
t.deepEqual(parts.electronAppName.after, ['desktop-gtk3'])
})

test('Electron < 4 apps require gconf', async t => {
const snapcraftYaml = await createYaml(t, { name: 'electronAppName' }, '1.8.2')
assertStagedPackage(t, snapcraftYaml, 'libgconf-2-4')
Expand Down

0 comments on commit d46342c

Please sign in to comment.