Various build and developer fixes, some optimizations (#2975)

* Various build and developer fixes, some optimizations

* Fix the linux build

* Fix afterpack

* Fix notarization variables

* Revert macos-notification-state changes from this PR

* Only build the tar for PRs

* Also ci

* Fix copy script

* Fix copy script more

* Remove @babel/cli

* Fix windows build

* Fix MAS build
This commit is contained in:
Devin Binnie
2024-03-12 10:04:11 -04:00
committed by GitHub
parent e5efa727fe
commit e56b5cdd6a
36 changed files with 921 additions and 3761 deletions

View File

@@ -1,20 +1,20 @@
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
const {spawnSync} = require('child_process');
const path = require('path');
const {flipFuses, FuseVersion, FuseV1Options} = require('@electron/fuses');
const {spawn} = require('@electron/notarize/lib/spawn.js');
const SETUID_PERMISSIONS = '4755';
function fixSetuid(context) {
return async (target) => {
if (!['appimage', 'snap'].includes(target.name.toLowerCase())) {
const result = await spawn('chmod', [SETUID_PERMISSIONS, path.join(context.appOutDir, 'chrome-sandbox')]);
if (result.code !== 0) {
const result = await spawnSync('chmod', [SETUID_PERMISSIONS, path.join(context.appOutDir, 'chrome-sandbox')]);
if (result.error) {
throw new Error(
`Failed to set proper permissions for linux arch on ${target.name}`,
`Failed to set proper permissions for linux arch on ${target.name}: ${result.error} ${result.stderr} ${result.stdout}`,
);
}
}

View File

@@ -1,7 +1,7 @@
// Copyright (c) 2015-2016 Yuya Ochiai
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
const buildConfig = require('../dist/buildConfig');
const buildConfig = require('../dist/common/config/buildConfig').default;
function validateBuildConfig(config) {
if (config.enableServerManagement === false && config.defaultServers && config.defaultServers.length === 0) {

View File

@@ -80,19 +80,39 @@ fi
if [[ -f "${SRC}"/mattermost-desktop-${VERSION}-linux-x64.tar.gz ]]; then
echo -e "Copying linux\n"
cp "${SRC}"/mattermost-desktop-*-linux-x64* "${DEST}/"
cp "${SRC}"/mattermost-desktop-*-linux-x86_64* "${DEST}/"
cp "${SRC}"/mattermost-desktop_"${VERSION}"-1_amd64*.deb "${DEST}/"
SOMETHING_COPIED=$((SOMETHING_COPIED + 10))
fi
if [[ -f "${SRC}"/mattermost-desktop-${VERSION}-linux-arm64.tar.gz ]]; then
echo -e "Copying linux\n"
cp "${SRC}"/mattermost-desktop-*-linux-arm64* "${DEST}/"
cp "${SRC}"/mattermost-desktop-*-linux-aarch64* "${DEST}/"
cp "${SRC}"/mattermost-desktop_"${VERSION}"-1_arm64*.deb "${DEST}/"
SOMETHING_COPIED=$((SOMETHING_COPIED + 11))
fi
if [[ -f "${SRC}"/mattermost-desktop-*-linux-x86_64* ]]; then
echo -e "Copying linux-rpm\n"
cp "${SRC}"/mattermost-desktop-*-linux-x86_64* "${DEST}/"
SOMETHING_COPIED=$((SOMETHING_COPIED + 12))
fi
if [[ -f "${SRC}"/mattermost-desktop-*-linux-aarch64* ]]; then
echo -e "Copying linux-rpm\n"
cp "${SRC}"/mattermost-desktop-*-linux-aarch64* "${DEST}/"
SOMETHING_COPIED=$((SOMETHING_COPIED + 13))
fi
if [[ -f "${SRC}"/mattermost-desktop_${VERSION}-1_amd64*.deb ]]; then
echo -e "Copying linux-deb\n"
cp "${SRC}"/mattermost-desktop_"${VERSION}"-1_amd64*.deb "${DEST}/"
SOMETHING_COPIED=$((SOMETHING_COPIED + 14))
fi
if [[ -f "${SRC}"/mattermost-desktop_${VERSION}-1_arm64*.deb ]]; then
echo -e "Copying linux-deb\n"
cp "${SRC}"/mattermost-desktop_"${VERSION}"-1_arm64*.deb "${DEST}/"
SOMETHING_COPIED=$((SOMETHING_COPIED + 15))
fi
if [[ $SOMETHING_COPIED -eq 0 ]]; then
echo "Didn't find anything to copy, it seems like something failed"
# Bash only returns 0-255 values

View File

@@ -4,19 +4,6 @@
const fs = require('fs');
const path = require('path');
const jq = require('node-jq');
// Patch the macos-notification-state library so we can build correctly
jq.run(
'.scripts.install = "node-gyp rebuild"',
'./node_modules/macos-notification-state/package.json',
).then((result) => {
fs.writeFileSync(
'./node_modules/macos-notification-state/package.json',
result,
);
});
// For linux dev, drop a desktop shortcut so deep linking works correctly
if (process.platform === 'linux') {
const xdgDir = path.resolve(process.env.HOME, '.local/share/applications');

View File

@@ -1,32 +0,0 @@
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
// inspired by https://kilianvalkhof.com/2019/electron/notarizing-your-electron-application/
require('dotenv').config();
const {notarize} = require('@electron/notarize');
const config = require('../electron-builder.json');
exports.default = async function notarizing(context) {
const {electronPlatformName, appOutDir} = context;
if (electronPlatformName !== 'darwin' || process.platform !== 'darwin') {
return;
}
const appName = context.packager.appInfo.productFilename;
if (typeof process.env.APPLEID === 'undefined') {
console.log('skipping notarization, remember to setup environment variables for APPLEID and APPLEIDPASS if you want to notarize');
return;
}
await notarize({
// should we change it to appBundleId: 'com.mattermost.desktop',
appBundleId: config.appId,
appPath: `${appOutDir}/${appName}.app`,
appleId: process.env.APPLEID,
appleIdPassword: process.env.APPLEIDPASS,
teamId: 'UQ8HT4Q2XM',
tool: 'notarytool',
});
};

View File

@@ -1,59 +0,0 @@
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
const {spawn, exec} = require('child_process');
const axios = require('axios');
const mmctlPath = process.env.MMCTL_PATH || 'mmctl';
const ping = setInterval(async () => {
try {
const pingRequest = await axios.get('http://localhost:8065/api/v4/system/ping');
if (pingRequest.status === 200) {
const addUserRequest = await axios.post(
'http://localhost:8065/api/v4/users',
{
email: 'test@test.com',
username: 'admin1',
password: 'Sys@dmin123',
allow_marketing: false,
});
if (addUserRequest.status === 201) {
clearInterval(ping);
exec('echo "Sys@dmin123" > passfile', () => {
const mmctlauth = spawn(mmctlPath, ['auth', 'login', 'http://localhost:8065', '--name', 'local-server', '--username', 'admin1', '--password-file', 'passfile']);
mmctlauth.stdout.on('data', (data) => {
console.log(`${data}`);
});
mmctlauth.stderr.on('data', (data) => {
console.log(`ERROR: ${data}`);
});
mmctlauth.on('close', () => {
const sampledata = spawn(mmctlPath, ['sampledata']);
sampledata.stdout.on('data', (data) => {
console.log(`${data}`);
});
sampledata.stderr.on('data', (data) => {
console.log(`ERROR: ${data}`);
});
sampledata.on('close', () => {
exec(`${mmctlPath} config set AnnouncementSettings.UserNoticesEnabled false`, (err, stdout, stderr) => {
console.log(err, stdout, stderr);
});
});
});
});
}
} else {
console.log(`ERROR: Trying to contact server, got ${pingRequest.status}`);
}
} catch {
console.log('waiting for server to respond...');
}
}, 1000);

26
scripts/watch.js Normal file
View File

@@ -0,0 +1,26 @@
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
const electron = require('electron-connect').server.create({path: 'dist/'});
const webpack = require('webpack');
const mainConfig = require('../webpack.config.main.js');
const preloadConfig = require('../webpack.config.preload.js');
const rendererConfig = require('../webpack.config.renderer.js');
Promise.all([mainConfig, preloadConfig, rendererConfig].map((config) => {
return new Promise((resolve) => {
const compiler = webpack(config);
compiler.watch({}, (err, stats) => {
if (err) {
console.error(err);
}
process.stdout.write(stats.toString({colors: true}));
process.stdout.write('\n');
if (!stats.hasErrors()) {
electron.restart();
}
resolve();
});
});
})).then(() => electron.start());

View File

@@ -1,34 +0,0 @@
// Copyright (c) 2015-2016 Yuya Ochiai
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
const electron = require('electron-connect').server.create({path: 'dist/'});
const webpack = require('webpack');
const mainConfig = require('../webpack.config.main.js');
const rendererConfig = require('../webpack.config.renderer.js');
let started = false;
const mainCompiler = webpack(mainConfig);
mainCompiler.watch({}, (err, stats) => {
if (err) {
console.error(err);
}
process.stdout.write(stats.toString({colors: true}));
process.stdout.write('\n');
if (!stats.hasErrors()) {
if (started) {
electron.restart();
} else {
electron.start();
started = true;
}
}
});
const preloadCompiler = webpack(rendererConfig);
preloadCompiler.watch({}, (err) => {
if (err) {
console.log(err);
}
});