Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/actions/set-npm-token/action.yml
Original file line number Diff line number Diff line change
@@ -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'
24 changes: 24 additions & 0 deletions .github/actions/set-npm-token/main.js
Original file line number Diff line number Diff line change
@@ -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);
});