Skip to content

Commit

Permalink
feat: Include GitHub compare link in the changelog (#48)
Browse files Browse the repository at this point in the history
* feat: Include GitHub compare link in the changelog

* fix: Full Changelog link markdown position
  • Loading branch information
ardalanamini authored Apr 29, 2022
1 parent 4f2084e commit a4aa721
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion action/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion action/index.js.map

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export interface TagInputI {
prerelease: boolean;
}

export interface TagResultI {
sha?: string;
name?: string;
}

export interface ChangelogInputI {
octokit: InstanceType<typeof GitHub>;
owner: string;
Expand Down
16 changes: 10 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function run() {

if (semver != null) prerelease = semver.prerelease.length > 0;

const tagRef = await getTagSha({
const { sha: tagRef, name: tagName } = await getTagSha({
octokit,
owner,
repo,
Expand All @@ -39,7 +39,7 @@ async function run() {
prerelease,
});

const changelog = await generate({
let changelog = await generate({
octokit,
owner,
repo,
Expand All @@ -48,13 +48,17 @@ async function run() {
inputs,
});

info(changelog);

setOutput("changelog", changelog);
if (tagName != null) {
changelog += `\n\n**Full Changelog**: https://github.com/${owner}/${repo}/compare/${tagName}...${inputs.releaseName}`;
}

info(`prerelease: ${prerelease}`);
info(`-> prerelease: ${prerelease}`);

setOutput("prerelease", prerelease);

info(`-> changelog: "${changelog}"`);

setOutput("changelog", changelog);
}

run().catch(setFailed);
10 changes: 5 additions & 5 deletions src/tag.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SemVer from "semver";
import { TagInputI } from "./constants.js";
import type { TagInputI, TagResultI } from "./constants.js";

export async function getTagSha(input: TagInputI): Promise<string | undefined> {
export async function getTagSha(input: TagInputI): Promise<TagResultI> {
const { octokit, owner, repo, sha, semver, prerelease } = input;

for await (const { data } of octokit.paginate.iterator(
Expand All @@ -18,17 +18,17 @@ export async function getTagSha(input: TagInputI): Promise<string | undefined> {
} of data) {
if (sha === tagSha) continue;

if (semver == null) return tagSha;
if (semver == null) return { sha: tagSha, name };

const tagSemver = SemVer.parse(name, { includePrerelease: true });

if (tagSemver == null || semver.compare(tagSemver) <= 0) continue;

if (tagSemver.prerelease.length > 0 && !prerelease) continue;

return tagSha;
return { sha: tagSha, name };
}
}

return undefined;
return {};
}

0 comments on commit a4aa721

Please # to comment.