Merge pull request #18 from GerardoLucero/master #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish to NPM | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout código | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| cache: 'npm' | |
| - name: Instalar dependencias | |
| run: npm ci | |
| - name: Ejecutar tests | |
| run: npm test | |
| - name: Ejecutar lint | |
| run: npm run lint | |
| publish: | |
| needs: test | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/main' | |
| steps: | |
| - name: Checkout código | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| registry-url: 'https://registry.npmjs.org' | |
| cache: 'npm' | |
| - name: Instalar dependencias | |
| run: npm ci | |
| - name: Build del proyecto | |
| run: npm run build:prod | |
| - name: Verificar si la versión ya existe en NPM | |
| id: check-version | |
| run: | | |
| PACKAGE_VERSION=$(node -p "require('./package.json').version") | |
| PACKAGE_NAME=$(node -p "require('./package.json').name") | |
| if npm view "$PACKAGE_NAME@$PACKAGE_VERSION" version 2>/dev/null; then | |
| echo "exists=true" >> $GITHUB_OUTPUT | |
| echo "La versión $PACKAGE_VERSION ya existe en NPM" | |
| else | |
| echo "exists=false" >> $GITHUB_OUTPUT | |
| echo "La versión $PACKAGE_VERSION no existe, procediendo con la publicación" | |
| fi | |
| - name: Publicar a NPM | |
| if: steps.check-version.outputs.exists == 'false' | |
| run: npm publish --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Crear release en GitHub | |
| if: steps.check-version.outputs.exists == 'false' | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: v${{ steps.check-version.outputs.version }} | |
| release_name: Release v${{ steps.check-version.outputs.version }} | |
| body: | | |
| ## Cambios en esta versión | |
| - Versión actualizada con dependencias modernas | |
| - Reemplazado moment.js por dayjs (más seguro y ligero) | |
| - Tests mejorados y más completos | |
| - Documentación actualizada | |
| - Correcciones de seguridad | |
| Para instalar esta versión: | |
| ```bash | |
| npm install calcula-rfc@${{ steps.check-version.outputs.version }} | |
| ``` | |
| draft: false | |
| prerelease: false |