mirror of
https://github.com/andrei0x309/clear-wallet.git
synced 2025-02-02 14:50:44 +00:00
chore: change release script to get changes from changelog file
This commit is contained in:
parent
33147ae987
commit
a650b4583d
@ -1,7 +1,65 @@
|
|||||||
const pFs = import('fs')
|
const pFs = import('fs')
|
||||||
const pCps = import('child_process')
|
const pCps = import('child_process')
|
||||||
|
|
||||||
async function ghRelease (changes: string[], isRebuild: boolean) {
|
|
||||||
|
async function readFirst2000Characters(filePath: string): Promise<string> {
|
||||||
|
|
||||||
|
const fs = (await pFs).default
|
||||||
|
try {
|
||||||
|
const fileStream = fs.createReadStream(filePath, { encoding: 'utf8' });
|
||||||
|
let data = '';
|
||||||
|
|
||||||
|
for await (const chunk of fileStream) {
|
||||||
|
data += chunk;
|
||||||
|
if (data.length >= 2000) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return data.substring(0, 2000);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`Error reading file: ${err}`);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function limitedSplit(str: string, delimiter: string, limit: number): string[] {
|
||||||
|
if (limit <= 0) {
|
||||||
|
throw new Error("Limit must be greater than 0");
|
||||||
|
}
|
||||||
|
|
||||||
|
const result: string[] = [];
|
||||||
|
let current = 0;
|
||||||
|
let found;
|
||||||
|
|
||||||
|
do {
|
||||||
|
found = str.indexOf(delimiter, current);
|
||||||
|
if (found === -1 || result.length === limit - 1) {
|
||||||
|
result.push(str.substring(current));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
result.push(str.substring(current, found));
|
||||||
|
current = found + delimiter.length;
|
||||||
|
} while (true);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
const getLastChangeLog = async () => {
|
||||||
|
const mainChainLogPath = 'CHANGELOG.md';
|
||||||
|
const fs = (await pFs).default
|
||||||
|
if (!fs.existsSync(mainChainLogPath)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
const mainChainLog = await readFirst2000Characters(mainChainLogPath)
|
||||||
|
const manifestVersions = limitedSplit(mainChainLog, '## ', 2)[1]
|
||||||
|
const changesText = '## ' + manifestVersions
|
||||||
|
return changesText
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
async function ghRelease (isRebuild: boolean) {
|
||||||
const fs = (await pFs).default
|
const fs = (await pFs).default
|
||||||
|
|
||||||
if (!fs.existsSync('releases')) {
|
if (!fs.existsSync('releases')) {
|
||||||
@ -38,14 +96,12 @@ async function ghRelease (changes: string[], isRebuild: boolean) {
|
|||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
changeLogPath,
|
changeLogPath,
|
||||||
`# ${pkg.version} \n
|
`# ${pkg.version} \n
|
||||||
${changes.reduce((acc: string, change: string) => {
|
${await getLastChangeLog()}`,
|
||||||
return acc + `- ${change}\n`;
|
|
||||||
}, '')}`,
|
|
||||||
);
|
);
|
||||||
const cps = (await pCps)
|
const cps = (await pCps)
|
||||||
console.log(
|
console.log(
|
||||||
await new Promise((resolve) => {
|
await new Promise((resolve) => {
|
||||||
const p = cps.spawn('gh', ['release', 'create', `v${pkg.version}`, `./${outputPath}`, '-F', `./${changeLogPath}`], {
|
const p = cps.spawn('gh', ['release', 'create', `v${pkg.version}`, `./${outputPath}`, '-F', `./${changeLogPath}`, '--target', 'main'], {
|
||||||
shell: true,
|
shell: true,
|
||||||
});
|
});
|
||||||
let result = '';
|
let result = '';
|
||||||
@ -60,14 +116,9 @@ async function ghRelease (changes: string[], isRebuild: boolean) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
if (!process.argv[2]) {
|
|
||||||
console.log('No changes provided');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const changes = process.argv[2].split(',');
|
|
||||||
|
|
||||||
const isRebuild = changes.includes('rebuild');
|
const isRebuild = process.argv[2] === 'rebuild';
|
||||||
|
|
||||||
await ghRelease(changes, isRebuild);
|
await ghRelease(isRebuild);
|
||||||
console.log('Release created', changes);
|
console.log('Release created');
|
||||||
})();
|
})();
|
||||||
|
Loading…
Reference in New Issue
Block a user