Skip to content

Commit 7eb59c5

Browse files
authored
chore(changelog): 新增日志自动生成功能 (#61)
1 parent 9836185 commit 7eb59c5

File tree

8 files changed

+2557
-2199
lines changed

8 files changed

+2557
-2199
lines changed

.github/workflows/deploy-site.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ on:
55
branches: [main]
66
paths:
77
- 'packages/rc-ui-lib/docs/**'
8-
- 'packages/rc-ui-lib/src/**'
98

109
jobs:
1110
build-and-deploy:
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Issue Close Require
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * *'
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
issue-close-require:
12+
permissions:
13+
issues: write
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: need reproduce
17+
uses: actions-cool/issues-helper@v3
18+
with:
19+
actions: 'close-issues'
20+
labels: 'need reproduce'
21+
inactive-day: 3
22+
body: |
23+
Since the issue was labeled with `need reproduce`, but no response in 3 days. This issue will be closed. If you have any questions, you can comment and reply.
24+
25+
由于该 issue 被标记为需要复现,却 3 天未收到回应。现关闭 issue,若有任何问题,可评论回复。

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"eslint": "^8.2.0",
2727
"husky": "^7.0.4",
2828
"lint-staged": "^12.1.2",
29+
"cpy-cli": "^5.0.0",
2930
"prettier": "^2.5.0",
3031
"pretty-quick": "^3.1.1",
3132
"rimraf": "^3.0.2",

packages/rc-cli/src/commands/changelog.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const DIST_FILE = join(ROOT, './changelog.generated.md');
1212
const HEADER_TEMPLATE = join(__dirname, '../../template/changelog-header.hbs');
1313
const MAIN_TEMPLATE = join(__dirname, '../../template/changelog-main.hbs');
1414
const COMMIT_TEMPLATE = join(__dirname, '../../template/changelog-commit.hbs');
15+
const CHANGELOG_MD = join(ROOT, './docs/markdown/changelog.zh-CN.md');
1516

1617
const mainTemplate = readFileSync(MAIN_TEMPLATE, 'utf-8');
1718
const headerPartial = readFileSync(HEADER_TEMPLATE, 'utf-8');
@@ -58,6 +59,9 @@ export async function changelog(): Promise<void> {
5859
preset: 'angular',
5960
releaseCount: 2,
6061
},
62+
null,
63+
null,
64+
null,
6165
{
6266
mainTemplate,
6367
headerPartial,
@@ -66,9 +70,32 @@ export async function changelog(): Promise<void> {
6670
},
6771
)
6872
.pipe(createWriteStream(DIST_FILE))
69-
.on('close', () => {
73+
.on('close', async () => {
7074
spinner.succeed(`Changelog generated at ${slimPath(DIST_FILE)}`);
75+
await updateChangelog(spinner);
7176
resolve();
7277
});
7378
});
7479
}
80+
81+
async function updateChangelog(spinner: ora.Ora) {
82+
fse.readFile(CHANGELOG_MD, (err, data) => {
83+
if (err) throw err;
84+
85+
const content = data.toString();
86+
const regex = /## /g;
87+
const match = regex.exec(content);
88+
if (!match) {
89+
console.log('未找到更新内容');
90+
return;
91+
}
92+
const generatedText = readFileSync(DIST_FILE);
93+
const insertIndex = match.index + match[0].length + 4;
94+
const updatedContent =
95+
content.slice(0, insertIndex) + generatedText + '\r\n' + content.slice(insertIndex);
96+
fse.writeFile(CHANGELOG_MD, updatedContent, 'utf8', (err) => {
97+
if (err) throw err;
98+
spinner.succeed(`更新日志插入成功`);
99+
});
100+
});
101+
}
Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,35 @@
1-
-
2-
{{#if scope}}
3-
{{scope}}:
4-
{{~/if}}
5-
{{#if subject}}
1+
-{{#if scope}} {{scope}}:
2+
{{~/if}} {{#if subject}}
63
{{~subject}}
74
{{~else}}
85
{{~header}}
96
{{~/if}}
107
{{#if references~}}
11-
{{~#each references}}
12-
[{{~this.repository}}#{{this.issue}}]({{~@root.repoUrl}}/{{~@root.issue}}/{{this.issue}}){{/each}}
8+
{{~#each references}} [{{~this.repository}}#{{this.issue}}](
9+
{{~#if @root.repository}}
10+
{{~#if @root.host}}
11+
{{~@root.host}}/
12+
{{~/if}}
13+
{{~#if @root.owner}}
14+
{{~@root.owner}}/
15+
{{~/if}}
16+
{{~@root.repository}}
17+
{{~else}}
18+
{{~@root.repoUrl}}
19+
{{~/if}}
20+
/{{~@root.issue}}/{{this.issue}}){{/each}}
21+
{{~else}} [{{shortHash}}](
22+
{{~#if @root.repository}}
23+
{{~#if @root.host}}
24+
{{~@root.host}}/
25+
{{~/if}}
26+
{{~#if @root.owner}}
27+
{{~@root.owner}}/
28+
{{~/if}}
29+
{{~@root.repository}}
1330
{{~else}}
14-
[{{shortHash}}]({{~@root.repoUrl}}/{{~@root.commit}}/{{hash}})
15-
{{~/if}}
31+
{{~@root.repoUrl}}
32+
{{~/if}}
33+
/{{~@root.commit}}/{{hash}})
34+
{{~/if}}
35+
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
1-
### [v{{version}}]({{~@root.repoUrl}}/compare/{{previousTag}}...{{currentTag}}) `{{date}}`
1+
### [v{{version}}](
2+
{{~#if @root.repository}}
3+
{{~#if @root.host}}
4+
{{~@root.host}}/
5+
{{~/if}}
6+
{{~#if @root.owner}}
7+
{{~@root.owner}}/
8+
{{~/if}}
9+
{{~@root.repository}}
10+
{{~else}}
11+
{{~@root.repoUrl}}
12+
{{~/if}}
13+
/compare/{{previousTag}}...{{currentTag}})
14+
15+
`{{date}}`

packages/rc-ui-lib/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"lint": "rc-cli lint",
1616
"build": "rc-cli build",
1717
"type": "tsc -p tsconfig.json",
18-
"release": "cp ../../README.md ./ && rc-cli release && rm ./README.md",
18+
"release": "cpy ../../README.md . --flat && rc-cli release && rimraf ./README.md",
1919
"changelog": "rc-cli changelog",
2020
"build:site": "rc-cli build-site",
2121
"release:site": "pnpm build:site && gh-pages -d site",
@@ -82,4 +82,4 @@
8282
"lib/**/style/*",
8383
"*.less"
8484
]
85-
}
85+
}

0 commit comments

Comments
 (0)