You've already forked setup-node
mirror of
https://github.com/actions/setup-node.git
synced 2025-07-04 06:03:13 +07:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
dd2e8a486f | |||
d963e800e3 | |||
27212a1fbb | |||
78148dae50 |
30
README.md
30
README.md
@ -1,5 +1,9 @@
|
||||
# setup-node
|
||||
|
||||
<p align="left">
|
||||
<a href="https://github.com/actions/setup-node"><img alt="GitHub Actions status" src="https://github.com/actions/setup-node/workflows/Main%20workflow/badge.svg"></a>
|
||||
</p>
|
||||
|
||||
This action sets by node environment for use in actions by:
|
||||
|
||||
- optionally downloading and caching a version of node - npm by version spec and add to PATH
|
||||
@ -15,7 +19,7 @@ steps:
|
||||
- uses: actions/checkout@master
|
||||
- uses: actions/setup-node@v1
|
||||
with:
|
||||
version: '10.x'
|
||||
node-version: '10.x'
|
||||
- run: npm install
|
||||
- run: npm test
|
||||
```
|
||||
@ -34,38 +38,50 @@ jobs:
|
||||
- name: Setup node
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
version: ${{ matrix.node }}
|
||||
node-version: ${{ matrix.node }}
|
||||
- run: npm install
|
||||
- run: npm test
|
||||
```
|
||||
|
||||
Set up auth with npm:
|
||||
Publish to npmjs and GPR with npm:
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- uses: actions/setup-node@v1
|
||||
with:
|
||||
version: '10.x'
|
||||
registry-url: <registry url>
|
||||
node-version: '10.x'
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
- run: npm install
|
||||
- run: npm publish
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
- uses: actions/setup-node@v1
|
||||
with:
|
||||
registry-url: 'https://npm.pkg.github.com'
|
||||
- run: npm publish
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
```
|
||||
|
||||
Set up auth with yarn:
|
||||
Publish to npmjs and GPR with yarn:
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- uses: actions/setup-node@v1
|
||||
with:
|
||||
version: '10.x'
|
||||
node-version: '10.x'
|
||||
registry-url: <registry url>
|
||||
- run: npm install -g yarn
|
||||
- run: yarn install
|
||||
- run: yarn publish
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.YARN_TOKEN }}
|
||||
- uses: actions/setup-node@v1
|
||||
with:
|
||||
registry-url: 'https://npm.pkg.github.com'
|
||||
- run: yarn publish
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
```
|
||||
|
||||
# License
|
||||
|
11
action.yml
11
action.yml
@ -1,14 +1,17 @@
|
||||
name: 'Setup Node.js for use with actions'
|
||||
name: 'Setup Node.js environment'
|
||||
description: 'Setup a Node.js environment and add it to the PATH, additionally providing proxy support'
|
||||
author: 'GitHub'
|
||||
inputs:
|
||||
version:
|
||||
description: 'Version Spec of the version to use. Examples: 10.x, 10.15.1, >=10.15.0, lts'
|
||||
inputs:
|
||||
node-version:
|
||||
description: 'Version Spec of the version to use. Examples: 10.x, 10.15.1, >=10.15.0'
|
||||
default: '10.x'
|
||||
registry-url:
|
||||
description: 'Optional registry to set up for auth. Will set the registry in a project level .npmrc and .yarnrc file, and set up auth to read in from env.NODE_AUTH_TOKEN'
|
||||
scope:
|
||||
description: 'Optional scope for authenticating against scoped registries'
|
||||
# Deprecated option, do not use. Will not be supported after October 1, 2019
|
||||
version:
|
||||
description: 'Deprecated. Use node-version instead. Will not be supported after October 1, 2019'
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: 'lib/setup-node.js'
|
||||
|
@ -30,7 +30,15 @@ function writeRegistryToFile(registryUrl, fileLocation) {
|
||||
}
|
||||
core.debug(`Setting auth in ${fileLocation}`);
|
||||
let newContents = '';
|
||||
|
||||
if (fs.existsSync(fileLocation)) {
|
||||
const curContents = fs.readFileSync(fileLocation, 'utf8');
|
||||
curContents.split(os.EOL).forEach((line) => {
|
||||
// Add current contents unless they are setting the registry
|
||||
if (!line.toLowerCase().startsWith('registry')) {
|
||||
newContents += line + os.EOL;
|
||||
}
|
||||
});
|
||||
}
|
||||
// Remove http: or https: from front of registry.
|
||||
const authString = registryUrl.replace(/(^\w+:|^)/, '') + ':_authToken=${NODE_AUTH_TOKEN}';
|
||||
const registryString = scope
|
||||
|
@ -26,7 +26,10 @@ function run() {
|
||||
// Version is optional. If supplied, install / use from the tool cache
|
||||
// If not supplied then task is still used to setup proxy, auth, etc...
|
||||
//
|
||||
const version = core.getInput('version');
|
||||
let version = core.getInput('version');
|
||||
if (!version) {
|
||||
version = core.getInput('node-version');
|
||||
}
|
||||
if (version) {
|
||||
// TODO: installer doesn't support proxy
|
||||
yield installer.getNode(version);
|
||||
|
@ -17,7 +17,7 @@ export function configAuthentication(registryUrl: string) {
|
||||
}
|
||||
|
||||
function writeRegistryToFile(registryUrl: string, fileLocation: string) {
|
||||
let scope = core.getInput('scope');
|
||||
let scope: string = core.getInput('scope');
|
||||
if (!scope && registryUrl.indexOf('npm.pkg.github.com') > -1) {
|
||||
scope = github.context.repo.owner;
|
||||
}
|
||||
@ -37,9 +37,9 @@ function writeRegistryToFile(registryUrl: string, fileLocation: string) {
|
||||
});
|
||||
}
|
||||
// Remove http: or https: from front of registry.
|
||||
const authString =
|
||||
const authString: string =
|
||||
registryUrl.replace(/(^\w+:|^)/, '') + ':_authToken=${NODE_AUTH_TOKEN}';
|
||||
const registryString = scope
|
||||
const registryString: string = scope
|
||||
? `${scope}:registry=${registryUrl}`
|
||||
: `registry=${registryUrl}`;
|
||||
newContents += `${authString}${os.EOL}${registryString}`;
|
||||
|
@ -9,7 +9,10 @@ async function run() {
|
||||
// Version is optional. If supplied, install / use from the tool cache
|
||||
// If not supplied then task is still used to setup proxy, auth, etc...
|
||||
//
|
||||
const version = core.getInput('version');
|
||||
let version = core.getInput('version');
|
||||
if (!version) {
|
||||
version = core.getInput('node-version');
|
||||
}
|
||||
if (version) {
|
||||
// TODO: installer doesn't support proxy
|
||||
await installer.getNode(version);
|
||||
|
Reference in New Issue
Block a user