mirror of
https://code.forgejo.org/actions/setup-node.git
synced 2024-11-24 08:11:04 -05:00
Update
This commit is contained in:
parent
dd1cda5071
commit
287437bd45
4 changed files with 60 additions and 46 deletions
|
@ -1,12 +1,4 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
|
||||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
||||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
||||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
||||||
});
|
|
||||||
};
|
|
||||||
var __importStar = (this && this.__importStar) || function (mod) {
|
var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
if (mod && mod.__esModule) return mod;
|
if (mod && mod.__esModule) return mod;
|
||||||
var result = {};
|
var result = {};
|
||||||
|
@ -15,28 +7,38 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const core = __importStar(require("@actions/core"));
|
const fs = __importStar(require("fs"));
|
||||||
|
const os = __importStar(require("os"));
|
||||||
const path = __importStar(require("path"));
|
const path = __importStar(require("path"));
|
||||||
const exec = __importStar(require("@actions/exec"));
|
const core = __importStar(require("@actions/core"));
|
||||||
function configAuth(registryUrl) {
|
function configAuth(registryUrl) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
let npmrc = path.resolve(process.cwd(), '.npmrc');
|
||||||
let npmrc = path.resolve(process.cwd(), '.npmrc');
|
let yarnrc = path.resolve(process.cwd(), '.yarnrc');
|
||||||
let yarnrc = path.resolve(process.cwd(), '.yarnrc');
|
writeRegistryToFile(registryUrl, npmrc, 'NPM_TOKEN');
|
||||||
yield writeRegistryToFile(registryUrl, 'npm', 'NPM_TOKEN');
|
writeRegistryToFile(registryUrl, yarnrc, 'YARN_TOKEN');
|
||||||
// writeRegistryToFile(registryUrl, 'yarn', 'YARN_TOKEN');
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
exports.configAuth = configAuth;
|
exports.configAuth = configAuth;
|
||||||
function writeRegistryToFile(registryUrl, packageManager, authTokenName) {
|
function writeRegistryToFile(registryUrl, fileLocation, authTokenName) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
core.debug(`Setting auth in ${fileLocation}`);
|
||||||
core.debug(`Setting up ${packageManager} auth`);
|
let newContents = '';
|
||||||
yield exec.exec(`${packageManager} config set registry=${registryUrl}`);
|
if (fs.existsSync(fileLocation)) {
|
||||||
yield exec.exec(`${packageManager} config set always-auth=true`);
|
const curContents = fs.readFileSync(fileLocation, 'utf8');
|
||||||
yield exec.exec(packageManager +
|
curContents.split(os.EOL).forEach((line) => {
|
||||||
' config set ' +
|
// 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+:|^)/, '') +
|
registryUrl.replace(/(^\w+:|^)/, '') +
|
||||||
':_authToken ${' +
|
':_authToken=${' +
|
||||||
authTokenName +
|
authTokenName +
|
||||||
'}');
|
'}';
|
||||||
});
|
fs.writeFileSync(fileLocation, newContents);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ function run() {
|
||||||
}
|
}
|
||||||
const registryUrl = core.getInput('registry-url');
|
const registryUrl = core.getInput('registry-url');
|
||||||
if (registryUrl) {
|
if (registryUrl) {
|
||||||
yield auth.configAuth(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');
|
||||||
|
|
|
@ -1,29 +1,41 @@
|
||||||
import * as core from '@actions/core';
|
import * as fs from 'fs';
|
||||||
|
import * as os from 'os';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as exec from '@actions/exec';
|
import * as core from '@actions/core';
|
||||||
|
|
||||||
export async function configAuth(registryUrl: string) {
|
export function configAuth(registryUrl: string) {
|
||||||
let npmrc: string = path.resolve(process.cwd(), '.npmrc');
|
let npmrc: string = path.resolve(process.cwd(), '.npmrc');
|
||||||
let yarnrc: string = path.resolve(process.cwd(), '.yarnrc');
|
let yarnrc: string = path.resolve(process.cwd(), '.yarnrc');
|
||||||
|
|
||||||
await writeRegistryToFile(registryUrl, 'npm', 'NPM_TOKEN');
|
writeRegistryToFile(registryUrl, npmrc, 'NPM_TOKEN');
|
||||||
// writeRegistryToFile(registryUrl, 'yarn', 'YARN_TOKEN');
|
writeRegistryToFile(registryUrl, yarnrc, 'YARN_TOKEN');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function writeRegistryToFile(
|
function writeRegistryToFile(
|
||||||
registryUrl: string,
|
registryUrl: string,
|
||||||
packageManager: string,
|
fileLocation: string,
|
||||||
authTokenName: string
|
authTokenName: string
|
||||||
) {
|
) {
|
||||||
core.debug(`Setting up ${packageManager} auth`);
|
core.debug(`Setting auth in ${fileLocation}`);
|
||||||
await exec.exec(`${packageManager} config set registry=${registryUrl}`);
|
let newContents = '';
|
||||||
await exec.exec(`${packageManager} config set always-auth=true`);
|
if (fs.existsSync(fileLocation)) {
|
||||||
await exec.exec(
|
const curContents = fs.readFileSync(fileLocation, 'utf8');
|
||||||
packageManager +
|
curContents.split(os.EOL).forEach((line: string) => {
|
||||||
' config set ' +
|
// Add current contents unless they are setting the registry
|
||||||
registryUrl.replace(/(^\w+:|^)/, '') +
|
if (!line.startsWith('registry')) {
|
||||||
':_authToken ${' +
|
newContents += line + os.EOL;
|
||||||
authTokenName +
|
}
|
||||||
'}'
|
});
|
||||||
);
|
}
|
||||||
|
newContents +=
|
||||||
|
'registry=' +
|
||||||
|
registryUrl +
|
||||||
|
os.EOL +
|
||||||
|
'always-auth=true' +
|
||||||
|
os.EOL +
|
||||||
|
registryUrl.replace(/(^\w+:|^)/, '') +
|
||||||
|
':_authToken=${' +
|
||||||
|
authTokenName +
|
||||||
|
'}';
|
||||||
|
fs.writeFileSync(fileLocation, newContents);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ async function run() {
|
||||||
|
|
||||||
const registryUrl = core.getInput('registry-url');
|
const registryUrl = core.getInput('registry-url');
|
||||||
if (registryUrl) {
|
if (registryUrl) {
|
||||||
await auth.configAuth(registryUrl);
|
auth.configAuth(registryUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: setup proxy from runner proxy config
|
// TODO: setup proxy from runner proxy config
|
||||||
|
|
Loading…
Reference in a new issue