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