Skip to content

Commit

Permalink
feat(tooling): move redhat packaging out to own step (#273 #837)
Browse files Browse the repository at this point in the history
* add patch-package so we can patch a node_modules package

* generate patch to disable build-id contents for RPM package

* move patch-package command to post-install script

* regenerate patch file
  • Loading branch information
shiftkey committed Aug 11, 2024
1 parent 112d7aa commit 7bf097d
Show file tree
Hide file tree
Showing 10 changed files with 288 additions and 42 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,13 @@
"electron-winstaller": "^5.0.0",
"eslint-plugin-github": "^4.10.1",
"markdownlint-cli": "^0.32.2",
"patch-package": "^6.5.1",
"postinstall-postinstall": "^2.1.0",
"reserved-words": "^0.1.2",
"tsconfig-paths": "^3.9.0"
},
"optionalDependencies": {
"electron-installer-debian": "3.2.0"
"electron-installer-debian": "3.2.0",
"electron-installer-redhat": "3.3.0"
}
}
10 changes: 10 additions & 0 deletions patches/electron-installer-redhat+3.3.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
diff --git a/node_modules/electron-installer-redhat/resources/spec.ejs b/node_modules/electron-installer-redhat/resources/spec.ejs
index 48f1dfd..360aec5 100644
--- a/node_modules/electron-installer-redhat/resources/spec.ejs
+++ b/node_modules/electron-installer-redhat/resources/spec.ejs
@@ -1,4 +1,5 @@
%define _binary_payload w<%= compressionLevel %>.xzdio
+%define _build_id_links none

Name: <%= name %>
Version: <%= version %>
10 changes: 1 addition & 9 deletions script/electron-builder-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,5 @@ linux:
# see https://github.com/shiftkey/desktop/issues/72 for more details
- x-scheme-handler/x-github-desktop-dev-auth
target:
- rpm
- AppImage
maintainer: 'GitHub, Inc <opensource+desktop@github.com>'
rpm:
depends:
# dugite-native dependencies
- libcurl
# keytar dependencies
- libsecret
- gnome-keyring
maintainer: 'Brendan Forster<github@brendanforster.com>'
17 changes: 2 additions & 15 deletions script/package-electron-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function packageElectronBuilder(): Promise<Array<string>> {

const appImageInstaller = `${distRoot}/GitHubDesktop-linux-*.AppImage`

let files = await globPromise(appImageInstaller)
const files = await globPromise(appImageInstaller)
if (files.length !== 1) {
return Promise.reject(
`Expected one AppImage installer but instead found '${files.join(
Expand All @@ -51,18 +51,5 @@ export async function packageElectronBuilder(): Promise<Array<string>> {

const appImageInstallerPath = files[0]

const rpmInstaller = `${distRoot}/GitHubDesktop-linux-*.rpm`

files = await globPromise(rpmInstaller)
if (files.length !== 1) {
return Promise.reject(
`Expected one RPM installer but instead found '${files.join(
', '
)}' - exiting...`
)
}

const rpmInstallerPath = files[0]

return Promise.resolve([appImageInstallerPath, rpmInstallerPath])
return Promise.resolve([appImageInstallerPath])
}
97 changes: 97 additions & 0 deletions script/package-redhat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { promisify } from 'util'
import { join } from 'path'

import glob = require('glob')
const globPromise = promisify(glob)

import { rename } from 'fs-extra'

import { getVersion } from '../app/package-info'
import { getDistPath, getDistRoot } from './dist-info'

const distRoot = getDistRoot()

// best guess based on documentation
type RedhatOptions = {
// required
src: string
dest: string
arch: 'x86_64'
// optional
description?: string
productDescription?: string
categories?: Array<string>
icon?: any
scripts?: {
pre?: string
post?: string
preun?: string
postun?: string
}
homepage?: string
mimeType?: Array<string>
requires?: Array<string>
}

const options: RedhatOptions = {
src: getDistPath(),
dest: distRoot,
arch: 'x86_64',
description: 'Simple collaboration from your desktop',
productDescription:
'This is the unofficial port of GitHub Desktop for Linux distributions',
categories: ['GNOME', 'GTK', 'Development'],
requires: [
// dugite-native dependencies
'(libcurl or libcurl4)',
// keytar dependencies
'libsecret',
'gnome-keyring',
],
icon: {
'256x256': 'app/static/logos/256x256.png',
'512x512': 'app/static/logos/512x512.png',
'1024x1024': 'app/static/logos/1024x1024.png',
},
scripts: {
post: 'script/resources/rpm/post.sh',
preun: 'script/resources/rpm/preun.sh',
},
homepage: 'https://github.com/shiftkey/desktop',
mimeType: [
'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',
],
}

export async function packageRedhat(): Promise<string> {
if (process.platform === 'win32') {
return Promise.reject('Windows is not supported')
}

const installer = require('electron-installer-redhat')

await installer(options)
const installersPath = `${distRoot}/github-desktop*.rpm`

const files = await globPromise(installersPath)

if (files.length !== 1) {
return Promise.reject(
`Expected one file but instead found '${files.join(', ')}' - exiting...`
)
}

const oldPath = files[0]

const newFileName = `GitHubDesktop-linux-${getVersion()}.rpm`
const newPath = join(distRoot, newFileName)
await rename(oldPath, newPath)

return Promise.resolve(newPath)
}
22 changes: 14 additions & 8 deletions script/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { assertNonNullable } from '../app/src/lib/fatal-error'

import { packageElectronBuilder } from './package-electron-builder'
import { packageDebian } from './package-debian'
import { packageRedhat } from './package-redhat'

const distPath = getDistPath()
const productName = getProductName()
Expand Down Expand Up @@ -217,16 +218,21 @@ async function packageLinux() {
console.log('Updating file mode for chrome-sandbox…')
await chmod(helperPath, 0o4755)
}
try {
const files = await packageElectronBuilder()
const debianPackage = await packageDebian()
const redhatPackage = await packageRedhat()

const files = await packageElectronBuilder()
const debianPackage = await packageDebian()
const installers = [...files, debianPackage, redhatPackage]

const installers = [...files, debianPackage]
console.log(`Installers created:`)
for (const installer of installers) {
console.log(` - ${installer}`)
}

console.log(`Installers created:`)
for (const installer of installers) {
console.log(` - ${installer}`)
generateChecksums(installers)
} catch (err) {
console.error('A problem occurred with the packaging step', err)
process.exit(1)
}

generateChecksums(installers)
}
8 changes: 8 additions & 0 deletions script/post-install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,12 @@ findYarnVersion(path => {
if (result.status !== 0) {
process.exit(result.status || 1)
}

if (process.platform === 'linux') {
result = spawnSync('node', getYarnArgs([path, 'patch-package']), options)

if (result.status !== 0) {
process.exit(result.status || 1)
}
}
})
12 changes: 12 additions & 0 deletions script/resources/rpm/post.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

INSTALL_DIR="/usr/lib/github-desktop"
CLI_DIR="$INSTALL_DIR/resources/app/static"

# add executable permissions for CLI interface
chmod +x "$CLI_DIR"/github || :

# create symbolic links to /usr/bin directory
ln -f -s "$CLI_DIR"/github /usr/bin || :

exit 0
8 changes: 8 additions & 0 deletions script/resources/rpm/preun.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

BASE_FILE="/usr/bin/github"

# remove symbolic links in /usr/bin directory
test -f ${BASE_FILE} && unlink ${BASE_FILE}

exit 0
Loading

0 comments on commit 7bf097d

Please sign in to comment.