diff --git a/.github/actions/apply-version/main.js b/.github/actions/apply-version/main.js index 7273971..9f42879 100644 --- a/.github/actions/apply-version/main.js +++ b/.github/actions/apply-version/main.js @@ -1,29 +1,21 @@ const fs = require('fs') -const path = require('path') const execSync = require('child_process').execSync const core = require('@actions/core') +const utils = require('../utils') /** * @fileoverview Replace version and links to API docs with the current/fresh * value where needed (package.json, readme, storybook intro). */ -/** - * @param {string} filepath relative to project root - * @return {string} absolute path - */ -function file(filepath) { - return path.resolve(__dirname, `../../../${filepath}`) -} - const TOKENS = { LINK_DOCS: 'CI_REPLACE_LINK_DOCS', VERSION: 'CI_REPLACE_VERSION', } const FILES = { - README: file('README.md'), - STORYBOOK_INTRO: file('story/stories/Intro.mdx'), + README: utils.file('README.md'), + STORYBOOK_INTRO: utils.file('story/stories/Intro.mdx'), } const version = core.getInput('version', {required: true}) diff --git a/.github/actions/publish/main.js b/.github/actions/publish/main.js index 84c3806..9ac152b 100644 --- a/.github/actions/publish/main.js +++ b/.github/actions/publish/main.js @@ -1,5 +1,7 @@ const execSync = require('child_process').execSync const core = require('@actions/core') +const fs = require('fs') +const utils = require('../utils') /** * @fileoverview Publish to NPM, if the version is in the beta format @@ -55,4 +57,16 @@ if (label) { } core.info(`Publishing ${type === 'beta' ? 'Beta version' : 'version'} ${version}.`) -execSync(`export NPM_TOKEN=${npmToken}; npm publish ${args.join(' ')}`, { stdio: 'inherit' }) + +const npmRcContent = ` +@castlabs:registry=https://registry.npmjs.org +//registry.npmjs.org/:_authToken=\${NPM_TOKEN} +` + +try { + fs.writeFileSync(utils.file('.npmrc'), npmRcContent) + execSync(`export NPM_TOKEN=${npmToken}; npm publish ${args.join(' ')}`, { stdio: 'inherit' }) +} catch (error) { + core.error('Failed to publish to NPM' + error) + process.exit(1) +} diff --git a/.github/actions/utils.js b/.github/actions/utils.js new file mode 100644 index 0000000..1396560 --- /dev/null +++ b/.github/actions/utils.js @@ -0,0 +1,13 @@ +const path = require('path') + +/** + * @param {string} filepath relative to project root + * @return {string} absolute path + */ +function file(filepath) { + return path.resolve(__dirname, `../../${filepath}`) +} + +module.exports = { + file, +}