Ir al contenido

Usar el registro en CI

CI usa el mismo .npmrc (o .yarnrc.yml) que una estación de trabajo de desarrollo — la única diferencia es que el token proviene de un almacén de secretos en lugar de un archivo en disco.

  1. Genera un token específico de CI en Packages → Manage tokens llamado ci-github (o similar). Usa un token distinto por pipeline para poder revocarlos de forma independiente.
  2. Añádelo como secreto:
    • GitHub Actions → Settings del repo → Secrets and variables → Actions → PIER_NPM_TOKEN.
    • GitLab CI → Settings del proyecto → CI/CD → Variables → PIER_NPM_TOKEN (protected, masked).
name: build
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 24
- name: Configure Pier registry
run: |
cat > .npmrc <<EOF
registry=https://YOUR-PIER-HOST/registry/npm/
//YOUR-PIER-HOST/registry/npm/:_authToken=${PIER_NPM_TOKEN}
always-auth=true
EOF
env:
PIER_NPM_TOKEN: ${{ secrets.PIER_NPM_TOKEN }}
- run: npm ci
- run: npm run build

Para pnpm reemplaza npm ci por pnpm install --frozen-lockfile, y para bun por bun install --frozen-lockfile.

- name: Configure Pier registry (yarn berry)
run: |
cat > .yarnrc.yml <<EOF
npmRegistryServer: "https://YOUR-PIER-HOST/registry/npm/"
npmAuthToken: "${PIER_NPM_TOKEN}"
npmAlwaysAuth: true
nodeLinker: node-modules
EOF
env:
PIER_NPM_TOKEN: ${{ secrets.PIER_NPM_TOKEN }}
- run: corepack enable && yarn install --immutable
build:
image: node:24
before_script:
- |
cat > .npmrc <<EOF
registry=https://YOUR-PIER-HOST/registry/npm/
//YOUR-PIER-HOST/registry/npm/:_authToken=${PIER_NPM_TOKEN}
always-auth=true
EOF
script:
- npm ci
- npm run build
- name: Publish
if: startsWith(github.ref, 'refs/tags/v')
run: npm publish
env:
NPM_CONFIG_REGISTRY: https://YOUR-PIER-HOST/registry/npm/

El .npmrc escrito en el paso 2 lleva el bearer; npm publish lo recoge automáticamente.

  • Un token por pipeline. Revócalo sin tocar nada más.
  • always-auth=true es obligatorio para yarn 1; inofensivo para npm/pnpm/bun. Yarn 4 requiere npmAlwaysAuth: true en .yarnrc.yml.
  • Cachea node_modules entre ejecuciones. El proxy es rápido, pero saltarse la instalación por completo es más rápido aún — usa la caché estándar de actions/setup-node.
  • Verifica que el registro es accesible antes de instalar — un simple curl -sf https://your-pier-host/registry/npm/-/ping de una línea ahorra un confuso error de instalación de 5 minutos si Traefik o el DNS se están portando mal.