Updates
This commit is contained in:
parent
9bb7038a07
commit
2b9c956517
28
README.md
28
README.md
@ -39,6 +39,34 @@ jobs:
|
|||||||
- run: npm test
|
- run: npm test
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Set up auth with npm:
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@master
|
||||||
|
- uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
version: '10.x'
|
||||||
|
registry-url: <registry url>
|
||||||
|
- run: npm install
|
||||||
|
- run: npm publish
|
||||||
|
env:
|
||||||
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
|
```
|
||||||
|
|
||||||
|
Set up auth with yarn:
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@master
|
||||||
|
- uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
version: '10.x'
|
||||||
|
registry-url: <registry url>
|
||||||
|
- run: npm install
|
||||||
|
- run: yarn publish
|
||||||
|
env:
|
||||||
|
YARN_TOKEN: ${{ secrets.YARN_TOKEN }}
|
||||||
|
```
|
||||||
|
|
||||||
# License
|
# License
|
||||||
|
|
||||||
The scripts and documentation in this project are released under the [MIT License](LICENSE)
|
The scripts and documentation in this project are released under the [MIT License](LICENSE)
|
||||||
|
@ -5,6 +5,8 @@ inputs:
|
|||||||
version:
|
version:
|
||||||
description: 'Version Spec of the version to use. Examples: 10.x, 10.15.1, >=10.15.0, lts'
|
description: 'Version Spec of the version to use. Examples: 10.x, 10.15.1, >=10.15.0, lts'
|
||||||
default: '10.x'
|
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.NPM_TOKEN or env.YARN_TOKEN respectively.'
|
||||||
runs:
|
runs:
|
||||||
using: 'node12'
|
using: 'node12'
|
||||||
main: 'lib/setup-node.js'
|
main: 'lib/setup-node.js'
|
||||||
|
33
lib/authutil.js
Normal file
33
lib/authutil.js
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
"use strict";
|
||||||
|
var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||||
|
result["default"] = mod;
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const fs = __importStar(require("fs"));
|
||||||
|
const os = __importStar(require("os"));
|
||||||
|
const path = __importStar(require("path"));
|
||||||
|
function configAuth(registryUrl) {
|
||||||
|
let npmrc = path.resolve(process.cwd(), '.npmrc');
|
||||||
|
let yarnrc = path.resolve(process.cwd(), '.yarnrc');
|
||||||
|
writeRegistryToFile(registryUrl, npmrc, 'NPM_TOKEN');
|
||||||
|
writeRegistryToFile(registryUrl, yarnrc, 'YARN_TOKEN');
|
||||||
|
}
|
||||||
|
exports.configAuth = configAuth;
|
||||||
|
function writeRegistryToFile(registryUrl, fileLocation, authTokenName) {
|
||||||
|
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.startsWith('registry')) {
|
||||||
|
newContents += line + os.EOL;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
newContents += 'registry=' + registryUrl + os.EOL + 'always-auth=true' + os.EOL + registryUrl.replace(/(^\w+:|^)/, '') + ':_authToken=${' + authTokenName + '}';
|
||||||
|
fs.writeFileSync(fileLocation, newContents);
|
||||||
|
}
|
@ -17,6 +17,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const core = __importStar(require("@actions/core"));
|
const core = __importStar(require("@actions/core"));
|
||||||
const installer = __importStar(require("./installer"));
|
const installer = __importStar(require("./installer"));
|
||||||
|
const auth = __importStar(require("./authutil"));
|
||||||
const path = __importStar(require("path"));
|
const path = __importStar(require("path"));
|
||||||
function run() {
|
function run() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
@ -30,6 +31,10 @@ function run() {
|
|||||||
// TODO: installer doesn't support proxy
|
// TODO: installer doesn't support proxy
|
||||||
yield installer.getNode(version);
|
yield installer.getNode(version);
|
||||||
}
|
}
|
||||||
|
const registryUrl = core.getInput('registry-url');
|
||||||
|
if (registryUrl) {
|
||||||
|
auth.configAuth(registryUrl);
|
||||||
|
}
|
||||||
// TODO: setup proxy from runner proxy config
|
// TODO: setup proxy from runner proxy config
|
||||||
const matchersPath = path.join(__dirname, '..', '.github');
|
const matchersPath = path.join(__dirname, '..', '.github');
|
||||||
console.log(`##[add-matcher]${path.join(matchersPath, 'tsc.json')}`);
|
console.log(`##[add-matcher]${path.join(matchersPath, 'tsc.json')}`);
|
||||||
|
39
src/authutil.ts
Normal file
39
src/authutil.ts
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import * as fs from 'fs';
|
||||||
|
import * as os from 'os';
|
||||||
|
import * as path from 'path';
|
||||||
|
|
||||||
|
export function configAuth(registryUrl: string) {
|
||||||
|
let npmrc: string = path.resolve(process.cwd(), '.npmrc');
|
||||||
|
let yarnrc: string = path.resolve(process.cwd(), '.yarnrc');
|
||||||
|
|
||||||
|
writeRegistryToFile(registryUrl, npmrc, 'NPM_TOKEN');
|
||||||
|
writeRegistryToFile(registryUrl, yarnrc, 'YARN_TOKEN');
|
||||||
|
}
|
||||||
|
|
||||||
|
function writeRegistryToFile(
|
||||||
|
registryUrl: string,
|
||||||
|
fileLocation: string,
|
||||||
|
authTokenName: string
|
||||||
|
) {
|
||||||
|
let newContents = '';
|
||||||
|
if (fs.existsSync(fileLocation)) {
|
||||||
|
const curContents = fs.readFileSync(fileLocation, 'utf8');
|
||||||
|
curContents.split(os.EOL).forEach((line: string) => {
|
||||||
|
// Add current contents unless they are setting the registry
|
||||||
|
if (!line.startsWith('registry')) {
|
||||||
|
newContents += line + os.EOL;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
newContents +=
|
||||||
|
'registry=' +
|
||||||
|
registryUrl +
|
||||||
|
os.EOL +
|
||||||
|
'always-auth=true' +
|
||||||
|
os.EOL +
|
||||||
|
registryUrl.replace(/(^\w+:|^)/, '') +
|
||||||
|
':_authToken=${' +
|
||||||
|
authTokenName +
|
||||||
|
'}';
|
||||||
|
fs.writeFileSync(fileLocation, newContents);
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as installer from './installer';
|
import * as installer from './installer';
|
||||||
|
import * as auth from './authutil';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
@ -14,6 +15,11 @@ async function run() {
|
|||||||
await installer.getNode(version);
|
await installer.getNode(version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const registryUrl = core.getInput('registry-url');
|
||||||
|
if (registryUrl) {
|
||||||
|
auth.configAuth(registryUrl);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: setup proxy from runner proxy config
|
// TODO: setup proxy from runner proxy config
|
||||||
const matchersPath = path.join(__dirname, '..', '.github');
|
const matchersPath = path.join(__dirname, '..', '.github');
|
||||||
console.log(`##[add-matcher]${path.join(matchersPath, 'tsc.json')}`);
|
console.log(`##[add-matcher]${path.join(matchersPath, 'tsc.json')}`);
|
||||||
|
Loading…
Reference in New Issue
Block a user