Skip to content

Commit

Permalink
Write .npmrc
Browse files Browse the repository at this point in the history
  • Loading branch information
fingerartur committed Nov 28, 2023
1 parent cd4c7a8 commit b45086b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
14 changes: 3 additions & 11 deletions .github/actions/apply-version/main.js
Original file line number Diff line number Diff line change
@@ -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})
Expand Down
16 changes: 15 additions & 1 deletion .github/actions/publish/main.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
}
13 changes: 13 additions & 0 deletions .github/actions/utils.js
Original file line number Diff line number Diff line change
@@ -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,
}

0 comments on commit b45086b

Please sign in to comment.