UNPKG

xrelease

Version:

xrelease (pronounced cross-release) helps you setup automated releases for your project for any language

34 lines 1.43 kB
import { execa } from 'execa'; import { readConfig } from '../config.js'; import { minimatch } from 'minimatch'; export async function checkBranch(overrideBranch, configPath) { try { // Get current branch const { stdout: currentBranch } = await execa('git', ['rev-parse', '--abbrev-ref', 'HEAD']); // Get allowed branches from config const config = await readConfig(configPath); const allowedBranches = getAllowedBranches(config, overrideBranch); // Check if current branch matches any of the allowed patterns const isAllowed = allowedBranches.some((pattern) => pattern.includes('*') ? minimatch(currentBranch, pattern) : currentBranch === pattern); if (!isAllowed) { throw new Error(`Release must be created from one of these branches: '${allowedBranches.join("', '")}'. Current branch is '${currentBranch}'`); } } catch (error) { if (error instanceof Error) { throw error; } throw new Error('Failed to check git branch'); } } function getAllowedBranches(config, overrideBranch) { if (overrideBranch) { return [overrideBranch]; } // Support both single branch and multiple branches in config if (config.release.branches?.length) { return config.release.branches; } return [config.release.branch || 'main']; } //# sourceMappingURL=check-branch.js.map