-
Notifications
You must be signed in to change notification settings - Fork 0
/
upgrade-rr.js
45 lines (40 loc) · 1.62 KB
/
upgrade-rr.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright © 2020 Wei Zhang (Charmve).
// The following code is covered by the MIT license.
const https = require('https');
const os = require('os');
function get(url) {
return new Promise((resolve, reject) => {
https.get(url, res => {
if (res.statusCode >= 400) {
reject(new Error(`Couldn't get ${url} - Response status: ${res.statusCode}`));
return;
}
let body = '';
res.on('data', chunk => { body += chunk; });
res.on('error', error => { reject(error); });
res.on('end', () => { resolve(body); });
}).on('error', error => {
reject(error);
});
});
}
exports.register = async (fixers) => {
const releases = await get('https://github.com/rr-debugger/rr/releases');
const versions = releases
.match(/\/rr-debugger\/rr\/releases\/download\/\d+\.\d+\.\d+\/rr-[0-9.]+-Linux-x86_64\.deb/g)
.map(path => path.split('/')[5]);
const latest = versions.shift();
fixers[0].push({
id: 'upgrade-rr',
// Fix only non-binary files. Source: https://unix.stackexchange.com/a/36240
cmd: `for file in \$(git grep -I --name-only -z -e '' | xargs -0 echo); do` +
versions.map(version => {
const pattern = version.replace(/\./g, '\\.');
return `
sed ${os.type() === 'Darwin' ? '-i "" -E' : '-i -e'} "s/\\(RR_VERSION.*\\)${pattern}/\\1${latest}/g" $file ;
sed ${os.type() === 'Darwin' ? '-i "" -E' : '-i -e'} "s/\\(mozilla\\|rr-debugger\\)\\(\\/rr\\/releases\\/download.*\\)${pattern}\\(.*\\)${pattern}/rr-debugger\\2${latest}\\3${latest}/g" $file ;`;
}).join('') +
'\ndone',
description: 'Update pinned rr version',
});
};