From 467718ed9b3c7c7785882ddda46c0c2d64d2a3bb Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Thu, 17 Jan 2019 16:52:39 -0400 Subject: [PATCH] adapt packaging script to build snap for classic enclosure --- package.json | 4 +- script/electron-builder-linux.yml | 39 +------------ script/package.ts | 96 +++++++++++++++++++++++++------ yarn.lock | 24 ++++++++ 4 files changed, 106 insertions(+), 57 deletions(-) diff --git a/package.json b/package.json index 9b4cf690339..31713183aff 100644 --- a/package.json +++ b/package.json @@ -119,7 +119,8 @@ "webpack-hot-middleware": "^2.22.2", "webpack-merge": "^4.1.2", "xml2js": "^0.4.16", - "xvfb-maybe": "^0.2.1" + "xvfb-maybe": "^0.2.1", + "yaml": "^1.4.0" }, "devDependencies": { "@types/byline": "^4.2.31", @@ -166,6 +167,7 @@ "@types/webpack-merge": "^4.1.3", "@types/winston": "^2.2.0", "@types/xml2js": "^0.4.0", + "@types/yaml": "^1.0.2", "electron": "5.0.6", "electron-builder": "20.39.0", "electron-packager": "^13.1.0", diff --git a/script/electron-builder-linux.yml b/script/electron-builder-linux.yml index 9d5718596e4..a638a0bb96d 100644 --- a/script/electron-builder-linux.yml +++ b/script/electron-builder-linux.yml @@ -38,48 +38,11 @@ rpm: # keytar dependencies - libsecret snap: - confinement: 'strict' + confinement: 'classic' stagePackages: - default - libcurl3 - openssh-client - gettext - plugs: - - browser-support - - desktop - - desktop-legacy - - gsettings - - home - - network - - opengl - - password-manager-service - - ssh-keys - - unity7 - - wayland - # additional plugs to pick up the GTK theme and icons from the system, mouse cursor theme still not fixed - - { - 'gtk-3-themes': - { - 'interface': 'content', - 'target': '$SNAP/data-dir/themes', - 'default-provider': 'gtk-common-themes:gtk-3-themes', - }, - } - - { - 'icon-themes': - { - 'interface': 'content', - 'target': '$SNAP/data-dir/icons', - 'default-provider': 'gtk-common-themes:icon-themes', - }, - } - - { - 'sound-themes': - { - 'interface': 'content', - 'target': '$SNAP/data-dir/sounds', - 'default-provider': 'gtk-common-themes:sounds-themes', - }, - } environment: DISABLE_WAYLAND: 1 diff --git a/script/package.ts b/script/package.ts index 297d45307a2..f14e785bb2b 100644 --- a/script/package.ts +++ b/script/package.ts @@ -6,8 +6,10 @@ import * as path from 'path' import * as crypto from 'crypto' import * as electronInstaller from 'electron-winstaller' import * as glob from 'glob' +import * as YAML from 'yaml' +const rimraf = require('rimraf') -import { getProductName, getCompanyName } from '../app/package-info' +import { getProductName, getCompanyName, getVersion } from '../app/package-info' import { getDistPath, getDistRoot, @@ -145,28 +147,55 @@ function getSha256Checksum(fullPath: string): Promise { }) } -function packageLinux() { - const electronBuilder = path.resolve( - __dirname, - '..', - 'node_modules', - '.bin', - 'electron-builder' +function throwIfError(command: string, args: string[]) { + const { error } = cp.spawnSync(command, args, { stdio: 'inherit' }) + + if (error != null) { + throw error + } +} + +function workaroundForSnapPackage() { + const distRoot = getDistRoot() + + const snapArchive = path.join( + distRoot, + `GitHubDesktop-linux-${getVersion()}.snap` ) + const snapFileSystem = path.join(distRoot, 'unsquashfs-root') + + throwIfError('unsquashfs', [ + '-dest', + snapFileSystem, + '-no-progress', + snapArchive, + ]) + + const snapMetaYaml = path.join(snapFileSystem, 'meta', 'snap.yaml') + + const yamlText = fs.readFileSync(snapMetaYaml, 'utf8') + const yaml = YAML.parse(yamlText) + + // regenerate the YAML without whatever electron-builder has included for the plugs + // element, because a package using the strict enclosure should not define this + const yamlWithoutPlugs = { + ...yaml, + apps: { + 'github-desktop': { + command: 'command.sh', + }, + }, + } - const configPath = path.resolve(__dirname, 'electron-builder-linux.yml') + const newYaml = YAML.stringify(yamlWithoutPlugs) + fs.writeFileSync(snapMetaYaml, newYaml, 'utf8') - const args = [ - 'build', - '--prepackaged', - distPath, - '--x64', - '--config', - configPath, - ] + throwIfError('snapcraft', ['pack', snapFileSystem, '--output', snapArchive]) - cp.spawnSync(electronBuilder, args, { stdio: 'inherit' }) + rimraf.sync(snapFileSystem) +} +function generateChecksums() { const distRoot = getDistRoot() const installersPath = `${distRoot}/GitHubDesktop-linux-*` @@ -195,3 +224,34 @@ function packageLinux() { fs.writeFile(checksumFile, checksumsText) }) } + +function packageLinux() { + const electronBuilder = path.resolve( + __dirname, + '..', + 'node_modules', + '.bin', + 'electron-builder' + ) + + const configPath = path.resolve(__dirname, 'electron-builder-linux.yml') + + const args = [ + 'build', + '--prepackaged', + distPath, + '--x64', + '--config', + configPath, + ] + + const { error } = cp.spawnSync(electronBuilder, args, { stdio: 'inherit' }) + + if (error != null) { + throw error + } + + workaroundForSnapPackage() + + generateChecksums() +} diff --git a/yarn.lock b/yarn.lock index f44581580f0..15c168b2451 100644 --- a/yarn.lock +++ b/yarn.lock @@ -78,6 +78,13 @@ resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.0.0-beta.51.tgz#27cec2df409df60af58270ed8f6aa55409ea86f6" integrity sha1-J87C30Cd9gr1gnDtj2qlVAnqhvY= +"@babel/runtime@^7.3.4": + version "7.4.2" + resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.4.2.tgz#f5ab6897320f16decd855eed70b705908a313fe8" + integrity sha512-7Bl2rALb7HpvXFL7TETNzKSAeBVCPHELzc0C//9FCxN8nsiueWSJBqaF+2oIJScyILStASR/Cx5WMkXGYTiJFA== + dependencies: + regenerator-runtime "^0.13.2" + "@babel/template@7.0.0-beta.51": version "7.0.0-beta.51" resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.0.0-beta.51.tgz#9602a40aebcf357ae9677e2532ef5fc810f5fbff" @@ -602,6 +609,11 @@ dependencies: "@types/node" "*" +"@types/yaml@^1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@types/yaml/-/yaml-1.0.2.tgz#bba080d64714c6ef3eaa023e235dacd2cfa3c938" + integrity sha512-rS1VJFjyGKNHk8H97COnPIK+oeLnc0J9G0ES63o/Ky+WlJCeaFGiGCTGhV/GEVKua7ZWIV1JIDopYUwrfvTo7A== + "@types/yargs@^12.0.9": version "12.0.12" resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-12.0.12.tgz#45dd1d0638e8c8f153e87d296907659296873916" @@ -8431,6 +8443,11 @@ regenerator-runtime@^0.11.0: resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.0.tgz#7e54fe5b5ccd5d6624ea6255c3473be090b802e1" integrity sha512-/aA0kLeRb5N9K0d4fw7ooEbI+xDe+DKD499EQqygGqeS8N3xto15p09uY2xj7ixP81sNPXvRLnAQIqdVStgb1A== +regenerator-runtime@^0.13.2: + version "0.13.2" + resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.2.tgz#32e59c9a6fb9b1a4aff09b4930ca2d4477343447" + integrity sha512-S/TQAZJO+D3m9xeN1WTI8dLKBBiRgXBlTJvbWjCThHWZj9EvHK70Ff50/tYj2J/fvBY6JtFVwRuazHN2E7M9BA== + regex-cache@^0.4.2: version "0.4.4" resolved "https://registry.yarnpkg.com/regex-cache/-/regex-cache-0.4.4.tgz#75bdc58a2a1496cec48a12835bc54c8d562336dd" @@ -10786,6 +10803,13 @@ yallist@^3.0.0, yallist@^3.0.2: resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.0.2.tgz#8452b4bb7e83c7c188d8041c1a837c773d6d8bb9" integrity sha1-hFK0u36Dx8GI2AQcGoN8dz1ti7k= +yaml@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.4.0.tgz#b729a3ef7e35bdc5ece8f28900e20a9b41510fc3" + integrity sha512-rzU83hGJrNgyT7OE2mP/SILeZxEMRJ0mza0n4KFtkNL1aXUZ79ZgZ5pIH56yT6LiqujcAs/Rqzp0ApvvNYfUfw== + dependencies: + "@babel/runtime" "^7.3.4" + yargs-parser@^13.0.0: version "13.0.0" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-13.0.0.tgz#3fc44f3e76a8bdb1cc3602e860108602e5ccde8b"