Skip to content

Commit

Permalink
fix(git): 修正依照分支名稱來處理 Changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
bluelovers committed Jul 27, 2022
1 parent a1de2b0 commit d6aa08d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 16 deletions.
46 changes: 46 additions & 0 deletions lib/git/branch-info.ts
Original file line number Diff line number Diff line change
@@ -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;
}
12 changes: 9 additions & 3 deletions scripts/ci-postpublish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -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;

Expand Down
14 changes: 3 additions & 11 deletions scripts/download-original-plugin.ts
Original file line number Diff line number Diff line change
@@ -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)
})
;
10 changes: 8 additions & 2 deletions scripts/update-git-tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() =>
Expand All @@ -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}`);
Expand All @@ -31,7 +34,10 @@ export default Bluebird.resolve()
{
console.info(`更新 git tag`);

await updateRepoTag();
if (isMasterBranch)
{
await updateRepoTag();
}

return updatePluginTag(__pluginVersion)
}
Expand Down

0 comments on commit d6aa08d

Please sign in to comment.