UNPKG

@halospv3/hce.shared-config

Version:

Automate commit message quality, changelogs, and CI/CD releases. Exports a semantic-release shareable configuration deserialized from this package's '.releaserc.yml'. Shared resources for .NET projects are also distributed with this package.

100 lines (92 loc) 4.22 kB
import { getEnvVarValue } from '../utils/env.mjs'; import { isError } from '../utils/isError.mjs'; import { NugetRegistryInfo, NRIOpts, NRIOptsBase } from './NugetRegistryInfo.mjs'; // https://docs.gitlab.com/ee/user/packages/nuget_repository/ class GitlabNugetRegistryInfo extends NugetRegistryInfo { /** * The GitLab API v4 root URL. * @returns The value of the environment variable `CI_API_V4_URL`. * If that's `undefined`, 'https://gitlab.com/api/v4' is returned, instead. */ static get CI_API_V4_URL() { return getEnvVarValue('CI_API_V4_URL') ?? 'https://gitlab.com/api/v4'; } /** * CI_PROJECT_ID - If you want to publish to your GitLab server, this needs to be set to the Id of the project you want to publish to. When running in GitLab CI this is already set to the project the pipeline runs in by GitLab. * This method checks the contents of your `.env` file, if present. * @returns The value of the environment variable `CI_PROJECT_ID` or `undefined`. * @todo add URI encoded project pathname as alternative e.g. 'halospv3%2FHCE.Shared' in 'https://gitlab.com/api/v4/projects/halospv3%2FHCE.Shared' */ static get projectId() { return getEnvVarValue('CI_PROJECT_ID'); } /** * CI_PROJECT_NAMESPACE_ID * This method checks the contents of your `.env` file, if present. * @returns The value of the environment variable 'CI_PROJECT_NAMESPACE_ID' or `undefined`. */ static get ownerId() { return getEnvVarValue('CI_PROJECT_NAMESPACE_ID'); } static DefaultGitlabTokenEnvVars = Object.freeze(['GL_TOKEN', 'GITLAB_TOKEN', 'CI_JOB_TOKEN']); /** * Creates an instance of GitlabNugetRegistryInfo. * @param opts The input type of {@link GLNRIOpts.from} */ constructor(opts) { const optsOut = GLNRIOpts.from(opts); if (isError(optsOut.source)) throw optsOut.source; super(optsOut); } /** * Get the GitLab Nuget API for your project url as seen in https://docs.gitlab.com/ee/user/packages/nuget_repository/index.html#publish-a-nuget-package-by-using-cicd * ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/nuget/index.json * @returns If {@link this.projectId} is a string, a string formatted like * `${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/nuget/index.json`. * Else, {@link Error}. */ static get projectUrl() { return this.projectId ? `${this.CI_API_V4_URL}/projects/${this.projectId}/packages/nuget/index.json` : new Error('The project-type URL was specified, but one or more of the required environment variables (CI_API_V4_URL, CI_PROJECT_ID) were undefined.'); } /** * ${CI_API_V4_URL}/groups/${CI_PROJECT_NAMESPACE_ID}/-/packages/nuget/index.json * @returns If {@link ownerId} is a string, then a string formatted like * `${CI_API_V4_URL}/groups/${CI_PROJECT_NAMESPACE_ID}/-/packages/nuget/index.json`. * Else, {@link Error}. */ static get groupUrl() { return this.ownerId ? `${this.CI_API_V4_URL}/groups/${this.ownerId}/-/packages/nuget/index.json` : new Error('env.CI_PROJECT_NAMESPACE_ID must be defined to use its GitLab API endpoint!'); } } const GLNRI = GitlabNugetRegistryInfo; /** * The Arktype definition for {@link GitlabNugetRegistryInfo}'s constructor parameter. Construct an object of this type by calling {@link GLNRIOpts.from} */ const GLNRIOpts = NRIOpts.merge({ tokenEnvVars: NRIOptsBase.get('tokenEnvVars').default(() => GLNRI.DefaultGitlabTokenEnvVars), /** * The GitLab Nuget API URL to push packages to -OR- a keyword such as "group" * or "project" used to determine URL. * @default GLNRI.projectUrl * @see {@link GLNRI.projectUrl}, {@link GLNRI.groupUrl} */ // todo: change '"group" | "project"' to '"GITLAB:PROJECT" | "GITLAB:GROUP"' source: NRIOptsBase.get('source').or('"group" | "project" | Error').pipe(source => { switch (source) { case 'group': { return GLNRI.groupUrl; } case 'project': { return GLNRI.projectUrl; } default: { return source; } } }).default(() => GLNRI.projectUrl) }); export { GLNRIOpts, GitlabNugetRegistryInfo }; //# sourceMappingURL=GitlabNugetRegistryInfo.mjs.map