forked from Tencent/cherry-markdown
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpr_merge_cherry-markdown_npm-dev.yml
More file actions
141 lines (111 loc) · 5.46 KB
/
pr_merge_cherry-markdown_npm-dev.yml
File metadata and controls
141 lines (111 loc) · 5.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
name: "Publish Cherry-Markdown Dev Preview on PR Merge"
on:
pull_request:
types: [closed]
paths:
- "packages/cherry-markdown/**"
permissions:
contents: read
pull-requests: write
issues: write
id-token: write
jobs:
npm-preview:
# 不需要在fork仓库的pr中运行, 仅当pr合并时运行
if: github.repository == 'Tencent/cherry-markdown' && github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'dev'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get Merge Commit SHA
run: echo "COMMIT_SHORT_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_ENV
- name: Get Commit Message
run: echo "COMMIT_MESSAGE=$(git log --oneline -1)" >> $GITHUB_ENV
- name: Install dependencies
run: sudo apt-get install -y moreutils
- name: Update package.json
working-directory: ./packages/cherry-markdown
run: |
BASE_VERSION=$(jq -r .version package.json)
VERSION="${BASE_VERSION}-$(date +'%Y%m%d%H%M').${{ env.COMMIT_SHORT_SHA }}"
jq --arg name "@cherry-markdown/cherry-markdown-dev" \
--arg version "$VERSION" \
'.name = $name | .version = $version | del(.scripts.publish?)' package.json | sponge package.json
echo "PACKAGE_VERSION=$VERSION" >> $GITHUB_ENV
echo "PACKAGE_NAME=@cherry-markdown/cherry-markdown-dev" >> $GITHUB_ENV
- name: Update README
working-directory: ./packages/cherry-markdown
run: |
cat <<-EOF > README.md
**⚠️ 开发预览警告 / Development Preview Warning**
变更 / Changes: ${{ env.COMMIT_MESSAGE }}
此版本为[临时测试版](${PACKAGE_NAME}@${PACKAGE_VERSION}),禁止在生产环境使用!
This is a [development preview version](${PACKAGE_NAME}@${PACKAGE_VERSION}), do NOT use in production!
EOF
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: .node-version
registry-url: https://registry.npmjs.org/
cache: yarn
- name: Install and build
working-directory: ./packages/cherry-markdown
run: yarn install && yarn build
- uses: actions/setup-node@v4
with:
node-version: 24
- name: npm publish
working-directory: ./packages/cherry-markdown
run: npm publish --tag latest
- name: Post comments
uses: actions/github-script@v7
with:
script: |
const commentTemplate = `📦 **cherry-markdown dev preview published**
⚠️ **注意**: 此版本为开发预览版,禁止在生产环境使用!
> 此方式引用代码中仍然可以使用 \`cherry-markdown\` 包名,不需要修改现有的 import 语句
⚠️ **Note**: This version is a developer preview and should not be used in production environments!
> This way of referencing allows you to still use the package name \`cherry-markdown\`, no need to modify existing import statements
**Install [NPM](https://www.npmjs.com/package/${process.env.PACKAGE_NAME}/v/${process.env.PACKAGE_VERSION}) with** :
\`\`\`bash
pnpm add cherry-markdown@npm:${process.env.PACKAGE_NAME}@${process.env.PACKAGE_VERSION}
\`\`\`
\`\`\`bash
yarn add cherry-markdown@npm:${process.env.PACKAGE_NAME}@${process.env.PACKAGE_VERSION}
\`\`\`
\`\`\`bash
npm i cherry-markdown@npm:${process.env.PACKAGE_NAME}@${process.env.PACKAGE_VERSION}
\`\`\`
如果你使用了其他以 cherry-markdown 作为同等依赖(peer dependency)的元框架,你需要在 package.json 文件中覆盖 cherry-markdown 依赖,具体操作方式会因你使用的包管理器而略有不同
If you use a meta framework that has cherry-markdown as peer dependency, you have to override the cherry-markdown dependency in your package.json, which works slightly different depending on your package manager
\`\`\`json
# npm
{
"overrides": {
"cherry-markdown": "npm:${process.env.PACKAGE_NAME}@${process.env.PACKAGE_VERSION}"
}
}
# yarn
{
"resolutions": {
"cherry-markdown": "npm:${process.env.PACKAGE_NAME}@${process.env.PACKAGE_VERSION}"
}
}
# pnpm
{
"pnpm": {
"overrides": {
"cherry-markdown": "npm:${process.env.PACKAGE_NAME}@${process.env.PACKAGE_VERSION}"
}
}
}
\`\`\`
在添加 overrides 之后,重新安装你的依赖并像往常一样启动你的开发服务器或构建你的项目即可,无需进一步的配置更改
After adding these overrides, reinstall your dependencies and start your development server or build your project as usual. No further configuration changes are required
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentTemplate
});