Skip to content

Commit

Permalink
ci(fix): 修正 github actions 上的 git 無法正確只回傳最後一個 commit 提交的檔案變動列表
Browse files Browse the repository at this point in the history
  • Loading branch information
bluelovers committed Feb 15, 2022
1 parent cf0203e commit 5a4ceff
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ jobs:
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@master
with:
fetch-depth: 2
- uses: actions/setup-node@master
with:
node-version: 17
Expand Down
17 changes: 17 additions & 0 deletions lib/git/git-logs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { gitlog } from 'gitlog2';
import { __root } from '../../test/__root';

export function getGitLogs(number?: number)
{
number ||= 1;
return gitlog({
repo: __root,
cwd: __root,
number,
execOptions: {
// 防止 git ENOBUFS 錯誤
// https://www.cxyzjd.com/article/F_Origin/108589968
maxBuffer: 1024 * 1024 * 100,
},
})
}
12 changes: 2 additions & 10 deletions scripts/ci-postpublish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { updateChangelogByCwd } from '@yarn-tool/changelog';
import { console } from 'debug-color2';
import { crossSpawnGitSync, crossSpawnGitAsync, ISpawnGitAsyncOptions, ISpawnGitSyncOptions } from '@git-lazy/spawn';
import { opts } from '../lib/git/_config';
import { getGitLogs } from '../lib/git/git-logs';

export default Bluebird.resolve((process.env as any).GITHUB_SHA as string)
.then((from) =>
Expand All @@ -19,16 +20,7 @@ export default Bluebird.resolve((process.env as any).GITHUB_SHA as string)

//from = '2d01cffc5da15e0a34a40b40ec3b7d0cc7612dda';

let to = gitlog({
repo: __root,
cwd: __root,
number: 1,
execOptions: {
// 防止 git ENOBUFS 錯誤
// https://www.cxyzjd.com/article/F_Origin/108589968
maxBuffer: 1024 * 1024 * 100,
},
})[0].hash;
let to = getGitLogs()[0].hash;

console.log(`input`);

Expand Down
15 changes: 4 additions & 11 deletions scripts/update-git-tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,22 @@ import { gitlog } from 'gitlog2';
import micromatch, { not, match } from 'micromatch';
import { console } from 'debug-color2';
import { opts } from '../lib/git/_config';
import { getGitLogs } from '../lib/git/git-logs';

export default Bluebird.resolve()
.then(() =>
{
return gitlog({
repo: __root,
cwd: __root,
number: 1,
execOptions: {
// 防止 git ENOBUFS 錯誤
// https://www.cxyzjd.com/article/F_Origin/108589968
maxBuffer: 1024 * 1024 * 100,
},
})
return getGitLogs()
})
.then((logs) =>
{
const commit = logs[0];

const bool = commit.subject === `build(changelog): update CHANGELOG`;
const bool2 = match(commit.files, 'CHANGELOG.md').length > 0;

console.cyan.info(commit.abbrevHash, `${commit.subject}`);
console.info(`include CHANGELOG: ${bool}`);
console.info(`include CHANGELOG: ${bool} , ${bool2}`);
console.dir(commit.files.length);

if (bool)
Expand Down
3 changes: 3 additions & 0 deletions test/__root.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { join } from "path";
import { console } from 'debug-color2';
import { enableDebug } from '@git-lazy/debug';

enableDebug();

console.enabledColor = true;

Expand Down

0 comments on commit 5a4ceff

Please sign in to comment.