1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-08-13 22:12:50 +02:00

Improved Android and Electron release process

This commit is contained in:
Laurent Cozic
2018-02-04 17:42:33 +00:00
parent b4dce0ed46
commit d278d830f0
6 changed files with 83 additions and 81 deletions

3
.gitignore vendored
View File

@@ -39,4 +39,5 @@ node_modules
Tools/github_oauth_token.txt
_releases
ReactNativeClient/lib/csstojs/
ElectronClient/app/gui/note-viewer/fonts/
ElectronClient/app/gui/note-viewer/fonts/
Tools/commit_hook.txt

View File

@@ -1,18 +0,0 @@
const fs = require('fs-extra');
const toolUtils = require('./tool-utils.js');
const rnDir = __dirname + '/../ReactNativeClient';
function androidVersionNumber() {
let content = fs.readFileSync(rnDir + '/android/app/build.gradle', 'utf8');
const r = content.match(/versionName\s+"(\d+?\.\d+?\.\d+)"/)
if (r.length !== 2) throw new Error('Could not get version number');
return r[1];
}
// const
// '/android/app/build/outputs/apk/app-armeabi-v7a-release.apk'
console.info(androidVersionNumber());

View File

@@ -1,36 +0,0 @@
const fs = require('fs-extra');
const rnDir = __dirname + '/../ReactNativeClient';
function increaseGradleVersionCode(content) {
const newContent = content.replace(/versionCode\s+(\d+)/, function(a, versionCode, c) {
const n = Number(versionCode);
if (isNaN(n) || !n) throw new Error('Invalid version code: ' + versionCode);
return 'versionCode ' + (n + 1);
});
if (newContent === content) throw new Error('Could not update version code');
return newContent;
}
function increaseGradleVersionName(content) {
const newContent = content.replace(/(versionName\s+"\d+?\.\d+?\.)(\d+)"/, function(match, prefix, buildNum) {
const n = Number(buildNum);
if (isNaN(n) || !n) throw new Error('Invalid version code: ' + versionCode);
return prefix + (n + 1) + '"';
});
if (newContent === content) throw new Error('Could not update version name');
return newContent;
}
function updateGradleConfig() {
let content = fs.readFileSync(rnDir + '/android/app/build.gradle', 'utf8');
content = increaseGradleVersionCode(content);
content = increaseGradleVersionName(content);
fs.writeFileSync(rnDir + '/android/app/build.gradle', content);
}
updateGradleConfig();

View File

@@ -1,5 +1,5 @@
const fs = require('fs-extra');
const { execCommand } = require('./tool-utils.js');
const { execCommand, githubRelease, githubOauthToken } = require('./tool-utils.js');
const path = require('path');
const fetch = require('node-fetch');
const uriTemplate = require('uri-template');
@@ -46,14 +46,7 @@ function gradleVersionName(content) {
return matches[1];
}
async function githubOauthToken() {
const r = await fs.readFile(rootDir + '/Tools/github_oauth_token.txt');
return r.toString();
}
async function main() {
const oauthToken = await githubOauthToken();
const newContent = updateGradleConfig();
const version = gradleVersionName(newContent);
const tagName = 'android-v' + version;
@@ -88,28 +81,14 @@ async function main() {
console.info('Creating GitHub release ' + tagName + '...');
const response = await fetch('https://api.github.com/repos/laurent22/joplin/releases', {
method: 'POST',
body: JSON.stringify({
tag_name: tagName,
name: tagName,
draft: false,
}),
headers: {
'Content-Type': 'application/json',
'Authorization': 'token ' + oauthToken,
},
});
const responseText = await response.text();
const responseJson = JSON.parse(responseText);
if (!responseJson.upload_url) throw new Error('No upload URL for release: ' + responseText);
const uploadUrlTemplate = uriTemplate.parse(responseJson.upload_url);
const release = await githubRelease(tagName, false);
const uploadUrlTemplate = uriTemplate.parse(release.upload_url);
const uploadUrl = uploadUrlTemplate.expand({ name: apkFilename });
const binaryBody = await fs.readFile(apkFilePath);
const oauthToken = await githubOauthToken();
console.info('Uploading ' + apkFilename + ' to ' + uploadUrl);
const uploadResponse = await fetch(uploadUrl, {

35
Tools/release-electron.js Normal file
View File

@@ -0,0 +1,35 @@
const fs = require('fs-extra');
const { execCommand, githubRelease, handleCommitHook } = require('./tool-utils.js');
const path = require('path');
const fetch = require('node-fetch');
const uriTemplate = require('uri-template');
const rootDir = path.dirname(__dirname);
const appDir = rootDir + '/ElectronClient/app';
async function main() {
const oauthToken = await githubOauthToken();
process.chdir(appDir);
console.info('Running from: ' + process.cwd());
const version = (await execCommand('npm version patch')).trim();
const tagName = version;
console.info('New version number: ' + version);
console.info(await execCommand('git add -A'));
console.info(await execCommand('git commit -m "Electron release ' + version + '"'));
await handleCommitHook();
console.info(await execCommand('git tag ' + tagName));
console.info(await execCommand('git push && git push --tags'));
const release = await githubRelease(tagName, true);
console.info('Created GitHub release: ' + release.url);
}
main().catch((error) => {
console.error('Fatal error');
console.error(error);
});

View File

@@ -81,4 +81,45 @@ toolUtils.fileExists = async function(filePath) {
});
}
toolUtils.githubOauthToken = async function() {
const r = await fs.readFile(__dirname + '/Tools/github_oauth_token.txt');
return r.toString();
}
toolUtils.githubRelease = async function(tagName, isDraft) {
const oauthToken = await githubOauthToken();
const response = await fetch('https://api.github.com/repos/laurent22/joplin/releases', {
method: 'POST',
body: JSON.stringify({
tag_name: tagName,
name: tagName,
draft: isDraft,
}),
headers: {
'Content-Type': 'application/json',
'Authorization': 'token ' + oauthToken,
},
});
const responseText = await response.text();
if (!response.ok) throw new Error('Cannot create GitHub release: ' + responseText);
const responseJson = JSON.parse(responseText);
if (!responseJson.url) throw new Error('No URL for release: ' + responseText);
return responseJson;
}
toolUtils.handleCommitHook = async function() {
const fs = require('fs-extra');
const filePath = __dirname + '/commit_hook.txt');
if (!(await fs.pathExists(filePath)) return;
const content = await fs.readFile(filePath);
if (!content) throw new Error('No content in ' + filePath);
console.info('Running hook: ' + content);
console.info(await toolUtils.execCommand(content));
}
module.exports = toolUtils;