You've already forked joplin
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:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -39,4 +39,5 @@ node_modules
|
|||||||
Tools/github_oauth_token.txt
|
Tools/github_oauth_token.txt
|
||||||
_releases
|
_releases
|
||||||
ReactNativeClient/lib/csstojs/
|
ReactNativeClient/lib/csstojs/
|
||||||
ElectronClient/app/gui/note-viewer/fonts/
|
ElectronClient/app/gui/note-viewer/fonts/
|
||||||
|
Tools/commit_hook.txt
|
@@ -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());
|
|
@@ -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();
|
|
@@ -1,5 +1,5 @@
|
|||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const { execCommand } = require('./tool-utils.js');
|
const { execCommand, githubRelease, githubOauthToken } = require('./tool-utils.js');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
const uriTemplate = require('uri-template');
|
const uriTemplate = require('uri-template');
|
||||||
@@ -46,14 +46,7 @@ function gradleVersionName(content) {
|
|||||||
return matches[1];
|
return matches[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
async function githubOauthToken() {
|
|
||||||
const r = await fs.readFile(rootDir + '/Tools/github_oauth_token.txt');
|
|
||||||
return r.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const oauthToken = await githubOauthToken();
|
|
||||||
|
|
||||||
const newContent = updateGradleConfig();
|
const newContent = updateGradleConfig();
|
||||||
const version = gradleVersionName(newContent);
|
const version = gradleVersionName(newContent);
|
||||||
const tagName = 'android-v' + version;
|
const tagName = 'android-v' + version;
|
||||||
@@ -88,28 +81,14 @@ async function main() {
|
|||||||
|
|
||||||
console.info('Creating GitHub release ' + tagName + '...');
|
console.info('Creating GitHub release ' + tagName + '...');
|
||||||
|
|
||||||
const response = await fetch('https://api.github.com/repos/laurent22/joplin/releases', {
|
const release = await githubRelease(tagName, false);
|
||||||
method: 'POST',
|
const uploadUrlTemplate = uriTemplate.parse(release.upload_url);
|
||||||
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 uploadUrl = uploadUrlTemplate.expand({ name: apkFilename });
|
const uploadUrl = uploadUrlTemplate.expand({ name: apkFilename });
|
||||||
|
|
||||||
const binaryBody = await fs.readFile(apkFilePath);
|
const binaryBody = await fs.readFile(apkFilePath);
|
||||||
|
|
||||||
|
const oauthToken = await githubOauthToken();
|
||||||
|
|
||||||
console.info('Uploading ' + apkFilename + ' to ' + uploadUrl);
|
console.info('Uploading ' + apkFilename + ' to ' + uploadUrl);
|
||||||
|
|
||||||
const uploadResponse = await fetch(uploadUrl, {
|
const uploadResponse = await fetch(uploadUrl, {
|
||||||
|
35
Tools/release-electron.js
Normal file
35
Tools/release-electron.js
Normal 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);
|
||||||
|
});
|
@@ -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;
|
module.exports = toolUtils;
|
Reference in New Issue
Block a user