-
Notifications
You must be signed in to change notification settings - Fork 0
Publishing
Guía completa para publicar nuevas versiones en NPM usando changesets.
Changesets es un sistema automático de versionado semántico. En lugar de decidir la versión manualmente:
- Tú describes los cambios en un archivo
.changeset - GitHub Actions crea automáticamente un PR de versión
- El merge del PR publica automáticamente en NPM
Desarrolla normalmente en tu rama:
git checkout -b feature/new-feature
# Edita archivos...
git add .
git commit -m "feat: agregar nueva funcionalidad"Cuando terminaste los cambios, crea un changeset:
npm run changesetSe abrirá un prompt interactivo:
? Which packages would you like to include? (Use arrow keys)
❯ @kettu/gitdb
? Which change type should this be? (Use arrow keys)
❯ patch (0.0.x) - Bug fixes
minor (0.x.0) - New features
major (x.0.0) - Breaking changes
? Please provide a summary of the changes
(Be concise - this will be used in the changelog)
❯ Add support for custom operators
Nota: Puedes crear múltiples changesets si el PR toca varias cosas.
git add .changeset/
git commit -m "chore: changeset for new feature"
git push origin feature/new-featureCuando haces push a main o develop:
- GitHub Actions detecta los archivos
.changeset - Crea automáticamente un PR llamado "chore: release version"
- El PR actualiza
package.jsonversion yCHANGELOG.md
# En GitHub:
# 1. Review el PR automático
# 2. Click "Merge pull request"GitHub Actions automáticamente:
- Ejecuta tests
- Publica en NPM
- Crea un tag Git (ej:
@kettu/gitdb@0.2.0) - Crea un Release en GitHub
Si necesitas publicar manualmente:
npm run releaseEsto:
- Corre type check y tests
- Corre build
- Incrementa versión automáticamente
- Publica en NPM
Después de npm run changeset, se crea un archivo en .changeset/:
.changeset/
├── lazy-lions-yell.md (changeset ID único)
└── config.json
---
"@kettu/gitdb": patch
---
Add support for custom WHERE operators and improve query performanceFormato:
- Primera línea después de
---:"package-name": change-type - Después: descripción del cambio (usada en changelog)
-
patch (0.0.x): Bug fixes, improvements sin cambios en API
npm run changeset # Seleccionar: patch -
minor (0.x.0): Nuevas features, backward compatible
npm run changeset # Seleccionar: minor -
major (x.0.0): Breaking changes
npm run changeset # Seleccionar: major
# 1. Arreglar bug
git checkout -b fix/null-pointer
# ... edita archivo ...
# 2. Crear changeset
npm run changeset
# Seleccionar: patch
# Describir: "Fix null pointer exception in select queries"
# 3. Push
git add . && git commit -m "fix: null pointer in queries"
git push origin fix/null-pointer
# 4. GitHub Actions automáticamente:
# - Crea PR de versión (0.1.0 → 0.1.1)
# - Espera merge
# - Publica en NPM# 1. Agregar feature
git checkout -b feat/aggregations
# ... edita archivo ...
# 2. Crear changeset
npm run changeset
# Seleccionar: minor
# Describir: "Add COUNT, SUM, AVG aggregation functions"
# 3. Push y merge
git add . && git commit -m "feat: add aggregations"
git push origin feat/aggregations
# 4. GitHub Actions automáticamente:
# - Crea PR de versión (0.1.1 → 0.2.0)
# - Publica en NPMEl archivo .changeset/config.json configura el comportamiento:
{
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "develop",
"updateInternalDependencies": "patch",
"ignore": []
}Opciones importantes:
-
baseBranch: Rama de donde hacer releases (develop) -
access: "public" para publicar en NPM público -
changelog: Cómo generar CHANGELOG.md
Necesitas configurar en GitHub Settings → Secrets:
Token de autenticación para publicar en NPM:
- Ve a https://npmjs.com → Account → Auth Tokens
- Crea un token con permisos "Publish"
- Copia el token
- En GitHub Repo → Settings → Secrets → New secret
- Nombre:
NPM_TOKEN - Valor: Pega el token
# En los workflows se usa así:
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}El archivo changesets-release.yml ejecuta:
on:
push:
branches:
- main
- develop # Detecta changesets en estas ramasEl workflow automáticamente:
- Detecta si hay archivos en
.changeset/ - Crea un PR de "chore: release version"
- El merge automáticamente publica en NPM
Después de hacer push:
- Ve al tab "Actions" en GitHub
- Busca el workflow "Release with Changesets"
- Si pasa, habrá un PR nuevo (buscable con: "chore: release")
- Review y merge el PR
Si necesitas revertir una publicación:
# Revertir commit en Git
git revert <commit-hash>
git push
# Crear changeset para rollback
npm run changeset
# Descripción: Revert version X.Y.Z - reasonProblema: Hiciste push pero el PR no aparece en 24h
Solución:
- Verifica que
.changeset/*.mdexiste - Verifica el workflow en el tab "Actions"
- Cheque los logs del workflow
Problema: El workflow falla en "Publish to NPM"
Solución:
- Verifica
NPM_TOKENen GitHub Secrets - Verifica que el token está válido (check en npmjs.com)
- Verifica permisos en
publishConfigde package.json
Problema: El changeset incrementó la versión incorrectamente
Solución:
- Elimina el PR de versión
- Elimina los archivos en
.changeset/ - Crea nuevos changesets correctos
- Un changeset por PR - Describir cambios coherentes
- Descripciones claras - Títulos que aparecerán en CHANGELOG
- No pushes version bumps - Deja que changesets lo haga
- Review el PR de versión - Verifica CHANGELOG antes de merge
- Test antes de changeset - Asegúrate que tests pasen
- Getting Started - Primeros pasos
- API Reference - Documentación completa