mirror of
https://github.com/actions/setup-node.git
synced 2025-06-30 14:43:48 +00:00
Add auth and ci
This commit is contained in:
parent
eac926003b
commit
caa2ca642d
9 changed files with 139 additions and 17 deletions
40
lib/auth.js
Normal file
40
lib/auth.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
"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 core = __importStar(require("@actions/core"));
|
||||
const path = __importStar(require("path"));
|
||||
const fs = __importStar(require("fs"));
|
||||
const os = __importStar(require("os"));
|
||||
function setNpmrc(registryUrl, registryToken, authFile) {
|
||||
let projectNpmrc = path.resolve(process.cwd(), '.npmrc');
|
||||
if (authFile) {
|
||||
projectNpmrc = path.resolve(process.cwd(), authFile);
|
||||
}
|
||||
let newContents = '';
|
||||
if (fs.existsSync(projectNpmrc)) {
|
||||
const curContents = fs.readFileSync(projectNpmrc, '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 +
|
||||
':_authToken=${NPM_TOKEN}';
|
||||
fs.writeFileSync(projectNpmrc, newContents);
|
||||
core.exportSecret('NPM_TOKEN', registryToken);
|
||||
}
|
||||
exports.setNpmrc = setNpmrc;
|
|
@ -63,8 +63,7 @@ function getNode(versionSpec) {
|
|||
//
|
||||
// prepend the tools path. instructs the agent to prepend for future tasks
|
||||
//
|
||||
// TODO - addPath not implemented yet (this should probably actually be in core)
|
||||
// tc.addPath(toolPath);
|
||||
core.addPath(toolPath);
|
||||
});
|
||||
}
|
||||
exports.getNode = getNode;
|
||||
|
|
|
@ -16,6 +16,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const auth = __importStar(require("./auth"));
|
||||
const installer = __importStar(require("./installer"));
|
||||
function run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
|
@ -29,6 +30,12 @@ function run() {
|
|||
// TODO: installer doesn't support proxy
|
||||
yield installer.getNode(version);
|
||||
}
|
||||
const registryUrl = core.getInput('registryUrl');
|
||||
if (registryUrl) {
|
||||
const registryToken = core.getInput('registryToken', { required: true });
|
||||
const authFile = core.getInput('authFile');
|
||||
auth.setNpmrc(registryUrl, registryToken, authFile);
|
||||
}
|
||||
// TODO: setup proxy from runner proxy config
|
||||
// TODO: problem matchers registered
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue