Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please anyone helps me to setup custom template for changelog #397

Open
MDmubarak786 opened this issue Aug 15, 2024 · 1 comment
Open

Please anyone helps me to setup custom template for changelog #397

MDmubarak786 opened this issue Aug 15, 2024 · 1 comment

Comments

@MDmubarak786
Copy link

Package.json file

{
  "name": "test",
  "version": "1.6.1",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "next": "14.2.5",
    "react": "^18",
    "react-dom": "^18"
  },
  "devDependencies": {
    "@semantic-release/changelog": "^6.0.3",
    "@semantic-release/commit-analyzer": "^13.0.0",
    "@semantic-release/exec": "^6.0.3",
    "@semantic-release/git": "^10.0.1",
    "@semantic-release/github": "^10.1.5",
    "@semantic-release/npm": "^12.0.1",
    "@semantic-release/release-notes-generator": "^14.0.1",
    "@types/node": "^20",
    "@types/react": "^18",
    "@types/react-dom": "^18",
    "commitizen": "^4.3.0",
    "conventional-changelog-conventionalcommits": "^8.0.0",
    "cz-conventional-changelog": "^3.3.0",
    "eslint": "^8",
    "eslint-config-next": "14.2.5",
    "postcss": "^8",
    "semantic-release": "^24.0.0",
    "tailwindcss": "^3.4.1",
    "typescript": "^5"
  },
  "release": {
    "plugins": [
      "@semantic-release/commit-analyzer",
      [
        "@semantic-release/release-notes-generator",
        {
          "writerOpts": {
            "mainTemplate": "./changelog-template.hbs"
          }
        }
      ],
      [
        "@semantic-release/changelog",
        {
          "changelogTitle": "# 🚀 Release Notes",
          "changelogFile": "CHANGELOG.md"
        }
      ],
      "@semantic-release/git",
      "@semantic-release/github"
    ]
  },
  "config": {
    "commitizen": {
      "path": "./node_modules/cz-conventional-changelog"
    }
  }
}

This is template file

# 🚀 Release Notes

{{#if version}}
## 📦 Version {{version}}
{{/if}}

{{#if date}}Released on: {{date}}
{{/if}}

{{#if commits}}
##  Commits

{{#each commits}}
- {{#if this.breaking}}💥 BREAKING CHANGE: {{/if}}{{#if this.type}}({{this.type}}) {{/if}}{{this.scope}}:
{{this.subject}}
{{/each}}
{{/if}}

{{#if noteGroups}}
## 📋 Notes

{{#each noteGroups}}
### {{title}}

{{#each notes}}
- {{text}}
{{/each}}

{{/each}}
{{/if}}

{{#if issues}}
## 🐛 Fixed Issues

{{#each issues}}
- {{this}}
{{/each}}
{{/if}}

{{#if merges}}
## 🔀 Merged Pull Requests

{{#each merges}}
- {{this}}
{{/each}}
{{/if}}

Please let me know what I might be missing—my template changes aren't reflecting in the changelog.

@Chagui-
Copy link

Chagui- commented Dec 20, 2024

I found that mainTemplate is not the filename, but the contents of the file. I copied this solution from somewhere else and it worked for me.

/**
 * @type {import('semantic-release').GlobalConfig}
 */
var fs = require('fs');

require.extensions['.hbs'] = function (module, filename) {
    module.exports = fs.readFileSync(filename, 'utf8');
};
mainTemplate = require('./changelog/template.hbs')
headerPartial = require('./changelog/header.hbs')
commitPartial = require('./changelog/commit.hbs')

module.exports = {
    branches: ["master"],
    plugins: [
      "@semantic-release/commit-analyzer",
      ["@semantic-release/release-notes-generator", {
        preset: "angular",
        writerOpts: {
          mainTemplate: mainTemplate,
          headerPartial: headerPartial,
          commitPartial: commitPartial,
        }
      }],
      "@semantic-release/changelog",
      "@semantic-release/git"
    ],
  };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants