{"id":4113,"date":"2016-07-15T14:22:48","date_gmt":"2016-07-15T22:22:48","guid":{"rendered":"https:\/\/blog.mozilla.org\/webdev\/?p=4113"},"modified":"2016-07-15T14:22:48","modified_gmt":"2016-07-15T22:22:48","slug":"auto-generating-a-changelog-from-git-history","status":"publish","type":"post","link":"https:\/\/blog.mozilla.org\/webdev\/2016\/07\/15\/auto-generating-a-changelog-from-git-history\/","title":{"rendered":"Auto-generating a changelog from git history"},"content":{"rendered":"<p>At Mozilla we share a lot of open source libraries. When you&#8217;re using someone else&#8217;s library, you might find that an upgrade breaks something in your application &#8212; but why? Glancing at the library&#8217;s changelog can help. However, manually maintaining a changelog when building features for a library can be a challenge.<\/p>\n<p>We&#8217;ve been experimenting with auto-generating a changelog from commit history itself and so far it makes changelogs easy and painless. Here&#8217;s how to set it up. These tools require <a href=\"https:\/\/nodejs.org\/en\/\">NodeJS<\/a> so it&#8217;s best suited for JavaScript libraries.<\/p>\n<p>First, you need to write commit messages in a way that allows you to extract metadata for a changelog. We use the <a href=\"https:\/\/github.com\/angular\/angular.js\/blob\/master\/CONTRIBUTING.md#commit\">Angular conventions<\/a> which specify simple prefixes like <code>feat:<\/code> for new features and <code>fix:<\/code> for bug fixes. Here&#8217;s an example of a commit message that adds a new feature:<\/p>\n<p><code>feat: Added a `--timeout` option to the `run` command<\/code><\/p>\n<p>Here&#8217;s an example of a bug fix:<\/p>\n<p><code>fix: Fixed `TypeError: runner is undefined` in the `run` command<\/code><\/p>\n<p>The nice thing about this convention is that tools such as <a href=\"https:\/\/greenkeeper.io\/\">Greenkeeper<\/a>, which sends pull requests for dependency updates, already support it.<\/p>\n<p>The first problem with this is a social one; all your contributors need to follow the convention. We chose to solve this with automation by making the tests fail if they don&#8217;t follow the conventions \ud83d\ude42 It&#8217;s also documented in our <code>CONTRIBUTING.md<\/code> file. We use the <a href=\"https:\/\/github.com\/marionebl\/conventional-changelog-lint\/\">conventional-changelog-lint<\/a> command as part of our continuous integration to trigger a test failure:<\/p>\n<p><code>conventional-changelog-lint --from master<\/code><\/p>\n<p>There was one gotcha in that <a href=\"https:\/\/travis-ci.org\/\">TravisCI<\/a> only does a shallow clone which doesn&#8217;t create a master branch. This will probably be <a href=\"https:\/\/github.com\/marionebl\/conventional-changelog-lint\/issues\/7\">fixed in the linter soon<\/a> but until then we had to add this to our <code>.travis.yml<\/code>:<\/p>\n<p><script src=\"https:\/\/gist.github.com\/kumar303\/edfc89b705fd33a5e04fb6210e519d2f.js\"><\/script><\/p>\n<p>Alright, everybody is writing semantic commits now! We can generate a changelog before each release using the <a href=\"https:\/\/github.com\/conventional-changelog\/conventional-changelog-cli\">conventional-changelog<\/a> tool. Since we adopted the Angular conventions, we run it like this before tagging to get the unreleased changes:<\/p>\n<p><code>conventional-changelog -p angular -u<\/code><\/p>\n<p>This scrapes our commit log, ignores merges, ignores chores (such as dependency updates), ignores documentation updates, and makes a Markdown list of features and fixes linked to their git commit. Example:<\/p>\n<pre>### Bug fixes\n* Fixed `TypeError: runner is undefined` in the `run` command ([abc1abcd](https:\/\/github.com\/...\/))\n\n### Features\n* Added a `--timeout` option to the `run` command ([abc1abcd](https:\/\/github.com\/...\/))<\/pre>\n<p>As you can see, we also make sure to write commit messages in past tense so that it reads more naturally as a historic changelog. You can always edit the auto-generated changelog to make it more readable though.<\/p>\n<p>The <code>conventional-changelog<\/code> tool can update a README.md file but, for us, we just paste the Markdown into our github releases so that it shows up next to each release tag.<\/p>\n<p>That&#8217;s it! There are a lot of options in the tools to customize linting commits or changelog generation.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>At Mozilla we share a lot of open source libraries. When you&#8217;re using someone else&#8217;s library, you might find that an upgrade breaks something in your application &#8212; but why? Glancing at the library&#8217;s changelog can help. However, manually maintaining &hellip; <a class=\"go\" href=\"https:\/\/blog.mozilla.org\/webdev\/2016\/07\/15\/auto-generating-a-changelog-from-git-history\/\">Continue reading<\/a><\/p>\n","protected":false},"author":293,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[288],"tags":[],"coauthors":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Auto-generating a changelog from git history - Mozilla Web Development<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blog.mozilla.org\/webdev\/2016\/07\/15\/auto-generating-a-changelog-from-git-history\/\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"kumar303\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/blog.mozilla.org\/webdev\/2016\/07\/15\/auto-generating-a-changelog-from-git-history\/\",\"url\":\"https:\/\/blog.mozilla.org\/webdev\/2016\/07\/15\/auto-generating-a-changelog-from-git-history\/\",\"name\":\"Auto-generating a changelog from git history - Mozilla Web Development\",\"isPartOf\":{\"@id\":\"https:\/\/blog.mozilla.org\/webdev\/#website\"},\"datePublished\":\"2016-07-15T22:22:48+00:00\",\"dateModified\":\"2016-07-15T22:22:48+00:00\",\"author\":{\"@id\":\"https:\/\/blog.mozilla.org\/webdev\/#\/schema\/person\/aa2b14e555e8a5fec38a51659b15e3c4\"},\"breadcrumb\":{\"@id\":\"https:\/\/blog.mozilla.org\/webdev\/2016\/07\/15\/auto-generating-a-changelog-from-git-history\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blog.mozilla.org\/webdev\/2016\/07\/15\/auto-generating-a-changelog-from-git-history\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/blog.mozilla.org\/webdev\/2016\/07\/15\/auto-generating-a-changelog-from-git-history\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/blog.mozilla.org\/webdev\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Auto-generating a changelog from git history\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/blog.mozilla.org\/webdev\/#website\",\"url\":\"https:\/\/blog.mozilla.org\/webdev\/\",\"name\":\"Mozilla Web Development\",\"description\":\"For make benefit of glorious tubes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/blog.mozilla.org\/webdev\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/blog.mozilla.org\/webdev\/#\/schema\/person\/aa2b14e555e8a5fec38a51659b15e3c4\",\"name\":\"kumar303\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/blog.mozilla.org\/webdev\/#\/schema\/person\/image\/a707ad1bf04083698e2b4a775a7492b7\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/059920b9daee1ece045f4031037ffb79?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/059920b9daee1ece045f4031037ffb79?s=96&d=mm&r=g\",\"caption\":\"kumar303\"},\"description\":\"Kumar hacks on Mozilla web services and tools for various projects, such as those supporting Firefox Add-ons. He hacks on lots of random open source projects too.\",\"sameAs\":[\"http:\/\/farmdev.com\/\",\"https:\/\/www.facebook.com\/kumar303\",\"https:\/\/x.com\/kumar303\"],\"url\":\"https:\/\/blog.mozilla.org\/webdev\/author\/kmcmillanmozilla-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Auto-generating a changelog from git history - Mozilla Web Development","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blog.mozilla.org\/webdev\/2016\/07\/15\/auto-generating-a-changelog-from-git-history\/","twitter_misc":{"Written by":"kumar303","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/blog.mozilla.org\/webdev\/2016\/07\/15\/auto-generating-a-changelog-from-git-history\/","url":"https:\/\/blog.mozilla.org\/webdev\/2016\/07\/15\/auto-generating-a-changelog-from-git-history\/","name":"Auto-generating a changelog from git history - Mozilla Web Development","isPartOf":{"@id":"https:\/\/blog.mozilla.org\/webdev\/#website"},"datePublished":"2016-07-15T22:22:48+00:00","dateModified":"2016-07-15T22:22:48+00:00","author":{"@id":"https:\/\/blog.mozilla.org\/webdev\/#\/schema\/person\/aa2b14e555e8a5fec38a51659b15e3c4"},"breadcrumb":{"@id":"https:\/\/blog.mozilla.org\/webdev\/2016\/07\/15\/auto-generating-a-changelog-from-git-history\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.mozilla.org\/webdev\/2016\/07\/15\/auto-generating-a-changelog-from-git-history\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/blog.mozilla.org\/webdev\/2016\/07\/15\/auto-generating-a-changelog-from-git-history\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blog.mozilla.org\/webdev\/"},{"@type":"ListItem","position":2,"name":"Auto-generating a changelog from git history"}]},{"@type":"WebSite","@id":"https:\/\/blog.mozilla.org\/webdev\/#website","url":"https:\/\/blog.mozilla.org\/webdev\/","name":"Mozilla Web Development","description":"For make benefit of glorious tubes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog.mozilla.org\/webdev\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blog.mozilla.org\/webdev\/#\/schema\/person\/aa2b14e555e8a5fec38a51659b15e3c4","name":"kumar303","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blog.mozilla.org\/webdev\/#\/schema\/person\/image\/a707ad1bf04083698e2b4a775a7492b7","url":"https:\/\/secure.gravatar.com\/avatar\/059920b9daee1ece045f4031037ffb79?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/059920b9daee1ece045f4031037ffb79?s=96&d=mm&r=g","caption":"kumar303"},"description":"Kumar hacks on Mozilla web services and tools for various projects, such as those supporting Firefox Add-ons. He hacks on lots of random open source projects too.","sameAs":["http:\/\/farmdev.com\/","https:\/\/www.facebook.com\/kumar303","https:\/\/x.com\/kumar303"],"url":"https:\/\/blog.mozilla.org\/webdev\/author\/kmcmillanmozilla-com\/"}]}},"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/blog.mozilla.org\/webdev\/wp-json\/wp\/v2\/posts\/4113"}],"collection":[{"href":"https:\/\/blog.mozilla.org\/webdev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mozilla.org\/webdev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/webdev\/wp-json\/wp\/v2\/users\/293"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/webdev\/wp-json\/wp\/v2\/comments?post=4113"}],"version-history":[{"count":0,"href":"https:\/\/blog.mozilla.org\/webdev\/wp-json\/wp\/v2\/posts\/4113\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mozilla.org\/webdev\/wp-json\/wp\/v2\/media?parent=4113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mozilla.org\/webdev\/wp-json\/wp\/v2\/categories?post=4113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mozilla.org\/webdev\/wp-json\/wp\/v2\/tags?post=4113"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/blog.mozilla.org\/webdev\/wp-json\/wp\/v2\/coauthors?post=4113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}