Cosa otterrai
Configurerai bump di versione automatizzati e generazione changelog guidati da Conventional Commits.
Il meccanismo
Il tooling legge i messaggi commit nel formato Conventional Commits e decide che tipo di release tagliare.
Passo 1: adottare Conventional Commits
git commit -m "feat(checkout): add Apple Pay support"
git commit -m "fix(auth): handle expired refresh tokens"
git commit -m "chore(deps): bump axios to 1.7.0"
git commit -m "feat!: drop Node 16 support
BREAKING CHANGE: minimum Node version is now 18."
Passo 2: imporre il formato
npm install --save-dev @commitlint/cli @commitlint/config-conventional husky
# commitlint.config.js
module.exports = { extends: ['@commitlint/config-conventional'] };
# .husky/commit-msg
#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"
npx --no -- commitlint --edit $1
Passo 3: installare tool di release
# .github/workflows/release-please.yml
name: release-please
on:
push:
branches: [main]
permissions:
contents: write
pull-requests: write
jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: googleapis/release-please-action@v4
with:
release-type: node
package-name: my-app
Passo 4: come funziona release-please
- Legge i commit dall'ultimo tag di release.
- Categorizza per tipo e decide la versione successiva.
- Aggiorna
CHANGELOG.mde versionepackage.json. - Apre una "release PR".
Passo 5: triggerare il workflow di publish
# .github/workflows/publish.yml
name: publish
on:
push:
tags: ['v*.*.*']
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm run build
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Passo 6: alternativa - changesets
npm install --save-dev @changesets/cli
npx changeset init
Passo 7: alternativa - semantic-release
npm install --save-dev semantic-release
# .releaserc.json
{
"branches": ["main"],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/github",
"@semantic-release/git"
]
}
Passo 8: pre-release
git checkout -b beta
git push -u origin beta
{
"branches": ["main", { "name": "beta", "prerelease": true }]
}
Passo 9: scrivere buoni messaggi commit
feat(checkout): add Apple Pay support
Implements Apple Pay via the Web Payments API. Falls back to the
existing card flow if Apple Pay is unavailable. Closes #1234.
Passo 10: gestire squash
- uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}