IDE updater bugfixes (#846)

* IDE updater assorted bugfix

- add linux AppImage target
- fix hardcoded if condition that causes to always show the update dialog
- fix redundant test build version
- recalculate sha512 after notarization on macOS

* boost notarization speed

* recalculate artifacts hash
This commit is contained in:
Alberto Iannaccone
2022-02-21 21:40:46 +00:00
committed by GitHub
parent 9b1f15def8
commit 0a87fd00f3
9 changed files with 120 additions and 61 deletions

View File

@@ -257,10 +257,12 @@ ${fs.readFileSync(path('..', 'build', 'package.json')).toString()}
);
//-----------------------------------------------------------------------------------------------------+
// Copy to another folder. Azure does not support wildcard for `PublishBuildArtifacts@1.pathToPublish` |
// Recalculate artifacts hash and copy to another folder (because they can change after signing them).
// Azure does not support wildcard for `PublishBuildArtifacts@1.pathToPublish` |
//-----------------------------------------------------------------------------------------------------+
if (isCI) {
try {
await recalculateArtifactsHash();
await copyFilesToBuildArtifacts();
} catch (e) {
echo(JSON.stringify(e));
@@ -400,6 +402,67 @@ ${fs.readFileSync(path('..', 'build', 'package.json')).toString()}
}
}
async function recalculateArtifactsHash() {
echo(`🚢 Detected CI, recalculating artifacts hash...`);
const { platform } = process;
const cwd = path('..', 'build', 'dist');
const channelFilePath = join(cwd, getChannelFile(platform));
const yaml = require('yaml');
try {
let fileContents = fs.readFileSync(channelFilePath, 'utf8');
const newChannelFile = yaml.parse(fileContents);
const { files, path } = newChannelFile;
const newSha512 = await hashFile(join(cwd, path));
newChannelFile.sha512 = newSha512;
if (!!files) {
const newFiles = [];
for (let file of files) {
const { url } = file;
const { size } = fs.statSync(join(cwd, url));
const newSha512 = await hashFile(join(cwd, url));
newFiles.push({ ...file, sha512: newSha512, size });
}
newChannelFile.files = newFiles;
}
const newChannelFileRaw = yaml.stringify(newChannelFile);
fs.writeFileSync(channelFilePath, newChannelFileRaw);
echo(`👌 >>> Channel file updated successfully. New channel file:`);
echo(newChannelFileRaw);
} catch (e) {
console.log(e);
}
}
async function hashFile(
file,
algorithm = 'sha512',
encoding = 'base64',
options
) {
const crypto = require('crypto');
return await new Promise((resolve, reject) => {
const hash = crypto.createHash(algorithm);
hash.on('error', reject).setEncoding(encoding);
fs.createReadStream(
file,
Object.assign({}, options, {
highWaterMark: 1024 * 1024,
/* better to use more memory but hash faster */
})
)
.on('error', reject)
.on('end', () => {
hash.end();
resolve(hash.read());
})
.pipe(hash, {
end: false,
});
});
}
/**
* Joins tha path from `__dirname`.
*/