|
| 1 | +const { execSync } = require('child_process'); |
| 2 | + |
| 3 | +// Detect current branch: GITHUB_REF_NAME (Actions) → GITHUB_REF → git |
| 4 | +function getCurrentBranch() { |
| 5 | + if (process.env.GITHUB_REF_NAME) return process.env.GITHUB_REF_NAME; |
| 6 | + if (process.env.GITHUB_REF) |
| 7 | + return process.env.GITHUB_REF.replace('refs/heads/', ''); |
| 8 | + return execSync('git rev-parse --abbrev-ref HEAD').toString().trim(); |
| 9 | +} |
| 10 | + |
| 11 | +const currentBranch = getCurrentBranch(); |
| 12 | + |
| 13 | +// Sanitize branch name for semver: replace any non-alphanumeric/hyphen char with '-' |
| 14 | +const prerelease = currentBranch |
| 15 | + .replace(/[^a-zA-Z0-9-]/g, '-') |
| 16 | + .replace(/^-+|-+$/g, ''); |
| 17 | + |
| 18 | +const isStableBranch = |
| 19 | + currentBranch === 'master' || /^\d+(\.\d+)*\.x$/.test(currentBranch); |
| 20 | +const isBetaBranch = currentBranch === 'beta'; |
| 21 | + |
| 22 | +const branches = [ |
| 23 | + 'master', |
| 24 | + { name: '+([0-9])?(.{+([0-9]),x}).x', prerelease: true }, // support branches (e.g., 1.x, 1.2.x) |
| 25 | + { name: 'beta', prerelease: 'beta' }, // explicit beta channel |
| 26 | +]; |
| 27 | + |
| 28 | +// Add current branch explicitly with a sanitized (semver-safe) prerelease identifier |
| 29 | +if (!isStableBranch && !isBetaBranch) { |
| 30 | + branches.push({ name: currentBranch, prerelease }); |
| 31 | +} |
| 32 | + |
1 | 33 | module.exports = { |
2 | | - branches: [ |
3 | | - 'master', |
4 | | - { name: '+([0-9])?(.{+([0-9]),x}).x', prerelease: true }, // support branches (e.g., 1.x, 1.2.x) |
5 | | - { name: 'beta', prerelease: true }, // explicit beta channel |
6 | | - { name: 'fix/*', prerelease: true }, // fix branches → x.x.x-fix.N |
7 | | - { name: 'feat/*', prerelease: true }, // feature branches → x.x.x-feat.N |
8 | | - ], |
| 34 | + branches, |
9 | 35 | tagFormat: '${name}-v${version}', |
10 | 36 | plugins: [ |
11 | 37 | ['@semantic-release/commit-analyzer', { preset: 'conventionalcommits' }], |
|
0 commit comments