Select Git revision
artifacts.ts
artifacts.ts 6.30 KiB
import { quote } from 'shlex';
import { join } from 'upath';
import { TEMPORARY_ERROR } from '../../../constants/error-messages';
import { logger } from '../../../logger';
import { exec } from '../../../util/exec';
import type { ExecOptions } from '../../../util/exec/types';
import {
ensureDir,
getLocalFiles,
getSiblingFileName,
outputCacheFile,
privateCacheDir,
writeLocalFile,
} from '../../../util/fs';
import { getFiles } from '../../../util/git';
import * as hostRules from '../../../util/host-rules';
import { regEx } from '../../../util/regex';
import { NugetDatasource } from '../../datasource/nuget';
import { parseRegistryUrl } from '../../datasource/nuget/common';
import type {
UpdateArtifact,
UpdateArtifactsConfig,
UpdateArtifactsResult,
} from '../types';
import {
MSBUILD_CENTRAL_FILE,
NUGET_CENTRAL_FILE,
getDependentPackageFiles,
} from './package-tree';
import { getConfiguredRegistries, getDefaultRegistries } from './util';
async function addSourceCmds(
packageFileName: string,
_config: UpdateArtifactsConfig,
nugetConfigFile: string
): Promise<string[]> {
const registries =
(await getConfiguredRegistries(packageFileName)) ?? getDefaultRegistries();
const result: string[] = [];
for (const registry of registries) {
const { password, username } = hostRules.find({
hostType: NugetDatasource.id,
url: registry.url,
});
const registryInfo = parseRegistryUrl(registry.url);
let addSourceCmd = `dotnet nuget add source ${quote(
registryInfo.feedUrl
)} --configfile ${quote(nugetConfigFile)}`;
if (registry.name) {
// Add name for registry, if known.
addSourceCmd += ` --name ${quote(registry.name)}`;
}
// Add registry credentials from host rules, if configured.
if (username) {
// Add username from host rules, if configured.
addSourceCmd += ` --username ${quote(username)}`;
}
if (password) {
// Add password from host rules, if configured.
addSourceCmd += ` --password ${quote(
password
)} --store-password-in-clear-text`;
}
result.push(addSourceCmd);
}
return result;
}
async function runDotnetRestore(
packageFileName: string,