@equinor/fusion-framework-cli
Version:
[](./LICENSE)
80 lines • 3.42 kB
JavaScript
import { resolveGithubAnnotations } from './resolve-github-annotations.js';
import { resolveDevopsAnnotations } from './resolve-devops-annotations.js';
import { version } from '../../version.js';
/**
* Resolves CI/CD environment-specific annotation variables.
*
* This function determines the current CI/CD runtime environment (GitHub Actions, Azure DevOps, or other)
* and returns a set of annotation variables relevant to that environment. These annotations are typically
* used for reporting build, test, or deployment results in a way that is compatible with the CI/CD provider's UI.
*
* @returns {Record<string, string>} An object containing annotation variables for the detected environment.
* If no known environment is detected, returns an empty object.
*/
export const resolveAnnotations = () => {
// Required annotations for manifest
const requiredAnnotations = {
cliVersion: version,
source: 'local',
reason: 'manual',
};
// Check if running in GitHub Actions environment
// If so, delegate to the GitHub-specific annotation resolver
if (process.env.GITHUB_ACTIONS) {
const annotation = resolveGithubAnnotations();
const baseAnnotations = {
...requiredAnnotations,
source: 'github',
reason: annotation.eventName,
workflow: annotation.workflow,
runId: annotation.runId,
runUrl: annotation.runUrl,
commitId: annotation.head_commit?.id,
repository: annotation.repository?.name,
repository_homepage: annotation.repository?.homepage,
repository_license: annotation.repository?.license?.name,
repository_owner: annotation.repository?.owner?.login,
repository_owner_avatar_url: annotation.repository?.owner?.avatar_url,
actor: annotation.actor,
sender_login: annotation.sender?.login,
sender_avatar_url: annotation.sender?.avatar_url,
};
if (annotation.pull_request) {
return {
...baseAnnotations,
branch: annotation.pull_request.head?.ref,
commitId: annotation.pull_request.head?.sha,
htmlUrl: annotation.pull_request.html_url,
};
}
if (annotation.release) {
return {
...baseAnnotations,
tag: annotation.release.tag_name,
htmlUrl: annotation.release.html_url,
};
}
return baseAnnotations;
}
// Check if running in Azure DevOps environment
// If so, delegate to the Azure DevOps-specific annotation resolver
if (process.env.SYSTEM_TEAMPROJECT) {
const annotations = resolveDevopsAnnotations();
return {
...requiredAnnotations,
source: 'azure_devops',
reason: annotations.reason,
repository: annotations.repository,
runId: annotations.runId,
runUrl: annotations.runUrl,
actor: annotations.actor,
branch: annotations.branch,
commitId: annotations.commitId,
workflow: annotations.pipelineName,
};
}
// Fallback: No known CI/CD environment detected
// Return required annotations indicating local build
return requiredAnnotations;
};
//# sourceMappingURL=resolve-annotations.js.map