mirror of https://github.com/sualko/cloud_bbb
build: use same code style for scripts
parent
92a06e3ff1
commit
33aad6367a
|
@ -1,12 +1,13 @@
|
|||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
require('colors').setTheme({
|
||||
verbose: 'cyan',
|
||||
warn: 'yellow',
|
||||
error: 'red',
|
||||
});
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const libxml = require("libxmljs");
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const libxml = require('libxmljs');
|
||||
const https = require('https');
|
||||
const archiver = require('archiver');
|
||||
const execa = require('execa');
|
||||
|
@ -38,8 +39,8 @@ async function prepareInfoXml() {
|
|||
}
|
||||
|
||||
function updateVersion(xmlDoc, version) {
|
||||
let versionChild = xmlDoc.get('//version');
|
||||
let currentVersion = versionChild.text();
|
||||
const versionChild = xmlDoc.get('//version');
|
||||
const currentVersion = versionChild.text();
|
||||
|
||||
if (version !== currentVersion) {
|
||||
console.log(`✔ Update version in info.xml to ${version}.`.green);
|
||||
|
@ -55,18 +56,18 @@ async function createRelease(appId) {
|
|||
console.log(`I'm now building ${appId} in version ${version}.`.verbose);
|
||||
|
||||
await execa('yarn', ['composer:install:dev']);
|
||||
console.log(`✔ composer dev dependencies installed`.green);
|
||||
console.log('✔ composer dev dependencies installed'.green);
|
||||
|
||||
await execa('yarn', ['lint']);
|
||||
console.log(`✔ linters are happy`.green);
|
||||
console.log('✔ linters are happy'.green);
|
||||
|
||||
await execa('yarn', ['composer:install']);
|
||||
console.log(`✔ composer dependencies installed`.green);
|
||||
console.log('✔ composer dependencies installed'.green);
|
||||
|
||||
await execa('yarn', ['build']);
|
||||
console.log(`✔ scripts built`.green);
|
||||
console.log('✔ scripts built'.green);
|
||||
|
||||
let filePath = await createArchive(appId, appId + '-v' + version);
|
||||
const filePath = await createArchive(appId, appId + '-v' + version);
|
||||
await createNextcloudSignature(appId, filePath);
|
||||
await createGPGSignature(filePath);
|
||||
await createGPGArmorSignature(filePath);
|
||||
|
@ -74,10 +75,10 @@ async function createRelease(appId) {
|
|||
|
||||
|
||||
function createArchive(appId, fileBaseName) {
|
||||
let fileName = `${fileBaseName}.tar.gz`;
|
||||
let filePath = path.normalize(__dirname + `/../archives/${fileName}`);
|
||||
let output = fs.createWriteStream(filePath);
|
||||
let archive = archiver('tar', {
|
||||
const fileName = `${fileBaseName}.tar.gz`;
|
||||
const filePath = path.normalize(__dirname + `/../archives/${fileName}`);
|
||||
const output = fs.createWriteStream(filePath);
|
||||
const archive = archiver('tar', {
|
||||
gzip: true,
|
||||
});
|
||||
|
||||
|
@ -109,12 +110,12 @@ function createArchive(appId, fileBaseName) {
|
|||
addDirectory('lib');
|
||||
addDirectory('templates');
|
||||
addFile('COPYING');
|
||||
addFile('README.md')
|
||||
addFile('README.md');
|
||||
|
||||
archive.glob('vendor/**/*', {
|
||||
ignore: ['.git']
|
||||
ignore: ['.git'],
|
||||
}, {
|
||||
prefix: appId
|
||||
prefix: appId,
|
||||
});
|
||||
|
||||
return new Promise(resolve => {
|
||||
|
@ -130,7 +131,7 @@ function createArchive(appId, fileBaseName) {
|
|||
|
||||
function createNextcloudSignature(appId, filePath) {
|
||||
const {
|
||||
exec
|
||||
exec,
|
||||
} = require('child_process');
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
@ -157,7 +158,7 @@ function createNextcloudSignature(appId, filePath) {
|
|||
|
||||
function createGPGSignature(filePath) {
|
||||
const {
|
||||
exec
|
||||
exec,
|
||||
} = require('child_process');
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
@ -183,7 +184,7 @@ function createGPGSignature(filePath) {
|
|||
|
||||
function createGPGArmorSignature(filePath) {
|
||||
const {
|
||||
exec
|
||||
exec,
|
||||
} = require('child_process');
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
@ -211,7 +212,7 @@ async function validateXml(xmlDoc) {
|
|||
const schemaLocation = xmlDoc.root().attr('noNamespaceSchemaLocation').value();
|
||||
|
||||
if (!schemaLocation) {
|
||||
throw "Found no schema location";
|
||||
throw 'Found no schema location';
|
||||
}
|
||||
|
||||
|
||||
|
@ -223,7 +224,7 @@ async function validateXml(xmlDoc) {
|
|||
|
||||
return;
|
||||
}
|
||||
let xsdDoc = libxml.parseXml(schemaString);
|
||||
const xsdDoc = libxml.parseXml(schemaString);
|
||||
|
||||
if (xmlDoc.validate(xsdDoc)) {
|
||||
console.log('✔ Document valid'.green);
|
||||
|
@ -252,8 +253,8 @@ function wget(url) {
|
|||
resolve(data);
|
||||
});
|
||||
|
||||
}).on("error", (err) => {
|
||||
}).on('error', (err) => {
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
});
|
||||
}
|
|
@ -1,13 +1,14 @@
|
|||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
require('colors').setTheme({
|
||||
verbose: 'cyan',
|
||||
warn: 'yellow',
|
||||
error: 'red',
|
||||
});
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const https = require('https');
|
||||
const { Octokit } = require("@octokit/rest");
|
||||
const { Octokit } = require('@octokit/rest');
|
||||
const execa = require('execa');
|
||||
const inquirer = require('inquirer');
|
||||
const git = require('simple-git/promise')();
|
||||
|
@ -49,7 +50,7 @@ async function generateChangelog() {
|
|||
|
||||
const logs = await git.log({
|
||||
from: latestTag,
|
||||
to: 'HEAD'
|
||||
to: 'HEAD',
|
||||
});
|
||||
|
||||
const sections = [{
|
||||
|
@ -63,13 +64,13 @@ async function generateChangelog() {
|
|||
const entries = {};
|
||||
|
||||
logs.all.forEach(log => {
|
||||
let [, type, scope, description] = log.message.match(/^([a-z]+)(?:\((\w+)\))?: (.+)/);
|
||||
let entry = { type, scope, description, issues: [] };
|
||||
const [, type, scope, description] = log.message.match(/^([a-z]+)(?:\((\w+)\))?: (.+)/);
|
||||
const entry = { type, scope, description, issues: [] };
|
||||
|
||||
if(log.body) {
|
||||
const matches = log.body.match(/(?:fix|fixes|closes?|refs?) #(\d+)/g) || [];
|
||||
|
||||
for (let match of matches) {
|
||||
for (const match of matches) {
|
||||
const [, number] = match.match(/(\d+)$/);
|
||||
|
||||
entry.issues.push(number);
|
||||
|
@ -86,7 +87,7 @@ async function generateChangelog() {
|
|||
let changeLog = `## ${title}\n`;
|
||||
|
||||
function stringifyEntry(entry) {
|
||||
let issues = entry.issues.map(issue => {
|
||||
const issues = entry.issues.map(issue => {
|
||||
return `[#${issue}](https://github.com/sualko/cloud_bbb/issues/${issue})`;
|
||||
}).join('');
|
||||
|
||||
|
@ -106,26 +107,26 @@ async function generateChangelog() {
|
|||
|
||||
delete entries[section.type];
|
||||
|
||||
changeLog += `\n`
|
||||
changeLog += '\n';
|
||||
});
|
||||
|
||||
const miscKeys = Object.keys(entries);
|
||||
|
||||
if (miscKeys && miscKeys.length > 0) {
|
||||
changeLog += `### Misc\n`;
|
||||
changeLog += '### Misc\n';
|
||||
|
||||
miscKeys.forEach(type => {
|
||||
entries[type].forEach(entry => {
|
||||
changeLog += stringifyEntry(entry);
|
||||
});
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
return changeLog;
|
||||
}
|
||||
|
||||
async function editChangeLog(changeLog) {
|
||||
let answers = await inquirer.prompt([{
|
||||
const answers = await inquirer.prompt([{
|
||||
type: 'editor',
|
||||
name: 'changeLog',
|
||||
message: 'You have now the possibility to edit the change log',
|
||||
|
@ -150,7 +151,7 @@ function hasChangeLogEntry() {
|
|||
}
|
||||
|
||||
async function commitChangeLog() {
|
||||
let status = await git.status();
|
||||
const status = await git.status();
|
||||
|
||||
if (status.staged.length > 0) {
|
||||
throw 'Repo not clean. Found staged files.';
|
||||
|
@ -171,7 +172,7 @@ async function stageAllFiles() {
|
|||
return;
|
||||
}
|
||||
|
||||
let gitProcess = execa('git', ['add', '-u']);
|
||||
const gitProcess = execa('git', ['add', '-u']);
|
||||
|
||||
gitProcess.stdout.pipe(process.stdout);
|
||||
|
||||
|
@ -179,7 +180,7 @@ async function stageAllFiles() {
|
|||
}
|
||||
|
||||
function showStagedDiff() {
|
||||
let gitProcess = execa('git', ['diff', '--staged']);
|
||||
const gitProcess = execa('git', ['diff', '--staged']);
|
||||
|
||||
gitProcess.stdout.pipe(process.stdout);
|
||||
|
||||
|
@ -203,7 +204,7 @@ function commit() {
|
|||
}
|
||||
|
||||
async function wantToContinue(message) {
|
||||
let answers = await inquirer.prompt([{
|
||||
const answers = await inquirer.prompt([{
|
||||
type: 'confirm',
|
||||
name: 'continue',
|
||||
message,
|
||||
|
@ -225,7 +226,7 @@ function push() {
|
|||
|
||||
async function createGithubRelease(changeLog) {
|
||||
if (!process.env.GITHUB_TOKEN) {
|
||||
throw 'Github token missing'
|
||||
throw 'Github token missing';
|
||||
}
|
||||
|
||||
const octokit = new Octokit({
|
||||
|
@ -233,8 +234,8 @@ async function createGithubRelease(changeLog) {
|
|||
userAgent: 'custom releaser for sualko/cloud_bbb',
|
||||
});
|
||||
|
||||
let origin = (await git.remote(['get-url', 'origin'])).trim();
|
||||
let matches = origin.match(/^git@github\.com:(.+)\/(.+)\.git$/);
|
||||
const origin = (await git.remote(['get-url', 'origin'])).trim();
|
||||
const matches = origin.match(/^git@github\.com:(.+)\/(.+)\.git$/);
|
||||
|
||||
if (!matches) {
|
||||
throw 'Origin is not configured or no ssh url';
|
||||
|
@ -245,6 +246,7 @@ async function createGithubRelease(changeLog) {
|
|||
const releaseOptions = {
|
||||
owner,
|
||||
repo,
|
||||
// eslint-disable-next-line @typescript-eslint/camelcase
|
||||
tag_name: tagName,
|
||||
name: `${package.name} ${tagName}`,
|
||||
body: changeLog.replace(/^## [^\n]+\n/, ''),
|
||||
|
@ -256,7 +258,7 @@ async function createGithubRelease(changeLog) {
|
|||
return [];
|
||||
}
|
||||
|
||||
let releaseResponse = await octokit.repos.createRelease(releaseOptions);
|
||||
const releaseResponse = await octokit.repos.createRelease(releaseOptions);
|
||||
|
||||
console.log(`Draft created, see ${releaseResponse.data.html_url}`.verbose);
|
||||
|
||||
|
@ -276,11 +278,12 @@ async function createGithubRelease(changeLog) {
|
|||
return 'application/octet-stream';
|
||||
}
|
||||
|
||||
let assetUrls = await Promise.all(files.map(async file => {
|
||||
const assetUrls = await Promise.all(files.map(async file => {
|
||||
const filename = path.basename(file);
|
||||
const uploadOptions = {
|
||||
owner,
|
||||
repo,
|
||||
// eslint-disable-next-line @typescript-eslint/camelcase
|
||||
release_id: releaseResponse.data.id,
|
||||
data: fs.createReadStream(file),
|
||||
headers: {
|
||||
|
@ -290,7 +293,7 @@ async function createGithubRelease(changeLog) {
|
|||
name: filename,
|
||||
};
|
||||
|
||||
let assetResponse = await octokit.repos.uploadReleaseAsset(uploadOptions);
|
||||
const assetResponse = await octokit.repos.uploadReleaseAsset(uploadOptions);
|
||||
|
||||
console.log(`Asset uploaded: ${assetResponse.data.name}`.verbose);
|
||||
|
||||
|
@ -321,8 +324,8 @@ async function uploadToNextcloudStore(archiveUrl) {
|
|||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Content-Length': data.length,
|
||||
'Authorization': `Token ${process.env.NEXTCLOUD_TOKEN}`,
|
||||
}
|
||||
Authorization: `Token ${process.env.NEXTCLOUD_TOKEN}`,
|
||||
},
|
||||
};
|
||||
|
||||
if (isDryRun) {
|
||||
|
@ -345,9 +348,9 @@ async function uploadToNextcloudStore(archiveUrl) {
|
|||
}
|
||||
|
||||
res.on('data', d => {
|
||||
process.stdout.write(d)
|
||||
})
|
||||
})
|
||||
process.stdout.write(d);
|
||||
});
|
||||
});
|
||||
|
||||
req.on('error', error => {
|
||||
reject(error);
|
||||
|
@ -360,54 +363,54 @@ async function uploadToNextcloudStore(archiveUrl) {
|
|||
|
||||
async function run() {
|
||||
await pull();
|
||||
console.log(`✔ pulled latest changes`.green);
|
||||
console.log('✔ pulled latest changes'.green);
|
||||
|
||||
await notAlreadyTagged();
|
||||
console.log(`✔ not already tagged`.green);
|
||||
console.log('✔ not already tagged'.green);
|
||||
|
||||
await lastCommitNotBuild();
|
||||
console.log(`✔ last commit is no build commit`.green);
|
||||
console.log('✔ last commit is no build commit'.green);
|
||||
|
||||
await isMasterBranch();
|
||||
console.log(`✔ this is the master branch`.green);
|
||||
console.log('✔ this is the master branch'.green);
|
||||
|
||||
let changeLog = await generateChangelog();
|
||||
console.log(`✔ change log generated`.green);
|
||||
console.log('✔ change log generated'.green);
|
||||
|
||||
changeLog = await editChangeLog(changeLog);
|
||||
console.log(`✔ change log updated`.green);
|
||||
console.log('✔ change log updated'.green);
|
||||
|
||||
console.log('Press any key to continue...');
|
||||
await keypress();
|
||||
|
||||
await hasChangeLogEntry();
|
||||
console.log(`✔ there is a change log entry for this version`.green);
|
||||
console.log('✔ there is a change log entry for this version'.green);
|
||||
|
||||
await commitChangeLog();
|
||||
console.log(`✔ change log commited`.green);
|
||||
console.log('✔ change log commited'.green);
|
||||
|
||||
await hasArchiveAndSignatures();
|
||||
console.log(`✔ found archive and signatures`.green);
|
||||
console.log('✔ found archive and signatures'.green);
|
||||
|
||||
await stageAllFiles();
|
||||
console.log(`✔ all files staged`.green);
|
||||
console.log('✔ all files staged'.green);
|
||||
|
||||
await showStagedDiff();
|
||||
|
||||
await wantToContinue('Should I commit those changes?');
|
||||
|
||||
await commit();
|
||||
console.log(`✔ All files commited`.green);
|
||||
console.log('✔ All files commited'.green);
|
||||
|
||||
await wantToContinue('Should I push all pending commits?');
|
||||
|
||||
await push();
|
||||
console.log(`✔ All commits pushed`.green);
|
||||
console.log('✔ All commits pushed'.green);
|
||||
|
||||
await wantToContinue('Should I continue to create a Github release?');
|
||||
|
||||
const assetUrls = await createGithubRelease(changeLog);
|
||||
console.log(`✔ released on github`.green);
|
||||
console.log('✔ released on github'.green);
|
||||
|
||||
const archiveAssetUrl = assetUrls.find(url => url.endsWith('.tar.gz'));
|
||||
console.log(`Asset url for Nextcloud store: ${archiveAssetUrl}`.verbose);
|
||||
|
@ -415,7 +418,7 @@ async function run() {
|
|||
await wantToContinue('Should I continue to upload the release to the app store?');
|
||||
|
||||
await uploadToNextcloudStore(archiveAssetUrl);
|
||||
console.log(`✔ released in Nextcloud app store`.green);
|
||||
console.log('✔ released in Nextcloud app store'.green);
|
||||
};
|
||||
|
||||
run().catch(err => {
|
||||
|
|
Loading…
Reference in New Issue