diff --git a/lib/git/branch-info.ts b/lib/git/branch-info.ts new file mode 100644 index 000000000..a6edf4930 --- /dev/null +++ b/lib/git/branch-info.ts @@ -0,0 +1,46 @@ +import { currentBranchName } from '@git-lazy/branch'; +import { __root } from '../../test/__root'; +import { console } from 'debug-color2'; + +export function parseVersionFromBranchName(branch: string) +{ + let m = /^(?:releases\/)?v((\d+)(?:\.(?:\d+))?)$/.exec(branch); + + if (m?.[1]) + { + return { + isVersionBranch: true as const, + version: m[1], + series: m[2], + } + } + + return { + isVersionBranch: false as const, + } +} + +export function getBranchInfo() +{ + const branchName = currentBranchName(__root); + + const isMasterBranch = branchName === 'master' || branchName === 'main'; + + const { + version, + series, + isVersionBranch, + } = parseVersionFromBranchName(branchName); + + const data = { + branchName, + isMasterBranch, + isVersionBranch, + version, + series, + }; + + console.dir(data); + + return data; +} diff --git a/scripts/ci-postpublish.ts b/scripts/ci-postpublish.ts index 977eeb296..4c5f04cff 100644 --- a/scripts/ci-postpublish.ts +++ b/scripts/ci-postpublish.ts @@ -12,6 +12,7 @@ import { __file_publish_tags_json } from '../lib/const'; import { array_unique_overwrite } from 'array-hyper-unique'; import { LF } from 'crlf-normalize'; import { getSourceInfoSync } from '../lib/build/get-source-info'; +import { getBranchInfo } from '../lib/git/branch-info'; export default Bluebird.resolve((process.env as any).GITHUB_SHA as string) .then((from) => @@ -124,9 +125,14 @@ export default Bluebird.resolve((process.env as any).GITHUB_SHA as string) if (_do) { - await updateChangelogByCwd(__root, { - type: 'independent', - }); + const { isMasterBranch } = getBranchInfo(); + + if (isMasterBranch) + { + await updateChangelogByCwd(__root, { + type: 'independent', + }); + } const __pluginVersion = getSourceInfoSync().pluginMeta.version; diff --git a/scripts/download-original-plugin.ts b/scripts/download-original-plugin.ts index b4166b64c..f3aa9d170 100644 --- a/scripts/download-original-plugin.ts +++ b/scripts/download-original-plugin.ts @@ -1,20 +1,12 @@ import { internalDownload } from '../lib/cli/internalDownload'; import Bluebird from 'bluebird'; -import { currentBranchName } from '@git-lazy/branch'; -import { __root } from '../test/__root'; +import { getBranchInfo } from '../lib/git/branch-info'; export default Bluebird.resolve() .then(() => { - let name = currentBranchName(__root); + const { series } = getBranchInfo(); - if (name?.length > 0) - { - let m = /^(?:releases\/)?v(\d+)(?:\.(?:\d+))?$/.exec(name); - - return internalDownload(m?.[1]) - } - - return internalDownload() + return internalDownload(series) }) ; diff --git a/scripts/update-git-tag.ts b/scripts/update-git-tag.ts index 16364a66a..1deddb95c 100644 --- a/scripts/update-git-tag.ts +++ b/scripts/update-git-tag.ts @@ -8,6 +8,7 @@ import { getGitLogs } from '../lib/git/git-logs'; import { join } from 'upath2'; import { updatePluginTag, updateRepoTag } from '../lib/git/git-tag'; import { getSourceInfoSync } from '../lib/build/get-source-info'; +import { getBranchInfo } from '../lib/git/branch-info'; export default Bluebird.resolve() .then(() => @@ -16,11 +17,13 @@ export default Bluebird.resolve() }) .then(async (logs) => { + const { isMasterBranch, isVersionBranch } = getBranchInfo(); + const __pluginVersion = getSourceInfoSync().pluginMeta.version; const commit = logs[0]; - const bool = commit.subject.startsWith(`build(changelog): update CHANGELOG`); + const bool = commit.subject.startsWith(`build(changelog): update CHANGELOG`) || isVersionBranch && commit.subject.startsWith(`build(release): update build`); const bool2 = match(commit.files, 'CHANGELOG.md').length > 0; console.cyan.info(commit.abbrevHash, `${commit.subject}`); @@ -31,7 +34,10 @@ export default Bluebird.resolve() { console.info(`更新 git tag`); - await updateRepoTag(); + if (isMasterBranch) + { + await updateRepoTag(); + } return updatePluginTag(__pluginVersion) }