Aller au contenu principal
~/GiwiSoft
1280px Git logo.svg  768x321

Générer un changelog Github

Giwi 2 min de lecture JavaScript

Bon, c’est cadeau, voici un script NodeJS pour vous générer un changelog tout beau tout propre avec les commits (hors merge) entre 2 tags Github :

#!/usr/bin/env node
const { execSync } = require('child_process');
let repo = '';
let md =
`TITRE DE VOTRE CHANGELOG
---

`;
// changez 'head -n 10' pour avoir autre chose que les 10 derniers tags
let tagList = execSync('git tag --sort=-committerdate | head -n 10').toString().split('\n');
let lastTag = tagList[0];
tagList = tagList.slice(1, -1);
tagList.forEach(tag => {
md += `## ${lastTag}

`;
execSync(`git log --no-merges --date=iso --format="> + ts%ct | %s %N (*[%cN](%ce) | [view commit](${repo}/commit/%H)*)" ${tag}..${lastTag}`)
.toString().split('\n').forEach(l => {
let timestamp = /ts([0-9]+)/.exec(l);
if (timestamp) {
l = l.replace('ts' + timestamp[1], new Date(timestamp[1] * 1000).toISOString().split('T')[0].replace(/\-/gi, '/'));
}
let issue = /#([0-9]+)/.exec(l);
if (issue) {
l = l.replace('#' + issue[1], `[#${issue[1]}](${repo}/issues/${issue[1]})`);
}
md += l + '\n';
});
lastTag = tag;

});
console.log(md);

Usage :

node changelog.js > CHANGELOG.md

Alternatives modernes

git-cliff (Rust) - le plus simple

git-cliff génère un changelog à partir de l’historique git, avec un template configurable :

# Installation
cargo install git-cliff

# Usage direct
git cliff -o CHANGELOG.md

# Config personnalisée (conventional commits)
git cliff --config cliff.toml

standard-version / semantic-release (Node.js)

Ces outils automatisent le versioning sémantique + changelog :

# standard-version
npx standard-version
# ou avec npm
npx standard-version --release-as minor

# semantic-release (CI uniquement)
npx semantic-release

Ils bumpent automatiquement le numéro de version, génèrent le changelog, et taggent le commit.

Conventional Commits + git-cliff

Adoptez le format Conventional Commits et tout s’enchaîne :

git commit -m "feat: ajouter la recherche full-text"
git commit -m "fix: corriger le crash sur la page d'accueil"
git commit -m "feat(api): nouveau endpoint /users"
git commit -m "docs: mise à jour du README"

Intégration CI/CD

# .github/workflows/release.yml
on:
push:
branches: [main]
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate changelog
run: |
npx -p conventional-changelog-cli -c "conventional-changelog -p angular -i CHANGELOG.md -s"
- name: Commit changelog
run: |
git config user.name "Release Bot"
git config user.email "bot@example.com"
git add CHANGELOG.md
git commit -m "chore: update changelog"
git push

Astuce : la plupart des projets modernes utilisent git-cliff ou semantic-release. Le script NodeJS ci-dessus reste parfait si vous voulez un contrôle minimal sans dépendance supplémentaire.