From 937efbf12bda316cefeaa505e97e92d1e2119ffb Mon Sep 17 00:00:00 2001 From: Alejandro Ruiz Ponce Date: Thu, 5 Feb 2026 10:25:32 +0100 Subject: [PATCH] chore(monorepo): Add github actions --- .github/actions/set-npm-token/action.yml | 10 ++++++++++ .github/actions/set-npm-token/main.js | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 .github/actions/set-npm-token/action.yml create mode 100644 .github/actions/set-npm-token/main.js diff --git a/.github/actions/set-npm-token/action.yml b/.github/actions/set-npm-token/action.yml new file mode 100644 index 0000000..4ba21b6 --- /dev/null +++ b/.github/actions/set-npm-token/action.yml @@ -0,0 +1,10 @@ +# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions +name: 'Set npm token' +description: 'This action sets a publish npm token (from an env var) in the .npmrc config file to be able to publish.' +inputs: + npm-token: + description: 'npm publish token' + required: true +runs: + using: 'node16' + main: 'main.js' diff --git a/.github/actions/set-npm-token/main.js b/.github/actions/set-npm-token/main.js new file mode 100644 index 0000000..39075bb --- /dev/null +++ b/.github/actions/set-npm-token/main.js @@ -0,0 +1,24 @@ +const core = require('@actions/core'); +const fs = require('fs'); +const path = require('path'); + +const main = async () => { + const token = core.getInput('npm-token') || process.env.NPM_TOKEN; + if (!token) { + throw new Error('NPM_TOKEN env var not set'); + } + + const lines = [ + // set npm auth token with publish permission from environment + `//registry.npmjs.org/:_authToken=${token}`, + + // this allows to execute npm lifecycle scripts by root + 'unsafe-perm = true', + ]; + + fs.writeFileSync(path.join(__dirname, '..', '..', '..', '.npmrc'), lines.join('\n')); +}; + +main().catch((error) => { + core.setFailed(error.message); +});