1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-30 08:26:59 +02:00

Tools: Move Android URL update to update-readme script

This commit is contained in:
Laurent Cozic 2021-08-20 11:37:12 +01:00
parent ee0b34156c
commit d6c4228a41
4 changed files with 43 additions and 24 deletions

View File

@ -1764,6 +1764,9 @@ packages/tools/setupNewRelease.js.map
packages/tools/tool-utils.d.ts
packages/tools/tool-utils.js
packages/tools/tool-utils.js.map
packages/tools/update-readme-download.d.ts
packages/tools/update-readme-download.js
packages/tools/update-readme-download.js.map
packages/tools/update-readme-sponsors.d.ts
packages/tools/update-readme-sponsors.js
packages/tools/update-readme-sponsors.js.map

3
.gitignore vendored
View File

@ -1749,6 +1749,9 @@ packages/tools/setupNewRelease.js.map
packages/tools/tool-utils.d.ts
packages/tools/tool-utils.js
packages/tools/tool-utils.js.map
packages/tools/update-readme-download.d.ts
packages/tools/update-readme-download.js
packages/tools/update-readme-download.js.map
packages/tools/update-readme-sponsors.d.ts
packages/tools/update-readme-sponsors.js
packages/tools/update-readme-sponsors.js.map

View File

@ -164,15 +164,6 @@ async function main() {
releaseFiles[releaseName] = await createRelease(releaseName, tagName, version);
}
if (!isPreRelease) {
console.info('Updating Readme URL...');
let readmeContent = await fs.readFile(`${rootDir}/README.md`, 'utf8');
readmeContent = readmeContent.replace(/(https:\/\/github.com\/laurent22\/joplin-android\/releases\/download\/android-v\d+\.\d+\.\d+\/joplin-v\d+\.\d+\.\d+\.apk)/, releaseFiles['main'].downloadUrl);
readmeContent = readmeContent.replace(/(https:\/\/github.com\/laurent22\/joplin-android\/releases\/download\/android-v\d+\.\d+\.\d+\/joplin-v\d+\.\d+\.\d+-32bit\.apk)/, releaseFiles['32bit'].downloadUrl);
await fs.writeFile(`${rootDir}/README.md`, readmeContent);
}
// NOT TESTED: These commands should not be necessary anymore since they are
// done in completeReleaseWithChangelog()

View File

@ -1,27 +1,33 @@
'use strict';
const fs = require('fs-extra');
import * as fs from 'fs-extra';
import { fileExtension } from '@joplin/lib/path-utils';
const request = require('request');
const { fileExtension } = require('@joplin/lib/path-utils');
const url = 'https://api.github.com/repos/laurent22/joplin/releases/latest';
const readmePath = `${__dirname}/../../README.md`;
async function msleep(ms) {
interface GitHubReleaseAsset {
name: string;
browser_download_url: string;
}
interface GitHubRelease {
assets: GitHubReleaseAsset[];
tag_name: string;
}
async function msleep(ms: number) {
return new Promise((resolve) => {
setTimeout(() => {
resolve();
resolve(null);
}, ms);
});
}
async function gitHubLatestRelease() {
async function gitHubLatestRelease(repoName: string): Promise<GitHubRelease> {
return new Promise((resolve, reject) => {
request.get({
url: url,
url: `https://api.github.com/repos/laurent22/${repoName}/releases/latest`,
json: true,
headers: { 'User-Agent': 'Joplin Readme Updater' },
}, (error, response, data) => {
}, (error: any, response: any, data: any) => {
if (error) {
reject(error);
} else if (response.statusCode !== 200) {
@ -34,7 +40,7 @@ async function gitHubLatestRelease() {
});
}
function downloadUrl(release, os, portable = false) {
function downloadUrl(release: GitHubRelease, os: string, portable = false) {
if (!release || !release.assets || !release.assets.length) return null;
for (let i = 0; i < release.assets.length; i++) {
@ -43,6 +49,7 @@ function downloadUrl(release, os, portable = false) {
const ext = fileExtension(name);
if (ext === 'dmg' && os === 'macos') return asset.browser_download_url;
if (ext === 'exe' && os === 'windows') {
if (portable) {
if (name === 'JoplinPortable.exe') return asset.browser_download_url;
@ -50,8 +57,15 @@ function downloadUrl(release, os, portable = false) {
if (name.match(/^Joplin-Setup-[\d.]+\.exe$/)) return asset.browser_download_url;
}
}
if (ext === 'AppImage' && os === 'linux') return asset.browser_download_url;
if (os === 'android32' && name.endsWith('32bit.apk')) return asset.browser_download_url;
if (os === 'android' && ext === 'apk' && !name.endsWith('32bit.apk')) return asset.browser_download_url;
}
throw new Error(`Could not find download URL for: ${os}`);
}
function readmeContent() {
@ -59,19 +73,19 @@ function readmeContent() {
return fs.readFileSync(readmePath, 'utf8');
}
function setReadmeContent(content) {
function setReadmeContent(content: string) {
if (!fs.existsSync(readmePath)) throw new Error(`Cannot find ${readmePath}`);
return fs.writeFileSync(readmePath, content);
}
async function main(argv) {
async function main(argv: any) {
const waitForVersion = argv.length === 3 ? argv[2] : null;
if (waitForVersion) console.info(`Waiting for version ${waitForVersion} to be released before updating readme...`);
let release = null;
while (true) {
release = await gitHubLatestRelease();
release = await gitHubLatestRelease('joplin');
if (!waitForVersion) break;
if (release.tag_name !== waitForVersion) {
@ -82,6 +96,10 @@ async function main(argv) {
}
}
const androidRelease = await gitHubLatestRelease('joplin-android');
const android32Url = downloadUrl(androidRelease, 'android32');
const androidUrl = downloadUrl(androidRelease, 'android');
const winUrl = downloadUrl(release, 'windows');
const winPortableUrl = downloadUrl(release, 'windows', true);
const macOsUrl = downloadUrl(release, 'macos');
@ -91,6 +109,8 @@ async function main(argv) {
console.info('Windows Portable: ', winPortableUrl);
console.info('macOS: ', macOsUrl);
console.info('Linux: ', linuxUrl);
console.info('Android: ', androidUrl);
console.info('Android 32: ', android32Url);
let content = readmeContent();
@ -98,6 +118,8 @@ async function main(argv) {
if (winPortableUrl) content = content.replace(/(https:\/\/github.com\/laurent22\/joplin\/releases\/download\/v\d+\.\d+\.\d+\/JoplinPortable.exe)/, winPortableUrl);
if (macOsUrl) content = content.replace(/(https:\/\/github.com\/laurent22\/joplin\/releases\/download\/v\d+\.\d+\.\d+\/Joplin-.*?\.dmg)/, macOsUrl);
if (linuxUrl) content = content.replace(/(https:\/\/github.com\/laurent22\/joplin\/releases\/download\/v\d+\.\d+\.\d+\/Joplin-.*?\.AppImage)/, linuxUrl);
if (androidUrl) content = content.replace(/(https:\/\/github.com\/laurent22\/joplin-android\/releases\/download\/android-v\d+\.\d+\.\d+\/joplin-v\d+\.\d+\.\d+\.apk)/, androidUrl);
if (android32Url) content = content.replace(/(https:\/\/github.com\/laurent22\/joplin-android\/releases\/download\/android-v\d+\.\d+\.\d+\/joplin-v\d+\.\d+\.\d+-32bit\.apk)/, android32Url);
setReadmeContent(content);