Skip to content

Commit 177e03c

Browse files
aalonzoluclaude
andcommitted
ci: publicar a npm vía OIDC trusted publishing
El job de npm seguía usando NPM_TOKEN y fallaba con E404 en el PUT. El paquete existe, así que ese 404 era en realidad un fallo de auth: npm responde 404 en vez de 401 para no revelar si un paquete existe. Los intentos previos de OIDC (34b4441, d023630) quedaron en la rama feature/subsidio y nunca llegaron a main, así que el merge de feat/consulta-cui dejó la versión con token. Además d023630 nunca llegó a ejecutar `npm publish`: su sed apuntaba a ~/.npmrc, pero setup-node escribe el archivo en $NPM_CONFIG_USERCONFIG. - Node 24 (trae npm 11.5.1+, requerido para OIDC) y id-token: write. - Se elimina la línea _authToken que setup-node escribe siempre que hay registry-url; vacía, npm asume que ya hay auth y nunca hace el intercambio OIDC (actions/setup-node#1551). - Sin NODE_AUTH_TOKEN: cualquier valor, aun vacío, suprime OIDC. - Sin --provenance: bajo trusted publishing se genera solo. - PyPI skip-existing y NuGet --skip-duplicate para que re-publicar un tag ya publicado sea idempotente en vez de fallar. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
1 parent 4a0cf2c commit 177e03c

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

‎.github/workflows/publish.yml‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ jobs:
8484
uses: pypa/gh-action-pypi-publish@release/v1
8585
with:
8686
packages-dir: python/dist/
87+
skip-existing: true # re-running a tag must not fail on an already-published version
8788
# Alternative: use API token instead of trusted publishing
8889
# with:
8990
# password: ${{ secrets.PYPI_API_TOKEN }}
@@ -94,25 +95,43 @@ jobs:
9495
name: Publish to npm
9596
runs-on: ubuntu-latest
9697
needs: test
98+
permissions:
99+
contents: read
100+
id-token: write # required for npm OIDC trusted publishing
97101
steps:
98102
- uses: actions/checkout@v4
99103

100104
- uses: actions/setup-node@v4
101105
with:
102-
node-version: "20"
106+
node-version: "24" # npm 11.5.1+ is required for OIDC; Node 24 ships it
103107
registry-url: "https://registry.npmjs.org"
104108

109+
- name: Unblock OIDC by stripping the _authToken line
110+
# setup-node always writes `_authToken=${NODE_AUTH_TOKEN}` when registry-url is
111+
# set. With no token that expands to an empty value, npm assumes auth is already
112+
# configured, never performs the OIDC exchange, and the registry answers E404.
113+
# See actions/setup-node#1551. The file lives at NPM_CONFIG_USERCONFIG, not ~/.npmrc.
114+
run: |
115+
npmrc="${NPM_CONFIG_USERCONFIG:-$HOME/.npmrc}"
116+
if [ -f "$npmrc" ]; then
117+
sed -i '/_authToken/d' "$npmrc"
118+
echo "Stripped _authToken from $npmrc:"
119+
cat "$npmrc"
120+
else
121+
echo "No .npmrc at $npmrc — nothing to strip."
122+
fi
123+
105124
- name: Set package version from tag
106125
run: |
107126
TAG="${{ github.ref_name }}"
108127
VERSION="${TAG#v}"
109128
cd javascript && npm version "$VERSION" --no-git-tag-version --allow-same-version
110129
111-
- name: Publish to npm
130+
- name: Publish to npm (OIDC trusted publishing — no NPM_TOKEN needed)
112131
working-directory: javascript
132+
# Do NOT set NODE_AUTH_TOKEN here: any value, even empty, suppresses OIDC.
133+
# Provenance is generated automatically under trusted publishing.
113134
run: npm publish --access public
114-
env:
115-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
116135

117136
# ── 4. Publish C# SDK to NuGet ────────────────────────────────────────────
118137
publish-nuget:
@@ -155,7 +174,7 @@ jobs:
155174

156175
- name: Publish to NuGet
157176
working-directory: dotnet
158-
run: dotnet nuget push nupkgs/*.nupkg --api-key ${{ steps.nuget-login.outputs.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
177+
run: dotnet nuget push nupkgs/*.nupkg --api-key ${{ steps.nuget-login.outputs.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
159178

160179
# ── 5. Notify Packagist to update PHP SDK ─────────────────────────────────
161180
publish-packagist:

0 commit comments

Comments
 (0)