Add release changelog creation script
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
"lint": "eslint src --ext .ts,.tsx,.js,.jsx --max-warnings=0 --cache",
|
"lint": "eslint src --ext .ts,.tsx,.js,.jsx --max-warnings=0 --cache",
|
||||||
"createCommitChangelog": "tsx tools/scripts/createCommitChangelog.ts",
|
"createCommitChangelog": "tsx tools/scripts/createCommitChangelog.ts",
|
||||||
"createTranslationChangelog": "tsx tools/scripts/createTranslationChangelog.ts",
|
"createTranslationChangelog": "tsx tools/scripts/createTranslationChangelog.ts",
|
||||||
|
"createReleaseChangelog": "tsx tools/scripts/createReleaseChangelog.ts",
|
||||||
"updateDeps": "tsx tools/scripts/updateDependencies.ts",
|
"updateDeps": "tsx tools/scripts/updateDependencies.ts",
|
||||||
"gql:codegen-base": "graphql-codegen --config gql_codegen.ts",
|
"gql:codegen-base": "graphql-codegen --config gql_codegen.ts",
|
||||||
"gql:codegen-formatter": "tsx tools/scripts/codegenFormatter.ts",
|
"gql:codegen-formatter": "tsx tools/scripts/codegenFormatter.ts",
|
||||||
|
|||||||
49
tools/scripts/createReleaseChangelog.ts
Normal file
49
tools/scripts/createReleaseChangelog.ts
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) Contributors to the Suwayomi project
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import yargs from 'yargs';
|
||||||
|
import { hideBin } from 'yargs/helpers';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import { createCommitChangelog } from './release/CommitChangelog.utils.ts';
|
||||||
|
import { createTranslationChangelog, validateWeblateDates } from './release/TranslationChangelog.utils.ts';
|
||||||
|
|
||||||
|
const { sha, date } = yargs(hideBin(process.argv))
|
||||||
|
.options({
|
||||||
|
sha: {
|
||||||
|
description: 'The hash of the last commit of the previous release',
|
||||||
|
type: 'string',
|
||||||
|
demandOption: true,
|
||||||
|
},
|
||||||
|
date: {
|
||||||
|
alias: 'ad',
|
||||||
|
description: 'IS0-8601 formatted date of the last release (e.g. 2024-05-01)',
|
||||||
|
type: 'string',
|
||||||
|
demandOption: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.parseSync();
|
||||||
|
|
||||||
|
if (!sha) {
|
||||||
|
throw new Error('Sha of last commit of the previous release has to be passed!');
|
||||||
|
}
|
||||||
|
const createReleaseChangelog = async (lastReleaseCommitSha: string, lastReleaseDate: string) => {
|
||||||
|
validateWeblateDates(lastReleaseDate, lastReleaseDate);
|
||||||
|
|
||||||
|
const tomorrow = dayjs().add(1, 'day');
|
||||||
|
|
||||||
|
const beforeDate = tomorrow.format('YYYY-MM-DD');
|
||||||
|
const afterDate = dayjs(lastReleaseDate).add(1, 'day').format('YYYY-MM-DD');
|
||||||
|
|
||||||
|
const commitChangelog = await createCommitChangelog(lastReleaseCommitSha);
|
||||||
|
const translationChangelog = await createTranslationChangelog(afterDate, beforeDate);
|
||||||
|
const changelog = `${translationChangelog}\n${commitChangelog}`;
|
||||||
|
|
||||||
|
console.log(changelog);
|
||||||
|
};
|
||||||
|
|
||||||
|
createReleaseChangelog(sha, date).then(console.log);
|
||||||
@@ -99,8 +99,6 @@ export const TRANSLATION_CHANGELOG_YARG_OPTIONS_DEFAULT = {
|
|||||||
keepKnownContributors: true,
|
keepKnownContributors: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
const dateRegex = /[0-9]{4}-[0-9]{2}-[0-9]{2}/g;
|
|
||||||
|
|
||||||
const fetchData = async <T = any>(url: string, authToken: string): Promise<T> => {
|
const fetchData = async <T = any>(url: string, authToken: string): Promise<T> => {
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@@ -307,17 +305,24 @@ const getKnownContributorsByLanguage = async (): Promise<Record<string, string[]
|
|||||||
return contributorByLanguage;
|
return contributorByLanguage;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const dateRegex = /[0-9]{4}-[0-9]{2}-[0-9]{2}/g;
|
||||||
|
const isValidIS08601Date = (date: string): boolean => !!date.match(dateRegex);
|
||||||
|
|
||||||
|
export const validateWeblateDates = (afterDate: string, beforeDate: string) => {
|
||||||
|
if (!isValidIS08601Date(afterDate) || !isValidIS08601Date(beforeDate)) {
|
||||||
|
throw new Error(
|
||||||
|
`The passed timestamps are not properly formatted. They have to match "${dateRegex}" (e.g. 2024-05-11)`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const createTranslationChangelog = async (
|
export const createTranslationChangelog = async (
|
||||||
afterDate: string,
|
afterDate: string,
|
||||||
beforeDate: string,
|
beforeDate: string,
|
||||||
requiredContributionCount: number = TRANSLATION_CHANGELOG_YARG_OPTIONS_DEFAULT.requiredContributionCount,
|
requiredContributionCount: number = TRANSLATION_CHANGELOG_YARG_OPTIONS_DEFAULT.requiredContributionCount,
|
||||||
keepKnownContributors: boolean = TRANSLATION_CHANGELOG_YARG_OPTIONS_DEFAULT.keepKnownContributors,
|
keepKnownContributors: boolean = TRANSLATION_CHANGELOG_YARG_OPTIONS_DEFAULT.keepKnownContributors,
|
||||||
): Promise<string> => {
|
): Promise<string> => {
|
||||||
if (!afterDate.match(dateRegex) || !beforeDate.match(dateRegex)) {
|
validateWeblateDates(afterDate, beforeDate);
|
||||||
throw new Error(
|
|
||||||
`The passed timestamps are not properly formatted. They have to match "${dateRegex}" (e.g. 2024-05-11)`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const timestampAfter = `${afterDate}T00:00:00.000Z`;
|
const timestampAfter = `${afterDate}T00:00:00.000Z`;
|
||||||
const timestampBefore = `${beforeDate}T00:00:00.000Z`;
|
const timestampBefore = `${beforeDate}T00:00:00.000Z`;
|
||||||
|
|||||||
Reference in New Issue
Block a user