1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Desktop: Seamless-Updates - rename latest-mac.yml to latest-mac-arm64.yml (#10985)

This commit is contained in:
Alice 2024-09-08 22:49:29 +03:00 committed by GitHub
parent 821cfc5bd8
commit 4da8060e62
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,12 +2,13 @@ const fs = require('fs');
const path = require('path'); const path = require('path');
const os = require('os'); const os = require('os');
const sha512 = require('js-sha512'); const sha512 = require('js-sha512');
const crypto = require('crypto');
const distDirName = 'dist'; const distDirName = 'dist';
const distPath = path.join(__dirname, distDirName); const distPath = path.join(__dirname, distDirName);
const generateChecksumFile = () => { const generateChecksumFile = () => {
if (os.platform() !== 'linux') { if (os.platform() !== 'linux') {
return []; // SHA-512 is only for AppImage return; // SHA-512 is only for AppImage
} }
let appImageName = ''; let appImageName = '';
@ -28,37 +29,91 @@ const generateChecksumFile = () => {
const sha512FileName = `${appImageName}.sha512`; const sha512FileName = `${appImageName}.sha512`;
const sha512FilePath = path.join(distPath, sha512FileName); const sha512FilePath = path.join(distPath, sha512FileName);
fs.writeFileSync(sha512FilePath, checksum); fs.writeFileSync(sha512FilePath, checksum);
return [sha512FilePath]; return sha512FilePath;
}; };
const renameLatestYmlFile = () => { const generateLatestArm64Yml = () => {
if (os.platform() === 'darwin' && process.arch === 'arm64') { if (os.platform() !== 'darwin' && process.arch !== 'arm64') {
// latest-mac.yml is only generated when publishing. return;
if (process.env.PUBLISH_ENABLED === 'false') { }
/* eslint-disable no-console */
console.info(`Publishing not enabled - skipping renaming latest-mac.yml file for arm64 architecture. process.env.PUBLISH_ENABLED = ${process.env.PUBLISH_ENABLED}`);
return;
}
/* eslint-disable no-console */ const calculateHash = (filePath) => {
console.info('Renaming latest-mac.yml file...'); const fileBuffer = fs.readFileSync(filePath);
const latestMacFilePath = path.join(distPath, 'latest-mac.yml'); const hashSum = crypto.createHash('sha512');
const renamedMacFilePath = path.join(distPath, 'latest-mac-arm64.yml'); hashSum.update(fileBuffer);
return hashSum.digest('base64');
};
if (fs.existsSync(latestMacFilePath)) { const getFileSize = (filePath) => {
/* eslint-disable no-console */ return fs.statSync(filePath).size;
console.info('Renamed latest-mac.yml file to latest-mac-arm64.yml succesfully!'); };
fs.renameSync(latestMacFilePath, renamedMacFilePath);
return [renamedMacFilePath]; const extractVersion = (filePath) => {
} else { return path.basename(filePath).split('-')[1];
throw new Error('latest-mac.yml not found!'); };
const files = fs.readdirSync(distPath);
let dmgPath = '';
let zipPath = '';
for (const file of files) {
if (file.endsWith('arm64.dmg')) {
const fileRenamed = `${file.slice(0, -4)}.DMG`; // renameReleaseAssets script will rename from .dmg to .DMG
dmgPath = path.join(distPath, fileRenamed);
} else if (file.endsWith('arm64.zip')) {
zipPath = path.join(distPath, file);
} }
} }
const versionFromFilePath = extractVersion(zipPath);
const info = {
version: versionFromFilePath,
dmgPath: dmgPath,
zipPath: zipPath,
releaseDate: new Date().toISOString(),
};
/* eslint-disable no-console */
if (!fs.existsSync(info.dmgPath) || !fs.existsSync(info.zipPath)) {
console.error('One or both executable files do not exist:', info.dmgPath, info.zipPath);
return;
}
console.info('Calculating hash of files...');
const dmgHash = calculateHash(info.dmgPath);
const zipHash = calculateHash(info.zipPath);
console.info('Calculating size of files...');
const dmgSize = getFileSize(info.dmgPath);
const zipSize = getFileSize(info.zipPath);
console.info('Generating content of latest-mac-arm64.yml file...');
const yamlFilePath = path.join(distPath, 'latest-mac-arm64.yml');
const yamlContent = `version: ${info.version}
files:
- url: ${path.basename(info.zipPath)}
sha512: ${zipHash}
size: ${zipSize}
- url: ${path.basename(info.dmgPath)}
sha512: ${dmgHash}
size: ${dmgSize}
path: ${path.basename(info.zipPath)}
sha512: ${zipHash}
releaseDate: '${info.releaseDate}'
`;
fs.writeFileSync(yamlFilePath, yamlContent);
console.log('YML file generated successfully for arm64 architecure.');
const fileContent = fs.readFileSync(yamlFilePath, 'utf8');
console.log('Generated YML Content:\n', fileContent);
/* eslint-enable no-console */
return yamlFilePath;
}; };
const mainHook = () => { const mainHook = () => {
generateChecksumFile(); const sha512FilePath = generateChecksumFile();
renameLatestYmlFile(); const lastestArm64YmlFilePath = generateLatestArm64Yml();
const outputFiles = [sha512FilePath, lastestArm64YmlFilePath].filter(item => item);
return outputFiles;
}; };
exports.default = mainHook; exports.default = mainHook;