From 8118e3821b88347a9293244e055a147c88972b02 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Thu, 11 May 2023 11:50:05 +0200 Subject: [PATCH 1/8] Update known authors --- scripts/generate_changelog_simple.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/generate_changelog_simple.js b/scripts/generate_changelog_simple.js index db856303982b..ab793e766a22 100644 --- a/scripts/generate_changelog_simple.js +++ b/scripts/generate_changelog_simple.js @@ -23,8 +23,8 @@ const fs = require("node:fs"); */ const knownAuthors = { "caymannava@gmail.com": "wemeetagain", - "76567250+g11tech@users.noreply.github.com": "g11tech", - "vutuyen2636@gmail.com": "tuyennhv", + "develop@g11tech.io": "g11tech", + "tuyen@chainsafe.io": "tuyennhv", "35266934+dapplion@users.noreply.github.com": "dapplion", "41898282+github-actions[bot]@users.noreply.github.com": "github-actions[bot]", "49699333+dependabot[bot]@users.noreply.github.com": "dependabot[bot]", @@ -39,6 +39,9 @@ const knownAuthors = { "ammar1lakho@gmail.com": "ammarlakho", "dadepo@gmail.com": "dadepo", "hi@enriqueortiz.dev": "Evalir", + "nflaig@protonmail.com": "nflaig", + "nazarhussain@gmail.com": "nazarhussain", + "me@matthewkeil.com": "matthewkeil", }; const fromTag = process.argv[2]; From b8b0f58bda4a174b728e5b846b73527c5880e845 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Fri, 12 May 2023 13:59:58 +0200 Subject: [PATCH 2/8] Generate changelog based on conventional commits --- scripts/generate_changelog_simple.js | 82 ++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 11 deletions(-) diff --git a/scripts/generate_changelog_simple.js b/scripts/generate_changelog_simple.js index ab793e766a22..24277a27aa83 100644 --- a/scripts/generate_changelog_simple.js +++ b/scripts/generate_changelog_simple.js @@ -12,9 +12,9 @@ const fs = require("node:fs"); // Docs // [script] // -// Exmaple +// Example // ``` -// node scripts/changelog_simple.js v0.32.0 v0.33.0 +// node scripts/generate_changelog.js v0.32.0 v0.33.0 // ``` /** @@ -52,36 +52,96 @@ if (!fromTag) throw Error("No process.argv[2]"); if (!toTag) throw Error("No process.argv[3]"); if (!outpath) throw Error("No process.argv[4]"); +/** + * @type {Record}>} + */ +const sections = { + feat: {heading: "Features", commitsByScope: {"": []}}, + fix: {heading: "Bug Fixes", commitsByScope: {"": []}}, + perf: {heading: "Performance", commitsByScope: {"": []}}, + refactor: {heading: "Refactoring", commitsByScope: {"": []}}, + deps: {heading: "Dependencies", commitsByScope: {"": []}}, + revert: {heading: "Reverts", commitsByScope: {"": []}}, + build: {heading: "Build System", commitsByScope: {"": []}}, + ci: {heading: "Continuous Integration", commitsByScope: {"": []}}, + test: {heading: "Tests", commitsByScope: {"": []}}, + style: {heading: "Styles", commitsByScope: {"": []}}, + chore: {heading: "Maintenance", commitsByScope: {"": []}}, + docs: {heading: "Documentation", commitsByScope: {"": []}}, + _: {heading: "Miscellaneous", commitsByScope: {"": []}}, +}; + const isPrCommitRg = /\(#\d+\)/; +const conventionalCommitRg = /^([a-z]+)(?:\((.*)\))?(?:(!))?: (.*)$/; const commitHashes = shell(`git log --pretty=format:"%H" ${fromTag}...${toTag}`); -let commitListStr = ""; - for (const commitHash of commitHashes.trim().split("\n")) { - const subject = shell(`git log --format='%s' ${commitHash}^!`); - if (!isPrCommitRg.test(subject)) { + const rawCommit = shell(`git log --format='%s' ${commitHash}^!`); + + if (!isPrCommitRg.test(rawCommit)) { + // Drop commits without a PR reference continue; } + const conventionalCommit = rawCommit.match(conventionalCommitRg); + if (!conventionalCommit) { + // Drop commits that do not follow conventional commit pattern + continue; + } + + const [, type, scope, _breaking, subject] = conventionalCommit; + const authorEmail = shell(`git log --format='%ae' ${commitHash}^!`); const authorName = shell(`git log --format='%an' ${commitHash}^!`); const login = getCommitAuthorLogin(commitHash, authorEmail, authorName); - commitListStr += `- ${subject} (@${login})\n`; + const formattedCommit = `- ${scope ? `**${scope}:** ` : ""}${subject} (@${login})\n`; + + // Sort commits by type and scope + // - assign each commit to section based on type + // - group commits by scope within each section + if (sections[type] != null) { + if (scope) { + if (sections[type].commitsByScope[scope] == null) { + sections[type].commitsByScope[scope] = []; + } + sections[type].commitsByScope[scope].push(formattedCommit); + } else { + sections[type].commitsByScope[""].push(formattedCommit); + } + } else { + // Commits with a type that is not defined in sections + sections._.commitsByScope[""].push(formattedCommit); + } } // Print knownAuthors to update if necessary console.log("knownAuthors", knownAuthors); -const changelog = `# Changelog +let changelog = `## Changelog [Full Changelog](https://github.com/ChainSafe/lodestar/compare/${fromTag}...${toTag}) +`; -**Merged pull requests:** +// Write sections to changelog +for (const type in sections) { + const section = sections[type]; + let hasCommits = false; + let sectionChangelog = `\n### ${section.heading}\n\n`; -${commitListStr} -`; + for (const commits of Object.values(section.commitsByScope)) { + if (commits.length > 0) { + hasCommits = true; + sectionChangelog += commits.join(""); + } + } + + if (hasCommits) { + // Only add section if it has at least one commit + changelog += sectionChangelog; + } +} // Print to console console.log(changelog); From 7b6f53285354112780f71315d69d60db718b9786 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Fri, 12 May 2023 14:02:03 +0200 Subject: [PATCH 3/8] Rename generate changelog script --- .github/workflows/publish-rc.yml | 2 +- .github/workflows/publish-stable.yml | 2 +- scripts/{generate_changelog_simple.js => generate_changelog.js} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename scripts/{generate_changelog_simple.js => generate_changelog.js} (100%) diff --git a/.github/workflows/publish-rc.yml b/.github/workflows/publish-rc.yml index 8a0890eb899c..91f3a6c518fd 100644 --- a/.github/workflows/publish-rc.yml +++ b/.github/workflows/publish-rc.yml @@ -75,7 +75,7 @@ jobs: # - name: Generate changelog - run: node scripts/generate_changelog_simple.js ${{ needs.tag.outputs.prev_tag }} ${{ needs.tag.outputs.tag }} CHANGELOG.md + run: node scripts/generate_changelog.js ${{ needs.tag.outputs.prev_tag }} ${{ needs.tag.outputs.tag }} CHANGELOG.md - name: Create Release id: create_release diff --git a/.github/workflows/publish-stable.yml b/.github/workflows/publish-stable.yml index e2bc856f3172..e6f1ab2ed281 100644 --- a/.github/workflows/publish-stable.yml +++ b/.github/workflows/publish-stable.yml @@ -81,7 +81,7 @@ jobs: # - name: Generate changelog - run: node scripts/generate_changelog_simple.js ${{ needs.tag.outputs.prev_tag }} ${{ needs.tag.outputs.tag }} CHANGELOG.md + run: node scripts/generate_changelog.js ${{ needs.tag.outputs.prev_tag }} ${{ needs.tag.outputs.tag }} CHANGELOG.md - name: Create Release id: create_release diff --git a/scripts/generate_changelog_simple.js b/scripts/generate_changelog.js similarity index 100% rename from scripts/generate_changelog_simple.js rename to scripts/generate_changelog.js From 2d4bc8f1b53aaefff877a927af1c03cd270d3326 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Fri, 12 May 2023 14:02:50 +0200 Subject: [PATCH 4/8] Update PR title checker types based on predefined sections --- .github/workflows/lint-pr-title.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint-pr-title.yml b/.github/workflows/lint-pr-title.yml index 5b2fdcaea2db..5aac4dfb49d1 100644 --- a/.github/workflows/lint-pr-title.yml +++ b/.github/workflows/lint-pr-title.yml @@ -20,7 +20,20 @@ jobs: with: # Configure which types are allowed (newline-delimited). # Default: https://github.com/commitizen/conventional-commit-types - #types: | + # Customized based on sections defined in scripts/generate_changelog.js + types: | + feat + fix + perf + refactor + deps + revert + build + ci + test + style + chore + docs # Configure which scopes are allowed (newline-delimited). # These are regex patterns auto-wrapped in `^ $`. From d5caae999fe93e9fd5a7c94ccf5c367b15d1a480 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Fri, 12 May 2023 15:58:37 +0200 Subject: [PATCH 5/8] Convert generate changelog script to ES module --- .github/workflows/lint-pr-title.yml | 2 +- .github/workflows/publish-rc.yml | 2 +- .github/workflows/publish-stable.yml | 2 +- scripts/{generate_changelog.js => generate_changelog.mjs} | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) rename scripts/{generate_changelog.js => generate_changelog.mjs} (97%) diff --git a/.github/workflows/lint-pr-title.yml b/.github/workflows/lint-pr-title.yml index 5aac4dfb49d1..52fb5197d36a 100644 --- a/.github/workflows/lint-pr-title.yml +++ b/.github/workflows/lint-pr-title.yml @@ -20,7 +20,7 @@ jobs: with: # Configure which types are allowed (newline-delimited). # Default: https://github.com/commitizen/conventional-commit-types - # Customized based on sections defined in scripts/generate_changelog.js + # Customized based on sections defined in scripts/generate_changelog.mjs types: | feat fix diff --git a/.github/workflows/publish-rc.yml b/.github/workflows/publish-rc.yml index 91f3a6c518fd..cbb8096e2f82 100644 --- a/.github/workflows/publish-rc.yml +++ b/.github/workflows/publish-rc.yml @@ -75,7 +75,7 @@ jobs: # - name: Generate changelog - run: node scripts/generate_changelog.js ${{ needs.tag.outputs.prev_tag }} ${{ needs.tag.outputs.tag }} CHANGELOG.md + run: node scripts/generate_changelog.mjs ${{ needs.tag.outputs.prev_tag }} ${{ needs.tag.outputs.tag }} CHANGELOG.md - name: Create Release id: create_release diff --git a/.github/workflows/publish-stable.yml b/.github/workflows/publish-stable.yml index e6f1ab2ed281..930d65332f05 100644 --- a/.github/workflows/publish-stable.yml +++ b/.github/workflows/publish-stable.yml @@ -81,7 +81,7 @@ jobs: # - name: Generate changelog - run: node scripts/generate_changelog.js ${{ needs.tag.outputs.prev_tag }} ${{ needs.tag.outputs.tag }} CHANGELOG.md + run: node scripts/generate_changelog.mjs ${{ needs.tag.outputs.prev_tag }} ${{ needs.tag.outputs.tag }} CHANGELOG.md - name: Create Release id: create_release diff --git a/scripts/generate_changelog.js b/scripts/generate_changelog.mjs similarity index 97% rename from scripts/generate_changelog.js rename to scripts/generate_changelog.mjs index 24277a27aa83..42e2961388b4 100644 --- a/scripts/generate_changelog.js +++ b/scripts/generate_changelog.mjs @@ -6,15 +6,15 @@ no-console */ -const {execSync} = require("node:child_process"); -const fs = require("node:fs"); +import {execSync} from "node:child_process"; +import fs from "node:fs"; // Docs // [script] // // Example // ``` -// node scripts/generate_changelog.js v0.32.0 v0.33.0 +// node scripts/generate_changelog.mjs v0.32.0 v0.33.0 // ``` /** From 3a0813e4bcee83a138dc915c41748876a99d2075 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Fri, 12 May 2023 17:29:00 +0200 Subject: [PATCH 6/8] Update order of sections --- .github/workflows/lint-pr-title.yml | 2 +- scripts/generate_changelog.mjs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint-pr-title.yml b/.github/workflows/lint-pr-title.yml index 52fb5197d36a..873343c8d799 100644 --- a/.github/workflows/lint-pr-title.yml +++ b/.github/workflows/lint-pr-title.yml @@ -26,8 +26,8 @@ jobs: fix perf refactor - deps revert + deps build ci test diff --git a/scripts/generate_changelog.mjs b/scripts/generate_changelog.mjs index 42e2961388b4..1de3ed835d1a 100644 --- a/scripts/generate_changelog.mjs +++ b/scripts/generate_changelog.mjs @@ -60,8 +60,8 @@ const sections = { fix: {heading: "Bug Fixes", commitsByScope: {"": []}}, perf: {heading: "Performance", commitsByScope: {"": []}}, refactor: {heading: "Refactoring", commitsByScope: {"": []}}, - deps: {heading: "Dependencies", commitsByScope: {"": []}}, revert: {heading: "Reverts", commitsByScope: {"": []}}, + deps: {heading: "Dependencies", commitsByScope: {"": []}}, build: {heading: "Build System", commitsByScope: {"": []}}, ci: {heading: "Continuous Integration", commitsByScope: {"": []}}, test: {heading: "Tests", commitsByScope: {"": []}}, From a9aa98f8db7ddd560a6e1eec2e3d7e3657846f89 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Mon, 15 May 2023 11:31:17 +0200 Subject: [PATCH 7/8] Update Changelog heading to h1 --- scripts/generate_changelog.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/generate_changelog.mjs b/scripts/generate_changelog.mjs index 1de3ed835d1a..c6427dbc7117 100644 --- a/scripts/generate_changelog.mjs +++ b/scripts/generate_changelog.mjs @@ -119,7 +119,7 @@ for (const commitHash of commitHashes.trim().split("\n")) { // Print knownAuthors to update if necessary console.log("knownAuthors", knownAuthors); -let changelog = `## Changelog +let changelog = `# Changelog [Full Changelog](https://github.com/ChainSafe/lodestar/compare/${fromTag}...${toTag}) `; From dc26df1ebe591072237821c7c8517b8a86f8c190 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Tue, 16 May 2023 10:41:59 +0200 Subject: [PATCH 8/8] Print out ignored commits with reason --- scripts/generate_changelog.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/generate_changelog.mjs b/scripts/generate_changelog.mjs index c6427dbc7117..cd809622c5ea 100644 --- a/scripts/generate_changelog.mjs +++ b/scripts/generate_changelog.mjs @@ -80,13 +80,13 @@ for (const commitHash of commitHashes.trim().split("\n")) { const rawCommit = shell(`git log --format='%s' ${commitHash}^!`); if (!isPrCommitRg.test(rawCommit)) { - // Drop commits without a PR reference + console.log(`Ignored commit "${rawCommit}" (missing PR reference)`); continue; } const conventionalCommit = rawCommit.match(conventionalCommitRg); if (!conventionalCommit) { - // Drop commits that do not follow conventional commit pattern + console.log(`Ignored commit "${rawCommit}" (not conventional commit)`); continue; }