UNPKG

@equinor/fusion-framework-cli

Version:

Command-line toolkit for developing, building, and publishing Fusion Framework applications and portal templates. Provides a unified developer experience from local development to production deployment.

99 lines 4.09 kB
import { resolveGithubAnnotations } from './resolve-github-annotations.js'; import { resolveDevopsAnnotations } from './resolve-devops-annotations.js'; import { resolveGitBranch } from './resolve-git-branch.js'; import { version } from '../../version.js'; /** * Extracts a branch name from a GitHub ref when the ref points to a branch. * * GitHub exposes refs like `refs/heads/main` for push events and `refs/tags/v1.0.0` * for tag/release events. Only branch refs should populate the manifest branch annotation. */ const resolveGithubBranch = (ref) => { if (!ref?.startsWith('refs/heads/')) { return undefined; } return ref.slice('refs/heads/'.length) || undefined; }; /** * 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 === 'true') { 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, branch: resolveGithubBranch(annotation.ref ?? process.env.GITHUB_REF), }; } // 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, branch: resolveGitBranch(), }; }; //# sourceMappingURL=resolve-annotations.js.map