diff --git a/.github/ISSUE_TEMPLATE/1.bug_report.yml b/.github/ISSUE_TEMPLATE/1.bug_report.yml
index f319b641..2f04a921 100644
--- a/.github/ISSUE_TEMPLATE/1.bug_report.yml
+++ b/.github/ISSUE_TEMPLATE/1.bug_report.yml
@@ -15,11 +15,9 @@ body:
options:
- label: There isn't an existing issue that reports the same bug to avoid duplicates.
- label: |
- The provided information offers a [minimal reproducible example](https://github.com/Tencent/cherry-markdown/tree/main/examples) of the bug
- ([Why create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example)).
+ The provided information offers a [minimal reproducible example](https://github.com/Tencent/cherry-markdown/tree/main/examples) of the bug, ([Why create a Minimal](https://stackoverflow.com/help/minimal-reproducible-example)).
- label: |
- For [Q&A](https://github.com/Tencent/cherry-markdown/discussions/categories/q-a),
- please open a [GitHub Discussion](https://github.com/Tencent/cherry-markdown/discussions) instead.
+ For [Q&A](https://github.com/Tencent/cherry-markdown/discussions/categories/q-a), please open a [GitHub Discussion](https://github.com/Tencent/cherry-markdown/discussions) instead.
- type: input
id: version
diff --git a/.github/workflows/PR&Commit-npm_build_preview.yml b/.github/workflows/PR&Commit-npm_build_preview.yml
new file mode 100644
index 00000000..34ebb173
--- /dev/null
+++ b/.github/workflows/PR&Commit-npm_build_preview.yml
@@ -0,0 +1,208 @@
+name: PR Merge Dev NPM Preview
+
+# task:
+# 1. 仅在主仓库中运行 (done)
+# 2. 仅在pr合并时运行 (done)
+# 3. 当pr合并时,获取pr合并后的commit id (done)
+# 4. 根据commit id 修改package.json中的版本号和名称 (done)
+# 5. 发布到npm (done)
+# 6. 发布成功后,将发布的版本号和链接回复到当前pr下(done)
+# 7. 发布成功后,将发布的版本号和链接回复到本repo的相关issue中 (done)
+# 8. 修改README.md —— 提示dev版本需谨慎使用 (done)
+
+on:
+ push:
+ pull_request_target:
+ types:
+ - closed
+ paths: # 这里是用来指定哪个文件更改,才会触发的
+ - "src/**"
+ - "package.json"
+ - "types/**"
+ - "examples/**"
+
+permissions:
+ pull-requests: write
+ issues: write
+
+jobs:
+ dev-deploy:
+ # 不需要在fork仓库的pr中运行, 仅当pr合并时运行
+ if: github.repository == 'Tencent/cherry-markdown' && github.event.pull_request.merged == true
+ runs-on: ubuntu-latest
+
+ steps:
+ # 检出仓库代码
+ - name: Checkout repository
+ uses:
+ actions/checkout@v4
+
+ # 获取PR合并后的commit id 或者 push commit id
+ - name: Get Merge Commit SHA or Push Commit SHA
+ run: |
+ if [ "${{ github.event.pull_request.merged }}" == "true" ]; then
+ SHORT_SHA=$(echo "${{ github.event.pull_request.merge_commit_sha }}" | cut -c1-7)
+ echo "COMMIT_SHORT_SHA=$SHORT_SHA" >> "$GITHUB_ENV"
+ else
+ if [ -n "${{ github.event.head_commit.id }}" ]; then
+ SHORT_SHA=$(echo "${{ github.event.head_commit.id }}" | cut -c1-7)
+ echo "COMMIT_SHORT_SHA=$SHORT_SHA" >> "$GITHUB_ENV"
+ else
+ echo "Not a merged PR and no push commit found, skipping"
+ fi
+ fi
+
+ # 根据commit id 修改package.json中的版本号和名称
+ - name: dev package version and name
+ run: |
+ if [ -f package.json ]; then
+
+ # 获取当前版本号并添加 Merge Commit SHA or Push Commit SHA
+ VERSION=$(node -p "require('./package.json').version")-dev.${{ env.COMMIT_SHORT_SHA }}
+
+ # 设置环境变量
+ echo "PACKAGE_VERSION=$VERSION" >> "$GITHUB_ENV"
+ package_name="@cherry-markdown-publisher/preview-dev"
+ echo "PACKAGE_NAME=$package_name" >> "$GITHUB_ENV"
+
+ # 打印当前版本号
+ echo "Current version: $PACKAGE_VERSION"
+
+ # 修改 package.json 中的 name 和 version,并检查 scripts 中是否存在 publish 属性,如果存在则移除
+ jq --arg package_name "$package_name" --arg package_version "$VERSION" '
+ .name=$package_name |
+ .version=$package_version |
+ if .scripts.publish then del(.scripts.publish) else . end
+ ' package.json > temp.json && mv temp.json package.json
+
+ # 打印修改后的 name 和 version
+ echo "Updated package.json:"
+ cat package.json | jq '.name, .version'
+
+ echo "$PACKAGE_VERSION"
+
+ # 检查 scripts 中是否存在 publish 属性,如果存在则移除
+ if jq -e '.scripts.publish' package.json > /dev/null; then
+ jq 'del(.scripts.publish)' package.json > temp.json && mv temp.json package.json
+ fi
+
+ else
+ echo "package.json 文件不存在"
+ fi
+
+ # 重写或创建 README.md 文件
+ echo -e '

\n' > README.md
+ echo -e '# Cherry Markdown Writer\n' >> README.md
+ echo -e '> !WARNING\n This is a dev preview version of `Cherry Markdown`, please use it with caution. No responsibility for production versions.\n' >> README.md
+
+ - name: Install Node.js
+ uses: actions/setup-node@v4
+ with:
+ node-version: "18"
+ registry-url: https://registry.npmjs.org/
+
+ - name: yarn install
+ run: |
+ npm i yarn -g
+ yarn install
+
+ - name: build
+ run: yarn build
+
+ - name: npm publish
+ run: npm publish
+ env:
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
+
+ - name: Comment on related issues
+ id: get-issues
+ uses: actions/github-script@v7
+ with:
+ result-encoding: string
+ retries: 3
+ retry-exempt-status-codes: 400,401
+ script: |
+ let issueArray = [];
+
+ // 添加issue到数组并去重
+ const addIssueToArray = (newIssues) => {
+ issueArray = [...new Set([...issueArray, ...newIssues])];
+ };
+
+ // 获取issue编号并转换成数字数组
+ const getIssueRegex = (issueText) => {
+ const issueRegex = /#(\d+)/g;
+ return Array.from(issueText?.matchAll(issueRegex), match => parseInt(match[1], 10));
+ };
+
+ const comment = `谢谢您的大力支持,请安装和此相关的测试版进行极速体验:
+ \`\`\`shell
+ npm install ${process.env.PACKAGE_NAME}@${process.env.PACKAGE_VERSION}
+ \`\`\`
+ [查看npm发布版本](https://www.npmjs.com/package/${process.env.PACKAGE_NAME}/v/${process.env.PACKAGE_VERSION}),请注意这是一个开发预览版本,请谨慎使用!`;
+
+ // 发布评论到issue
+ const createComment = async (issueNumbers) => {
+ console.log('issueNumbers', issueNumbers);
+ for (const issueNumber of issueNumbers) {
+ await github.rest.issues.createComment({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ issue_number: issueNumber,
+ body: comment
+ });
+ }
+ };
+
+ try {
+ // 获取当前PR的issue信息
+ const processPullRequest = async (pull_number) => {
+ issueArray.push(pull_number);
+
+ const { data: pullRequest } = await github.rest.pulls.get({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ pull_number: pull_number
+ });
+ addIssueToArray(getIssueRegex(pullRequest.title));
+ addIssueToArray(getIssueRegex(pullRequest.body));
+
+ // 获取当前PR的issue评论信息
+ const { data: issueComments } = await github.rest.issues.listComments({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ issue_number: pull_number
+ });
+ issueComments.forEach(comment => {
+ addIssueToArray(getIssueRegex(comment.body));
+ });
+
+ // 获取当前PR的review评论信息
+ const { data: reviewComments } = await github.rest.pulls.listReviewComments({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ pull_number: pull_number
+ });
+ reviewComments.forEach(comment => {
+ addIssueToArray(getIssueRegex(comment.body));
+ });
+ };
+
+ // 获取commit信息
+ const processCommits = () => {
+ context.payload.commits.forEach(commit => {
+ addIssueToArray(getIssueRegex(commit.message));
+ });
+ };
+
+ // 判断当前PR是否有issue 或者 commit是否有issue
+ if (context.payload.pull_request) {
+ await processPullRequest(context.issue.number);
+ } else if (context.payload.commits) {
+ processCommits();
+ }
+
+ await createComment(issueArray);
+ } catch (error) {
+ console.log('error', error);
+ }
diff --git a/.github/workflows/pr-merge-dev-npm_preview.yml b/.github/workflows/pr-merge-dev-npm_preview.yml
deleted file mode 100644
index d2593cbc..00000000
--- a/.github/workflows/pr-merge-dev-npm_preview.yml
+++ /dev/null
@@ -1,202 +0,0 @@
-name: PR Merge Dev NPM Preview
-
-# task:
-# 1. 仅在主仓库中运行 (done)
-# 2. 仅在pr合并时运行 (done)
-# 3. 当pr合并时,获取pr合并后的commit id (done)
-# 4. 根据commit id 修改package.json中的版本号和名称 (done)
-# 5. 发布到npm (done)
-# 6. 发布成功后,将发布的版本号和链接回复到当前pr下(done)
-# 7. 发布成功后,将发布的版本号和链接回复到本repo的相关issue中 (done)
-# 8. 修改README.md —— 提示dev版本需谨慎使用 (done)
-
-on:
- pull_request_target:
- types:
- - closed
- paths: # 这里是用来指定哪个文件更改,才会触发的
- - 'src/**'
- - 'package.json'
- - 'types/**'
- - 'examples/**'
-
-permissions:
- pull-requests: write
- issues: write
-
-jobs:
- dev-deploy:
- # 不需要在fork仓库的pr中运行, 仅当pr合并时运行
- if: github.repository == 'Tencent/cherry-markdown' && github.event.pull_request.merged == true
- runs-on: ubuntu-latest
-
- steps:
- # 检出仓库代码
- - name: Checkout repository
- uses:
- actions/checkout@v4
-
- # 获取PR合并后的SHA
- - name: Get merge commit SHA
- run: |
- if [ "${{ github.event.pull_request.merged }}" == "true" ]; then
- SHORT_SHA=$(echo "${{ github.event.pull_request.merge_commit_sha }}" | cut -c1-7)
- echo "MERGE_COMMIT_SHORT_SHA=$SHORT_SHA" >> "$GITHUB_ENV"
-
- else
- echo "Not a merged PR, skipping"
- fi
-
- # 根据commit id 修改package.json中的版本号和名称
- - name: dev package version and name
- run: |
- if [ -f package.json ]; then
-
- # 获取当前版本号并添加 merge commit SHA
- VERSION=$(node -p "require('./package.json').version")-dev.${{ env.MERGE_COMMIT_SHORT_SHA }}
-
- # 设置环境变量
- echo "PACKAGE_VERSION=$VERSION" >> "$GITHUB_ENV"
- package_name="@cherry-markdown-publisher/preview-dev"
- echo "PACKAGE_NAME=$package_name" >> "$GITHUB_ENV"
-
- # 打印当前版本号
- echo "Current version: $PACKAGE_VERSION"
-
- # 修改 package.json 中的 name 和 version,并检查 scripts 中是否存在 publish 属性,如果存在则移除
- jq --arg package_name "$package_name" --arg package_version "$VERSION" '
- .name=$package_name |
- .version=$package_version |
- if .scripts.publish then del(.scripts.publish) else . end
- ' package.json > temp.json && mv temp.json package.json
-
- # 打印修改后的 name 和 version
- echo "Updated package.json:"
- cat package.json | jq '.name, .version'
-
- echo "$PACKAGE_VERSION"
-
- # 检查 scripts 中是否存在 publish 属性,如果存在则移除
- if jq -e '.scripts.publish' package.json > /dev/null; then
- jq 'del(.scripts.publish)' package.json > temp.json && mv temp.json package.json
- fi
-
- else
- echo "package.json 文件不存在"
- fi
-
- # 重写或创建 README.md 文件
- echo -e '
\n' > README.md
- echo -e '# Cherry Markdown Writer\n' >> README.md
- echo -e '> !WARNING\n This is a dev preview version of `Cherry Markdown`, please use it with caution. No responsibility for production versions.\n' >> README.md
-
- - name: Install Node.js
- uses: actions/setup-node@v4
- with:
- node-version: "18"
- registry-url: https://registry.npmjs.org/
-
- - name: yarn install
- run: |
- npm i yarn -g
- yarn install
-
- - name: build
- run: yarn build
-
- - name: npm publish
- run: npm publish
- env:
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
-
- - name: Comment on related issues
- id: get-issues
- uses: actions/github-script@v7
- with:
- result-encoding: string
- retries: 3
- retry-exempt-status-codes: 400,401
- script: |
- let issue_array =[context.issue.number];
-
- // 添加issue到数组并去重
- const addIssueToArray = (newIssues) => {
- issue_array.push(...newIssues);
- issue_array = [...new Set(issue_array)];
- };
-
- try {
- // 获取pr的issue编号并且转换成数字数组
- const getIssueRegex =(issueText)=>{
- const issueRegex = /#(\d+)/g
- return Array.from(issueText?.matchAll(issueRegex), match => parseInt(match[1], 10));
- };
-
- const comment = `谢谢您的大力支持,请安装和此相关的测试版进行极速体验:
- \`\`\`shell
- npm install ${process.env.PACKAGE_NAME}@${process.env.PACKAGE_VERSION}
- \`\`\`
- [查看npm发布版本](https://www.npmjs.com/package/${process.env.PACKAGE_NAME}/v/${process.env.PACKAGE_VERSION}),请注意这是一个开发预览版本,请谨慎使用!`;
-
- // 发布评论到issue
- const createComment= async (issueNumbers) => {
- if(typeof value === 'number' && !isNaN(value)) return;
- issueNumbers.forEach(async (issueNumber) => {
- await github.rest.issues.createComment({
- owner: context.repo.owner,
- repo: context.repo.repo,
- issue_number: issueNumber,
- body: comment
- });
- });
- };
-
- // 获取当前提交的pr信息[title,body]
- const { data: pullCommits } =
- await github.rest.pulls.get({
- owner:context.repo.owner,
- repo: context.repo.repo,
- pull_number: context.issue.number
- });
- const pullCommitsIssueTitleNumbers = getIssueRegex(pullCommits.title);
- addIssueToArray(pullCommitsIssueTitleNumbers);
- const pullCommitsIssueBodyNumbers = getIssueRegex(pullCommits.body);
- addIssueToArray(pullCommitsIssueBodyNumbers);
-
- console.log('pullCommits-title',pullCommitsIssueTitleNumbers);
- console.log('pullCommits-body',pullCommitsIssueBodyNumbers);
-
- // 获取当前pr的issue信息[body]
- const { data: listPrIssue } =
- await github.rest.issues.listComments({
- owner: context.repo.owner,
- repo: context.repo.repo,
- issue_number: context.issue.number
- });
- listPrIssue.forEach((item) => {
- const listPrIssueIssueNumbers = getIssueRegex(item.body);
- addIssueToArray(listPrIssueIssueNumbers);
-
- console.log('listPrIssue',item.body);
- console.log('listPrIssue',listPrIssueIssueNumbers);
- });
-
- // 获取当前pr的 review 信息[body]
- const { data: listReviewComments } =
- await github.rest.pulls.listReviewComments({
- owner: context.repo.owner,
- repo: context.repo.repo,
- pull_number: context.issue.number
- });
- listReviewComments.forEach((item) => {
- const listReviewCommentsIssueNumbers = getIssueRegex(item.body);
- addIssueToArray(listReviewCommentsIssueNumbers);
-
- console.log('listReviewComments',item.body);
- console.log('listReviewComments',listReviewCommentsIssueNumbers);
- });
-
- createComment(issue_array);
- }catch(error){
- console.log('error',error);
- }