Skip to content

Commit

Permalink
Add action: Link to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fingerartur committed Nov 27, 2023
1 parent 3b22205 commit 4998da0
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 19 deletions.
11 changes: 11 additions & 0 deletions .github/actions/link-docs/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: 'Link to Docs'
description: 'Add fresh links to API docs to the README and package.json'

inputs:
version:
description: The SDK version
required: true

runs:
using: 'node16'
main: './linkDocs.js'
31 changes: 31 additions & 0 deletions .github/actions/link-docs/linkDocs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const fs = require('fs')
const execSync = require('child_process').execSync
const core = require('@actions/core')

const LINK_TOKEN = 'CI_REPLACE_LINK_DOCS'
const README_FILE = 'README.MD'

const version = core.getInput('version', {required: true})
const homepage = `https://players.castlabs.com/react-dom/${version}/docs/`

/**
* Set the "homepage" attribute in package.json
* @param {string} link
*/
function addLinkToPackageJson(link) {
execSync(`npm pkg set homepage=${link}`, { stdio: 'inherit' })
}

/**
* Replace token by link in the README.md file
* @param {string} link
* @param {string} token
*/
function addLinkToReadme(link, token) {
let content = fs.readFileSync(README_FILE, 'utf8')
content = content.replace(token, link)
fs.writeFileSync(README_FILE, content)
}

addLinkToReadme(homepage, LINK_TOKEN)
addLinkToPackageJson(homepage)
47 changes: 28 additions & 19 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,7 @@ jobs:
- name: Install Dependencies
run: npm ci

- name: Write NPM RC File
run: |
echo '@castlabs:registry=https://registry.npmjs.org' > .npmrc
echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' >> .npmrc
- name: Set Package Version
run: npm --no-git-tag-version --allow-same-version version ${{ env.VERSION }}

- name: Build
run: npm run build

# TODO remove the --dry-run
- name: Publish to NPM
run: npm publish --dry-run

- name: Add NPM Release Job summary
run: |
echo '### NPM Release' >> $GITHUB_STEP_SUMMARY
echo "Released version ${{ env.VERSION }} of https://www.npmjs.com/package/@castlabs/prestoplay-react-components" >> $GITHUB_STEP_SUMMARY
## Publish the API docs

- name: Build Storybook
run: npm run build-storybook
Expand All @@ -70,3 +52,30 @@ jobs:
run: |
echo '### Docs' >> $GITHUB_STEP_SUMMARY
echo "Published docs to https://players.castlabs.com/${{ env.WEB_PATH }}" >> $GITHUB_STEP_SUMMARY
## Publish the NPM package

- name: Write NPM RC File
run: |
echo '@castlabs:registry=https://registry.npmjs.org' > .npmrc
echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' >> .npmrc
- name: Set Package Version
run: npm --no-git-tag-version --allow-same-version version ${{ env.VERSION }}

- name: Link to API Docs
uses: ./.github/actions/link-docs
with:
version: ${{ env.VERSION }}

- name: Build
run: npm run build

# TODO remove the --dry-run
- name: Publish to NPM
run: npm publish --dry-run

- name: Add NPM Release Job summary
run: |
echo '### NPM Release' >> $GITHUB_STEP_SUMMARY
echo "Released version ${{ env.VERSION }} of https://www.npmjs.com/package/@castlabs/prestoplay-react-components" >> $GITHUB_STEP_SUMMARY

0 comments on commit 4998da0

Please sign in to comment.