|
| 1 | +name: NPM Publish |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + release_type: |
| 7 | + description: 'Tipo de liberación' |
| 8 | + required: true |
| 9 | + default: 'Publicación desde package.json' |
| 10 | + type: choice |
| 11 | + options: |
| 12 | + - 'Publicación desde package.json' |
| 13 | + |
| 14 | +jobs: |
| 15 | + build-and-publish: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: Checkout repository |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Setup Node.js |
| 22 | + uses: actions/setup-node@v4 |
| 23 | + with: |
| 24 | + node-version: '18' |
| 25 | + registry-url: 'https://registry.npmjs.org/' |
| 26 | + |
| 27 | + - name: Get package version |
| 28 | + id: package-version |
| 29 | + run: echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV |
| 30 | + |
| 31 | + - name: Install dependencies |
| 32 | + run: npm ci |
| 33 | + |
| 34 | + - name: Run lint |
| 35 | + run: npm run lint |
| 36 | + |
| 37 | + - name: Run tests |
| 38 | + run: npm run test |
| 39 | + |
| 40 | + - name: Build package |
| 41 | + run: npm run build |
| 42 | + |
| 43 | + - name: Verify build artifacts |
| 44 | + run: | |
| 45 | + if [ ! -d "dist/cjs" ]; then |
| 46 | + echo "CommonJS build missing" |
| 47 | + exit 1 |
| 48 | + fi |
| 49 | + if [ ! -d "dist/esm" ]; then |
| 50 | + echo "ESM build missing" |
| 51 | + exit 1 |
| 52 | + fi |
| 53 | + if [ ! -d "dist/types" ]; then |
| 54 | + echo "TypeScript definitions missing" |
| 55 | + exit 1 |
| 56 | + fi |
| 57 | + |
| 58 | + - name: Publish to NPM |
| 59 | + run: npm publish --access public |
| 60 | + env: |
| 61 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 62 | + npm_config_//registry.npmjs.org/:_authToken: ${{ secrets.NPM_TOKEN }} |
| 63 | + npm_config_email: ${{ secrets.NPM_USER }} |
| 64 | + |
| 65 | + - name: Create GitHub Release |
| 66 | + uses: softprops/action-gh-release@v1 |
| 67 | + with: |
| 68 | + name: v${{ env.VERSION }} |
| 69 | + tag_name: v${{ env.VERSION }} |
| 70 | + generate_release_notes: true |
| 71 | + env: |
| 72 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments