Skip to content

Commit

Permalink
Own changelog system
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuncion committed Dec 13, 2024
1 parent a03cbc8 commit 72a8660
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 12 deletions.
81 changes: 81 additions & 0 deletions .github/actions/generate-changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// 📂 Generate Changelog
// 📝 By: ! Tuncion#0809
// 📝 Version: 1.0.0
// 📝 Date: 13.12.2024

const fs = require("fs");
const { execSync, exec } = require("child_process");

(async () => {
const ReleaseType = process.env.RELEASE_TYPE || 'Release';

const Changelog = [];
const Contributors = {};
const LastTag = execSync(`git describe --tags --abbrev=0 HEAD^`).toString().trim();

// All Commits since last tag
const AllCommitsSinceLastTag = [];
const GitLogSinceLastTag = execSync(`git log ${LastTag}..HEAD --pretty=format:"%H|%h|%s|%an|%ae|%ad"`)
.toString()
.trim()
.split("\n");

GitLogSinceLastTag.forEach((commit) => {
const [hash, short_hash, message, author, email, date] = commit.split("|");
AllCommitsSinceLastTag.push({ hash, short_hash, message, author, email, date });
Contributors[email] = author;
});

// Whats's Changed
Changelog.push(`## What's Changed`);

const ChangedList = {
chores: [],
commits: [],
};
AllCommitsSinceLastTag.forEach((commit) => {
if (commit.message.startsWith("chore:")) {
ChangedList.chores.push(commit);
} else {
ChangedList.commits.push(commit);
};
});

// Chore
if (ChangedList.chores.length > 0) {
Changelog.push(`### Chores:`);
ChangedList.chores.forEach((commit) => {
Changelog.push(`- ${commit.short_hash}: ${commit.message} ([${commit.author}](https://github.com/${commit.author.replaceAll(' ', '%20')}))`);
});
};

// Commits
Changelog.push(`### Commits:`);
ChangedList.commits.forEach((commit) => {
Changelog.push(`- ${commit.short_hash}: ${commit.message} ([${commit.author}](https://github.com/${commit.author.replaceAll(' ', '%20')}))`);
});

// Contributor
Changelog.push(`\n## Contributors`);

for (const [email, author] of Object.entries(Contributors)) {
const response = await fetch(`https://api.github.com/users/${author}`);
if (!response.ok) continue;
const ContributorData = await response.json();
if (!ContributorData || !ContributorData.avatar_url) continue;
Changelog.push(`- [<img alt="${author}" src="${ContributorData.avatar_url}" width="20"> **${ContributorData.login}** (${ContributorData.name})](${ContributorData.html_url})`);
};
Changelog.push(`\n**Thank you for your contribution ❤️**`);

// Disclaimer
Changelog.push(`\n## Disclaimer`);

if (ReleaseType == 'Release') {
Changelog.push(`This is a **🚀 New Release** that may include experimental features or enhancements. Please review the changelog for details and test thoroughly.`);
} else {
Changelog.push(`This is a **🚨 Hotfix Release** designed to address issues. Please update to ensure optimal performance and stability.`);
};

// Save to file
fs.writeFileSync(`./changelog.md`, Changelog.join('\n'), { encoding: "utf8" });
})();
23 changes: 11 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,15 @@ jobs:
- name: Archive Files
run: node .github/actions/archive-files.js

- name: Create Release
uses: "marvinpinto/action-automatic-releases@latest"
id: auto_release
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
automatic_release_tag: v${{ env.RELEASE_VERSION }}
title: 🎅 v${{ env.RELEASE_VERSION }}
prerelease: false
files: |
${{ github.event.repository.name }}.zip
- name: Generate Changelog
run: node .github/actions/generate-changelog.js
env:
CI: false
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_TYPE: ${{ github.event.inputs.update_type }}

- name: Create release
uses: softprops/action-gh-release@v1
with:
name: "🎅 v${{ env.RELEASE_VERSION }}"
tag_name: v${{ env.RELEASE_VERSION }}
body_path: changelog.md
files: ${{ github.event.repository.name }}.zip

0 comments on commit 72a8660

Please sign in to comment.