diff --git a/.github/actions/generate-changelog.js b/.github/actions/generate-changelog.js new file mode 100644 index 0000000..95950f2 --- /dev/null +++ b/.github/actions/generate-changelog.js @@ -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(`- [${author} **${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" }); +})(); \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a5dcc37..1b3d6c1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 }} \ No newline at end of file + 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 \ No newline at end of file