refactor: improve code quality (#138)

Signed-off-by: Ardalan Amini <[email protected]>
This commit is contained in:
Ardalan Amini authored and GitHub committed 2023-04-29 22:47:35 +03:30
1 parent 1e734abbf9
commit 418818d74b
40 files changed
+2210 -467

No files matched your search

+119 -82
View File
@@ -23,138 +23,175 @@
*
*/
import { debug } from "@actions/core";
import {
APP_AUTHOR_SUFFIX,
APP_AUTHOR_SUFFIX_LENGTH,
type ChangelogInputI,
COMMIT_REGEX,
type LogsI,
type ReferenceI,
} from "./constants";
commitTypes,
defaultCommitType,
includeCommitLinks,
includePRLinks,
mentionAuthors,
octokit,
parseCommitMessage,
repository,
sha,
} from "./utils/index.js";
function trim(value: string): string {
interface TypeGroupI {
scopes: ScopeGroupI[];
type: string;
}
interface ScopeGroupI {
logs: LogI[];
scope: string;
}
interface LogI {
description: string;
references: string[];
}
function trim<T extends string | undefined>(value: T): T {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (value == null) return value;
return value.trim().replace(/ {2,}/g, " ");
return value.trim().replace(/ {2,}/g, " ") as never;
}
function unique(value: string[]): string[] {
return [...new Set(value)];
}
export async function generate(input: ChangelogInputI): Promise<string> {
const { octokit, owner, repo, sha, tagRef, inputs } = input;
const { commitTypes, defaultCommitType, mentionAuthors, includePRLinks, includeCommitLinks } = inputs;
function sortBy<T>(array: T[], property: keyof T): T[] {
return array.sort((a, b) => (a[property] as string).localeCompare(b[property] as string));
}
const repoUrl = `https://github.com/${ owner }/${ repo }`;
const commits: LogsI = {};
export async function generateChangelog(lastSha?: string): Promise<string> {
const { paginate, rest } = octokit();
const { owner, repo, url } = repository();
const defaultType = defaultCommitType();
const typeMap = commitTypes();
paginator: for await (const { data } of octokit.paginate.iterator(
octokit.rest.repos.listCommits,
const iterator = paginate.iterator(
rest.repos.listCommits,
{
per_page: 100,
sha : sha(),
owner,
repo,
sha,
},
)) {
);
const typeGroups: TypeGroupI[] = [];
paginator: for await (const { data } of iterator) {
for (const commit of data) {
if (commit.sha === tagRef) break paginator;
if (commit.sha === lastSha) break paginator;
const message = commit.commit.message.split("\n")[0];
let { type, category, title, pr, flag } = COMMIT_REGEX.exec(message)?.groups ?? {};
debug(`commit message -> ${ message }`);
if (!title) continue;
let { type, scope, description, pr, flag } = parseCommitMessage(message);
if (!description) continue;
description = trim(description);
flag = trim(flag);
if (flag === "ignore") continue;
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
type = commitTypes[trim(type)] ?? defaultCommitType;
type = typeMap[trim(type ?? "")] ?? defaultType;
category = category ? trim(category) : "";
let typeGroup = typeGroups.find(record => record.type === type);
title = trim(title);
if (typeGroup == null) {
typeGroup = {
type,
scopes: [],
};
let types = commits[type];
types ??= commits[type] = {};
let logs = types[category];
logs ??= types[category] = [];
const existingCommit = logs.find(log => log.title === title);
const reference: ReferenceI = {
author: mentionAuthors ? commit.author?.login : null,
commit: includeCommitLinks ? commit.sha : null,
pr : includePRLinks ? pr : null,
};
if (existingCommit == null) {
logs.push({
title,
references: [reference],
});
} else {
existingCommit.references.push(reference);
typeGroups.push(typeGroup);
}
scope = trim(scope ?? "");
let scopeGroup = typeGroup.scopes.find(record => record.scope === scope);
if (scopeGroup == null) {
scopeGroup = {
scope,
logs: [],
};
typeGroup.scopes.push(scopeGroup);
}
let log = scopeGroup.logs.find(record => record.description === description);
if (log == null) {
log = {
description,
references: [],
};
scopeGroup.logs.push(log);
}
const reference: string[] = [];
if (pr && includePRLinks()) reference.push(`${ url }/issues/${ pr }`);
if (includeCommitLinks()) reference.push(`${ url }/commit/${ commit.sha }`);
if (commit.author?.login && mentionAuthors()) reference.push(`by @${ commit.author.login }`);
if (reference.length > 0) log.references.push(reference.join(" "));
}
}
const TYPES = unique([...Object.values(commitTypes), defaultCommitType]);
const types = unique(Object.values(typeMap).concat(defaultType));
return TYPES.reduce<string[]>((changelog, type) => {
const typeGroup = commits[type];
const changelog: string[] = [];
if (typeGroup == null) return changelog;
for (const type of types) {
const typeGroup = typeGroups.find(log => log.type === type);
if (typeGroup == null) continue;
changelog.push(`## ${ type }`);
const categories = Object.keys(typeGroup).sort();
sortBy(typeGroup.scopes, "scope");
for (const category of categories) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const categoryGroup = typeGroup[category]!;
const defaultCategory = category.length === 0;
for (const { scope, logs } of typeGroup.scopes) {
let prefix = "";
if (!defaultCategory) changelog.push(`* **${ category }:**`);
if (scope.length > 0) {
changelog.push(`* **${ scope }:**`);
const baseLine = defaultCategory ? "" : " ";
prefix = " ";
}
for (const { title, references } of categoryGroup) {
let log = `${ baseLine }* ${ title }`;
for (const { description, references } of logs) {
let line = `${ prefix }* ${ description }`;
const links: string[] = [];
if (references.length > 0) line += ` (${ references.join(", ") })`;
for (const { pr, commit, author } of references) {
const link: string[] = [];
if (pr != null) link.push(`${ repoUrl }/pull/${ pr }`);
if (commit != null) link.push(`${ repoUrl }/commit/${ commit }`);
if (author != null) {
// eslint-disable-next-line max-depth
if (author.endsWith(APP_AUTHOR_SUFFIX)) link.push(`by [@${ author }](https://github.com/apps/${ author.slice(0, -APP_AUTHOR_SUFFIX_LENGTH) })`);
else link.push(`by @${ author }`);
}
if (link.length > 0) links.push(link.join(" "));
}
if (links.length > 0) log += ` (${ links.join(", ") })`;
changelog.push(log);
changelog.push(line);
}
}
changelog.push("");
}
return changelog;
}, []).join("\n");
return changelog.join("\n");
}
export interface ChangelogRecordI {
description: string;
references: string[];
scope: string;
type: string;
}
-84
View File
@@ -1,84 +0,0 @@
/*
* MIT License
*
* Copyright (c) 2020-2023 Ardalan Amini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
import { type GitHub } from "@actions/github/lib/utils";
import { type SemVer } from "semver";
export const COMMIT_REGEX
= /^(?<type>[^:()]*)(?:\((?<category>[^()]*?)\)|): *(?<title>.+?) *(?:\(#(?<pr>[1-9]\d*?)\)|) *(?:\[(?<flag>[^[\]]*?)]|)\s*$/;
export const APP_AUTHOR_SUFFIX = "[bot]";
export const APP_AUTHOR_SUFFIX_LENGTH = APP_AUTHOR_SUFFIX.length;
export type TypesI = Record<string, string>;
export type LogsI = Record<string, Record<string, LogI[] | undefined> | undefined>;
export interface LogI {
references: ReferenceI[];
title: string;
}
export interface ReferenceI {
author?: string | null;
commit: string | null;
pr?: string | null;
}
export interface TagInputI {
octokit: InstanceType<typeof GitHub>;
owner: string;
prerelease: boolean;
repo: string;
semver: SemVer | null;
sha: string;
}
export interface TagResultI {
name?: string;
sha?: string;
}
export interface ChangelogInputI {
inputs: ActionInputsI;
octokit: InstanceType<typeof GitHub>;
owner: string;
repo: string;
sha: string;
tagRef?: string;
}
export interface ActionInputsI {
commitTypes: TypesI;
defaultCommitType: string;
includeCommitLinks: boolean;
includeCompare: boolean;
includePRLinks: boolean;
mentionAuthors: boolean;
mentionNewContributors: boolean;
releaseName: string;
semver: boolean;
}
-73
View File
@@ -1,73 +0,0 @@
/*
* MIT License
*
* Copyright (c) 2020-2023 Ardalan Amini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
import { getBooleanInput, getInput } from "@actions/core";
import Joi from "joi";
import YAML from "yaml";
import { type ActionInputsI, type TypesI } from "./constants";
export function getToken(): string {
return getInput("github-token", { required: true });
}
export async function getInputs(): Promise<ActionInputsI> {
const commitTypes = YAML.parse(getInput("commit-types", { required: true }));
const defaultCommitType = getInput("default-commit-type", { required: true });
const releaseName = getInput("release-name", { required: true });
const mentionAuthors = getBooleanInput("mention-authors", { required: true });
const mentionNewContributors = getBooleanInput("mention-new-contributors", {
required: true,
});
const includeCompare = getBooleanInput("include-compare", { required: true });
const includePRLinks = getBooleanInput("include-pr-links", { required: true });
const includeCommitLinks = getBooleanInput("include-commit-links", { required: true });
const semver = getBooleanInput("semver", { required: true });
return Joi.object<ActionInputsI, true>()
.keys({
commitTypes: Joi.object<TypesI>()
.pattern(Joi.string(), Joi.string())
.required(),
defaultCommitType : Joi.string().required(),
releaseName : Joi.string().required(),
mentionAuthors : Joi.boolean().required(),
mentionNewContributors: Joi.boolean().required(),
includeCompare : Joi.boolean().required(),
includePRLinks : Joi.boolean().required(),
includeCommitLinks : Joi.boolean().required(),
semver : Joi.boolean().required(),
})
.validateAsync({
commitTypes,
defaultCommitType,
releaseName,
mentionAuthors,
mentionNewContributors,
includeCompare,
includePRLinks,
includeCommitLinks,
semver,
});
}
+61
View File
@@ -0,0 +1,61 @@
/*
* MIT License
*
* Copyright (c) 2020-2023 Ardalan Amini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
import { marked } from "marked";
import { includeCompareLink, mentionNewContributors, octokit, releaseName, repository } from "./utils/index.js";
export async function generateFooter(previousTagName?: string): Promise<string> {
const { owner, repo, url } = repository();
const tagName = releaseName();
const footer: string[] = [];
if (mentionNewContributors()) {
const { rest } = octokit();
const { data } = await rest.repos.generateReleaseNotes({
owner,
repo,
tag_name : tagName,
previous_tag_name: previousTagName,
});
const tokens = marked.lexer(data.body);
// eslint-disable-next-line max-len
const index = tokens.findIndex(markdownToken => markdownToken.type === "heading" && markdownToken.text === "New Contributors");
const markdownToken = tokens[index + 1];
if (markdownToken.type === "list") footer.push(`## New Contributors\n${ markdownToken.raw }\n`);
}
if (includeCompareLink() && previousTagName) footer.push(`**Full Changelog**: ${ url }/compare/${ previousTagName }...${ tagName }`);
if (footer.length > 0) footer.unshift("");
return footer.join("\n\n");
}
+11 -82
View File
@@ -23,95 +23,24 @@
*
*/
import { info, setFailed, setOutput } from "@actions/core";
import { context, getOctokit } from "@actions/github";
import { marked } from "marked";
import { parse as parseSemVer, type SemVer } from "semver";
import { generate } from "./changelog.js";
import { getInputs, getToken } from "./context.js";
import { getTagSha } from "./tag.js";
import { setFailed } from "@actions/core";
import { generateChangelog } from "./changelog.js";
import { generateFooter } from "./footer.js";
import { getTagInfo } from "./tag.js";
import { setChangelog, setPrerelease, setReleaseId } from "./utils/index.js";
async function run(): Promise<void> {
const inputs = await getInputs();
const { prerelease, releaseId, previous } = await getTagInfo();
const octokit = getOctokit(getToken());
setPrerelease(prerelease);
const {
repo: { owner, repo },
sha,
} = context;
setReleaseId(releaseId);
let semver: SemVer | null = null;
let changelog = await generateChangelog(previous?.sha);
if (inputs.semver) {
semver = parseSemVer(inputs.releaseName, {
includePrerelease: true,
} as never);
changelog += await generateFooter(previous?.name);
if (semver == null) {
setFailed(`Expected a semver compatible releaseName, got "${ inputs.releaseName }" instead.`);
return;
}
}
let prerelease = false;
let releaseId = "latest";
if (semver != null) {
prerelease = semver.prerelease.length > 0;
if (prerelease) releaseId = semver.prerelease[0] as string;
}
const { sha: tagRef, name: tagName } = await getTagSha({
octokit,
owner,
repo,
sha,
semver,
prerelease,
});
let changelog = await generate({
octokit,
owner,
repo,
sha,
tagRef,
inputs,
});
if (inputs.mentionNewContributors) {
const { data } = await octokit.rest.repos.generateReleaseNotes({
owner,
repo,
tag_name : inputs.releaseName,
previous_tag_name: tagName,
});
const tokens = marked.lexer(data.body);
const index = tokens.findIndex(token => token.type === "heading" && token.text === "New Contributors");
const token = tokens[index + 1];
if (token.type === "list") changelog += `\n\n## New Contributors\n${ token.raw }\n`;
}
if (inputs.includeCompare && tagName != null) changelog += `\n\n**Full Changelog**: https://github.com/${ owner }/${ repo }/compare/${ tagName }...${ inputs.releaseName }`;
info(`-> prerelease: ${ prerelease }`);
setOutput("prerelease", prerelease);
info(`-> release-id: ${ releaseId }`);
setOutput("release-id", releaseId);
info(`-> changelog: "${ changelog }"`);
setOutput("changelog", changelog);
setChangelog(changelog);
}
run().catch(setFailed);
+53 -21
View File
@@ -23,45 +23,77 @@
*
*/
import { parse as parseSemVer } from "semver";
import { type TagInputI, type TagResultI } from "./constants.js";
import { type SemVer } from "semver";
import { octokit, parseSemVer, releaseName, repository, semver, sha } from "./utils/index.js";
export async function getTagSha(input: TagInputI): Promise<TagResultI> {
const { octokit, owner, repo, sha, semver, prerelease } = input;
export interface TagInfoI {
prerelease: boolean;
for await (const { data } of octokit.paginate.iterator(
octokit.rest.repos.listTags,
previous?: {
name: string;
sha: string;
};
releaseId: string;
}
export async function getTagInfo(): Promise<TagInfoI> {
const { paginate, rest } = octokit();
const { owner, repo } = repository();
const info: TagInfoI = {
releaseId : "latest",
prerelease: false,
};
let semVer: SemVer | null = null;
if (semver()) {
semVer = parseSemVer();
if (semVer == null) throw new Error(`Expected a semver compatible releaseName, got "${ releaseName() }" instead.`);
info.prerelease = semVer.prerelease.length > 0;
if (info.prerelease) info.releaseId = `${ semVer.prerelease[0] }`;
}
const iterator = paginate.iterator(
rest.repos.listTags,
{
per_page: 100,
owner,
repo,
},
)) {
for (const {
name,
commit: { sha: tagSha },
} of data) {
if (sha === tagSha) continue;
);
if (semver == null) {
return {
sha: tagSha,
loop: for await (const { data } of iterator) {
for (const { name, commit } of data) {
if (sha() === commit.sha) continue;
if (semVer == null) {
info.previous = {
name,
sha: commit.sha,
};
break loop;
}
const tagSemver = parseSemVer(name, { includePrerelease: true } as never);
const version = parseSemVer(name);
if (tagSemver == null || semver.compare(tagSemver) <= 0) continue;
if (version == null || semVer.compare(version) <= 0) continue;
if (tagSemver.prerelease.length > 0 && !prerelease) continue;
if (version.prerelease.length > 0 && !info.prerelease) continue;
return {
sha: tagSha,
info.previous = {
name,
sha: commit.sha,
};
break loop;
}
}
return {};
return info;
}
+34
View File
@@ -0,0 +1,34 @@
/*
* MIT License
*
* Copyright (c) 2023 Ardalan Amini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
import { getBooleanInput } from "@actions/core";
import { cache } from "./cache.js";
export function booleanInput(
name: string,
required = true,
): boolean {
return cache(name, () => getBooleanInput(name, { required }));
}
+32
View File
@@ -0,0 +1,32 @@
/*
* MIT License
*
* Copyright (c) 2023 Ardalan Amini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
const CACHE = (new Map);
export function cache<T>(key: string, value: () => T, overwrite = false): T {
if (!CACHE.has(key) || overwrite) CACHE.set(key, value());
return CACHE.get(key);
}
+36
View File
@@ -0,0 +1,36 @@
/*
* MIT License
*
* Copyright (c) 2023 Ardalan Amini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
export * from "./inputs/index.js";
export * from "./outputs/index.js";
export * from "./boolean-input.js";
export * from "./cache.js";
export * from "./input.js";
export * from "./octokit.js";
export * from "./output.js";
export * from "./parse-commit-message.js";
export * from "./parse-semver.js";
export * from "./repository.js";
export * from "./sha.js";
+35
View File
@@ -0,0 +1,35 @@
/*
* MIT License
*
* Copyright (c) 2023 Ardalan Amini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
import { getInput } from "@actions/core";
import { cache } from "./cache.js";
export function input<T = string>(
name: string,
parser: (value: string) => T = (value): T => value as T,
required = true,
): T {
return cache(name, () => parser(getInput(name, { required })));
}
+31
View File
@@ -0,0 +1,31 @@
/*
* MIT License
*
* Copyright (c) 2023 Ardalan Amini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
import YAML from "yaml";
import { input } from "../input.js";
export function commitTypes(): Record<string, string> {
return input("commit-types", value => YAML.parse(value));
}
+30
View File
@@ -0,0 +1,30 @@
/*
* MIT License
*
* Copyright (c) 2023 Ardalan Amini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
import { input } from "../input.js";
export function defaultCommitType(): string {
return input("default-commit-type");
}
+30
View File
@@ -0,0 +1,30 @@
/*
* MIT License
*
* Copyright (c) 2023 Ardalan Amini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
import { booleanInput } from "../boolean-input.js";
export function includeCommitLinks(): boolean {
return booleanInput("include-commit-links");
}
+30
View File
@@ -0,0 +1,30 @@
/*
* MIT License
*
* Copyright (c) 2023 Ardalan Amini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
import { booleanInput } from "../boolean-input.js";
export function includeCompareLink(): boolean {
return booleanInput("include-compare");
}
+30
View File
@@ -0,0 +1,30 @@
/*
* MIT License
*
* Copyright (c) 2023 Ardalan Amini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
import { booleanInput } from "../boolean-input.js";
export function includePRLinks(): boolean {
return booleanInput("include-pr-links");
}
+35
View File
@@ -0,0 +1,35 @@
/*
* MIT License
*
* Copyright (c) 2023 Ardalan Amini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
export * from "./commit-types.js";
export * from "./default-commit-type.js";
export * from "./include-compare-link.js";
export * from "./include-commit-links.js";
export * from "./include-pr-links.js";
export * from "./mention-authors.js";
export * from "./mention-new-contributors.js";
export * from "./release-name.js";
export * from "./semver.js";
export * from "./token.js";
+30
View File
@@ -0,0 +1,30 @@
/*
* MIT License
*
* Copyright (c) 2023 Ardalan Amini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
import { booleanInput } from "../boolean-input.js";
export function mentionAuthors(): boolean {
return booleanInput("mention-authors");
}
@@ -0,0 +1,30 @@
/*
* MIT License
*
* Copyright (c) 2023 Ardalan Amini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
import { booleanInput } from "../boolean-input.js";
export function mentionNewContributors(): boolean {
return booleanInput("mention-new-contributors");
}
+30
View File
@@ -0,0 +1,30 @@
/*
* MIT License
*
* Copyright (c) 2023 Ardalan Amini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
import { input } from "../input.js";
export function releaseName(): string {
return input("release-name");
}
+30
View File
@@ -0,0 +1,30 @@
/*
* MIT License
*
* Copyright (c) 2023 Ardalan Amini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
import { booleanInput } from "../boolean-input.js";
export function semver(): boolean {
return booleanInput("semver");
}
+30
View File
@@ -0,0 +1,30 @@
/*
* MIT License
*
* Copyright (c) 2023 Ardalan Amini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
import { input } from "../input.js";
export function token(): string {
return input("github-token");
}
+33
View File
@@ -0,0 +1,33 @@
/*
* MIT License
*
* Copyright (c) 2023 Ardalan Amini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
import { getOctokit } from "@actions/github";
import { type GitHub } from "@actions/github/lib/utils.js";
import { cache } from "./cache.js";
import { token } from "./inputs/index.js";
export function octokit(): InstanceType<typeof GitHub> {
return cache("octokit", () => getOctokit(token()));
}
+32
View File
@@ -0,0 +1,32 @@
/*
* MIT License
*
* Copyright (c) 2023 Ardalan Amini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
import { info, setOutput } from "@actions/core";
export function output(name: string, value: unknown): void {
info(`output -> ${ name }: ${ value }`);
setOutput(name, value);
}
+28
View File
@@ -0,0 +1,28 @@
/*
* MIT License
*
* Copyright (c) 2023 Ardalan Amini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
export * from "./set-changelog.js";
export * from "./set-prerelease.js";
export * from "./set-release-id.js";
+30
View File
@@ -0,0 +1,30 @@
/*
* MIT License
*
* Copyright (c) 2023 Ardalan Amini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
import { output } from "../output.js";
export function setChangelog(changelog: string): void {
output("changelog", changelog);
}
+30
View File
@@ -0,0 +1,30 @@
/*
* MIT License
*
* Copyright (c) 2023 Ardalan Amini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
import { output } from "../output.js";
export function setPrerelease(prerelease: boolean): void {
output("prerelease", prerelease);
}
+30
View File
@@ -0,0 +1,30 @@
/*
* MIT License
*
* Copyright (c) 2023 Ardalan Amini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
import { output } from "../output.js";
export function setReleaseId(releaseId: string): void {
output("release-id", releaseId);
}
+30
View File
@@ -0,0 +1,30 @@
/*
* MIT License
*
* Copyright (c) 2023 Ardalan Amini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
const REGEX = /^(?<type>[^:()]*)(?:\((?<scope>[^()]*?)\)|): *(?<description>.+?) *(?:\(#(?<pr>[1-9]\d*?)\)|) *(?:\[(?<flag>[^[\]]*?)]|)\s*$/;
export function parseCommitMessage(message: string): { description?: string; flag?: string; pr?: `${ number }`; scope?: string; type?: string } {
return REGEX.exec(message)?.groups ?? {};
}
+34
View File
@@ -0,0 +1,34 @@
/*
* MIT License
*
* Copyright (c) 2023 Ardalan Amini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
import { parse, type SemVer } from "semver";
import { cache } from "./cache.js";
import { releaseName } from "./inputs/index.js";
export function parseSemVer(version = releaseName()): SemVer | null {
return cache(`semver-${ version }`, () => parse(version, { includePrerelease: true } as never));
}
export { SemVer };
+39
View File
@@ -0,0 +1,39 @@
/*
* MIT License
*
* Copyright (c) 2023 Ardalan Amini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
import { context } from "@actions/github";
import { cache } from "./cache.js";
export function repository(): { owner: string; repo: string; url: string } {
return cache("repo", () => {
const { repo: { owner, repo }, serverUrl } = context;
return {
owner,
repo,
url: `${ serverUrl }/${ owner }/${ repo }`,
};
});
}
+31
View File
@@ -0,0 +1,31 @@
/*
* MIT License
*
* Copyright (c) 2023 Ardalan Amini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
import { context } from "@actions/github";
import { cache } from "./cache.js";
export function sha(): string {
return cache("sha", () => context.sha);
}