Skip to content

Commit

Permalink
add electron-builder config to repository (#254 #496)
Browse files Browse the repository at this point in the history
  • Loading branch information
shiftkey committed Aug 11, 2024
1 parent a6a8cb7 commit 3aa1b91
Show file tree
Hide file tree
Showing 6 changed files with 756 additions and 37 deletions.
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "desktop",
"name": "github-desktop",
"productName": "GitHub Desktop",
"bundleID": "com.github.GitHubClient",
"companyName": "GitHub, Inc.",
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@
"webpack-dev-middleware": "^5.3.4",
"webpack-hot-middleware": "^2.25.1",
"webpack-merge": "^5.8.0",
"xml2js": "^0.5.0"
"xml2js": "^0.5.0",
"xvfb-maybe": "^0.2.1",
"yaml": "^1.4.0"
},
"devDependencies": {
"@github/markdownlint-github": "^0.1.0",
Expand Down Expand Up @@ -157,6 +159,7 @@
"@types/webpack-merge": "^5.0.0",
"@types/xml2js": "^0.4.11",
"electron": "30.0.8",
"electron-builder": "^24.13.3",
"electron-packager": "^17.1.1",
"electron-winstaller": "^5.0.0",
"eslint-plugin-github": "^4.10.1",
Expand Down
2 changes: 1 addition & 1 deletion script/dist-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function getExecutableName() {
if (process.platform === 'win32') {
return `${getWindowsIdentifierName()}${suffix}`
} else if (process.platform === 'linux') {
return 'desktop'
return `github-desktop${suffix}`
} else {
return productName
}
Expand Down
40 changes: 40 additions & 0 deletions script/electron-builder-linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
artifactName: 'GitHubDesktop-${os}-${version}.${ext}'
linux:
category: 'GNOME;GTK;Development'
packageCategory: 'GNOME;GTK;Development'
icon: 'app/static/logos'
mimeTypes:
- x-scheme-handler/x-github-client
- x-scheme-handler/x-github-desktop-auth
# workaround for handling OAuth flow until we figure out what we're doing
# With the development OAuth details
# see https://github.com/shiftkey/desktop/issues/72 for more details
- x-scheme-handler/x-github-desktop-dev-auth
target:
- deb
- rpm
- AppImage
maintainer: 'GitHub, Inc <opensource+desktop@github.com>'
deb:
afterInstall: './script/linux-after-install.sh'
afterRemove: './script/linux-after-remove.sh'
depends:
# default Electron dependencies
- gconf2
- gconf-service
- libnotify4
- libappindicator1
- libxtst6
- libnss3
# dugite-native dependencies
- libcurl3 | libcurl4
# keytar dependencies
- libsecret-1-0
- gnome-keyring
rpm:
depends:
# dugite-native dependencies
- libcurl
# keytar dependencies
- libsecret
- gnome-keyring
95 changes: 95 additions & 0 deletions script/package.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
/* eslint-disable no-sync */

import * as cp from 'child_process'
import { chmodSync, createReadStream } from 'fs'
import { writeFile } from 'fs/promises'
import * as path from 'path'
import * as electronInstaller from 'electron-winstaller'
import * as crypto from 'crypto'

import glob = require('glob')

import { getProductName, getCompanyName } from '../app/package-info'
import {
getDistPath,
Expand All @@ -24,6 +30,7 @@ import { getVersion } from '../app/package-info'
import { rename } from 'fs/promises'
import { join } from 'path'
import { assertNonNullable } from '../app/src/lib/fatal-error'
import { pathExistsSync } from 'fs-extra'

const distPath = getDistPath()
const productName = getProductName()
Expand All @@ -39,6 +46,8 @@ if (process.platform === 'darwin') {
packageOSX()
} else if (process.platform === 'win32') {
packageWindows()
} else if (process.platform === 'linux') {
packageLinux()
} else {
console.error(`I don't know how to package for ${process.platform} :(`)
process.exit(1)
Expand Down Expand Up @@ -157,3 +166,89 @@ function packageWindows() {
process.exit(1)
})
}

function getSha256Checksum(fullPath: string): Promise<string> {
return new Promise<string>((resolve, reject) => {
const algo = 'sha256'
const shasum = crypto.createHash(algo)

const s = createReadStream(fullPath)
s.on('data', function (d) {
shasum.update(d)
})
s.on('error', err => {
reject(err)
})
s.on('end', function () {
const d = shasum.digest('hex')
resolve(d)
})
})
}

function generateChecksums() {
const distRoot = getDistRoot()

const installersPath = `${distRoot}/GitHubDesktop-linux-*`

glob(installersPath, async (error, files) => {
if (error != null) {
throw error
}

const checksums = new Map<string, string>()

for (const f of files) {
const checksum = await getSha256Checksum(f)
checksums.set(f, checksum)
}

let checksumsText = `Checksums: \n`

for (const [fullPath, checksum] of checksums) {
const fileName = path.basename(fullPath)
checksumsText += `${checksum} - ${fileName}\n`
}

const checksumFile = path.join(distRoot, 'checksums.txt')

await writeFile(checksumFile, checksumsText)
})
}

function packageLinux() {
const helperPath = path.join(getDistPath(), 'chrome-sandbox')
const exists = pathExistsSync(helperPath)

if (exists) {
console.log('Updating file mode for chrome-sandbox…')
chmodSync(helperPath, 0o4755)
}

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
}

generateChecksums()
}
Loading

0 comments on commit 3aa1b91

Please sign in to comment.