-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b22205
commit 4998da0
Showing
3 changed files
with
70 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters