fix: restore correct RFC calculation code and tests #15
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: CI/CD | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| packages: write | |
| env: | |
| NODE_VERSION: '18' | |
| REGISTRY_URL: 'https://registry.npmjs.org' | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| node-version: [18, 20] | |
| steps: | |
| - name: Checkout código | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js ${{ matrix.node-version }} | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| cache: 'npm' | |
| - name: Instalar dependencias | |
| run: npm install | |
| - name: Ejecutar linter | |
| run: npm run lint --if-present | |
| - name: Ejecutar tests | |
| run: npm test | |
| - name: Ejecutar build | |
| run: npm run build --if-present | |
| 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: ${{ env.NODE_VERSION }} | |
| registry-url: ${{ env.REGISTRY_URL }} | |
| cache: 'npm' | |
| - name: Instalar dependencias | |
| run: npm install | |
| - name: Ejecutar build | |
| run: npm run build --if-present | |
| - name: Ejecutar tests | |
| run: npm test | |
| - name: Verificar si versión ya existe en NPM | |
| id: check-version | |
| run: | | |
| PACKAGE_NAME=$(node -p "require('./package.json').name") | |
| PACKAGE_VERSION=$(node -p "require('./package.json').version") | |
| echo "name=$PACKAGE_NAME" >> $GITHUB_OUTPUT | |
| echo "version=$PACKAGE_VERSION" >> $GITHUB_OUTPUT | |
| if npm view "$PACKAGE_NAME@$PACKAGE_VERSION" version 2>/dev/null; then | |
| echo "Version $PACKAGE_VERSION already exists on NPM" | |
| echo "should-publish=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "Version $PACKAGE_VERSION does not exist on NPM, will publish" | |
| echo "should-publish=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Publicar en NPM | |
| if: steps.check-version.outputs.should-publish == 'true' | |
| run: npm publish | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Crear GitHub Release | |
| if: steps.check-version.outputs.should-publish == 'true' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const { data: release } = await github.rest.repos.createRelease({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| tag_name: `v${{ steps.check-version.outputs.version }}`, | |
| name: `Release v${{ steps.check-version.outputs.version }}`, | |
| body: `## Cambios en esta versión | |
| - Versión ${{ steps.check-version.outputs.version }} publicada automáticamente | |
| - Tests pasando: ✅ | |
| - Linting pasando: ✅ | |
| - Build exitoso: ✅ | |
| Para instalar esta versión: | |
| \`\`\`bash | |
| npm install ${{ steps.check-version.outputs.name }}@${{ steps.check-version.outputs.version }} | |
| \`\`\``, | |
| draft: false, | |
| prerelease: false | |
| }); | |
| console.log(`Release created: ${release.html_url}`); |