Skip to content

Commit

Permalink
build(release): set npm token via .npmrc
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Feb 8, 2024
1 parent 428768b commit 154583b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 3 additions & 1 deletion libs/semantic-release-plugin/src/prepare/gitCommit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import {type ContextWithNextRelease} from '../types';
export const gitCommit = async (context: ContextWithNextRelease): Promise<void> => {
const {env, cwd, nextRelease} = context;

await executeWithErrorHandling('git', ['add', '-A'], {cwd, env});
await executeWithErrorHandling('git', ['restore', '--staged', '.npmrc'], {cwd, env});
await executeWithErrorHandling(
'git',
['commit', '-am', `chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}`],
['commit', '-m', `chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}`],
{
cwd,
env,
Expand Down
14 changes: 6 additions & 8 deletions libs/semantic-release-plugin/src/prepare/setNpmAuth.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import {executeWithErrorHandling} from '../utils';
import path from 'node:path';
import * as fs from 'node:fs';
import {type ContextWithNextRelease} from '../types';

export const setNpmAuth = async (context: ContextWithNextRelease): Promise<void> => {
const {logger, cwd, env} = context;
const {logger, cwd} = context;

logger.log('Setting NPM token');
logger.log('Creating .npmrc');

await executeWithErrorHandling(
'npm',
['config', 'set', '//registry.npmjs.org/:_authToken', context.env.NPM_TOKEN ?? ''],
{cwd, env},
);
const filePath = path.resolve(cwd, '.npmrc');
await fs.promises.writeFile(filePath, `//registry.npmjs.org/:_authToken=${context.env.NPM_TOKEN ?? ''}`);
};

0 comments on commit 154583b

Please sign in to comment.