-
Notifications
You must be signed in to change notification settings - Fork 3
100 lines (89 loc) · 3.52 KB
/
Copy pathmain.yml
File metadata and controls
100 lines (89 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: NPM Publish
on:
workflow_dispatch:
inputs:
release_type:
description: 'Tipo de liberación'
required: true
default: 'Publicación desde package.json'
type: choice
options:
- 'Publicación desde package.json'
# id-token: write habilita Trusted Publishing (OIDC) de npm, que publica sin token.
# Mientras no se dé de alta el "trusted publisher" del paquete en npmjs.com, npm usa
# el NPM_TOKEN del .npmrc que escribe setup-node. Declararlo ahora no cambia nada.
permissions:
contents: read
id-token: write
jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Node 24 trae npm >= 11.5.1, requisito de Trusted Publishing.
# Node 18 dejó de tener soporte en abril de 2025 y trae npm 10.
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '24'
registry-url: 'https://registry.npmjs.org/'
- name: Get package version
id: package-version
run: echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV
# El registry de npm responde 404 (no 401) a cualquier PUT sin credencial válida.
# Sin esta verificación, un token vencido se manifiesta 400 líneas después como un
# "E404 Not Found - PUT" que parece un problema del paquete y no de autenticación.
- name: Verify npm credentials
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
if [ -z "$NODE_AUTH_TOKEN" ]; then
echo "::error::El secret NPM_TOKEN no existe o está vacío."
exit 1
fi
if ! npm whoami; then
echo "::error::NPM_TOKEN inválido o expirado. Los granular access tokens de npm caducan: genera uno nuevo con permiso Read and write sobre el paquete y actualiza el secret NPM_TOKEN."
exit 1
fi
# Informativo: si el token es válido pero no cubre este paquete, el publish
# también devolvería 404. Aquí se ve el permiso real que trae el token.
npm access list packages || echo "No fue posible listar los permisos del token (no bloquea el publish)."
- name: Verify version is not already published
run: |
if npm view "$(node -p "require('./package.json').name")@${VERSION}" version > /dev/null 2>&1; then
echo "::error::La versión ${VERSION} ya está publicada en npm. Incrementa la versión en package.json."
exit 1
fi
echo "La versión ${VERSION} está libre."
- name: Install dependencies
run: npm ci
- name: Build package
run: npm run build
- name: Verify build artifacts
run: |
if [ ! -d "dist/cjs" ]; then
echo "CommonJS build missing"
exit 1
fi
if [ ! -d "dist/esm" ]; then
echo "ESM build missing"
exit 1
fi
if [ ! -f "dist/cjs/index.d.ts" ]; then
echo "TypeScript definitions missing"
exit 1
fi
if [ ! -f "dist/cjs/package.json" ]; then
echo "CJS package.json missing"
exit 1
fi
if [ ! -f "dist/esm/package.json" ]; then
echo "ESM package.json missing"
exit 1
fi
echo "Build artifacts verified successfully"
- name: Publish to NPM
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}