Repository navigation
105 lines (86 loc) · 3.67 KB
/
Copy pathreusable-npm-dev-preview.yml
File metadata and controls
105 lines (86 loc) · 3.67 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
# =============================================================================
# Reusable Workflow: npm Dev Preview
#
# 发布 @cherry-markdown/cherry-markdown-dev 到 npm(带时间戳版本号)
# 并在 PR 中评论安装指引(alias 方式,无需修改 import 语句)
# =============================================================================
name: 'Reusable: npm Dev Preview'
on:
workflow_call:
inputs:
pr_number:
required: true
type: number
jobs:
npm-dev-preview:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: .node-version
registry-url: https://registry.npmjs.org/
cache: yarn
- name: Prepare dev package
working-directory: ./packages/cherry-markdown
env:
COMMIT_SHORT_SHA: ${{ github.sha }}
run: |
COMMIT_SHORT_SHA="${COMMIT_SHORT_SHA:0:7}"
COMMIT_MESSAGE=$(git log --oneline -1)
BASE_VERSION=$(jq -r .version package.json)
VERSION="${BASE_VERSION}-$(date +'%Y%m%d%H%M').${COMMIT_SHORT_SHA}"
# 修改包名和版本号
tmp=$(mktemp) && jq \
--arg name "@cherry-markdown/cherry-markdown-dev" \
--arg version "$VERSION" \
'.name = $name | .version = $version | del(.scripts.publish?)' \
package.json > "$tmp" && mv "$tmp" package.json
# 写入警告 README
cat > README.md <<EOF
**⚠️ 开发预览警告 / Development Preview Warning**
变更 / Changes: ${COMMIT_MESSAGE}
此版本为临时测试版,禁止在生产环境使用!
This is a development preview version, do NOT use in production!
EOF
# 输出环境变量供后续步骤使用
echo "PACKAGE_VERSION=$VERSION" >> $GITHUB_ENV
echo "PACKAGE_NAME=@cherry-markdown/cherry-markdown-dev" >> $GITHUB_ENV
- name: Install and build
run: yarn install && yarn build
- name: npm publish
working-directory: ./packages/cherry-markdown
run: npm publish --access public --tag latest --provenance
- name: Comment install instructions
if: success()
uses: actions/github-script@v7
with:
script: |
const name = process.env.PACKAGE_NAME;
const version = process.env.PACKAGE_VERSION;
github.rest.issues.createComment({
issue_number: ${{ inputs.pr_number }},
owner: context.repo.owner,
repo: context.repo.repo,
body: `📦 **cherry-markdown dev published** — \`${name}@${version}\`
⚠️ **注意**: 此版本为开发预览版,禁止在生产环境使用!
> 通过 alias 安装后,代码中仍然可以使用 \`cherry-markdown\` 包名,无需修改 import 语句
**[查看 NPM](https://www.npmjs.com/package/${name}/v/${version})**
\`\`\`bash
pnpm add cherry-markdown@npm:${name}@${version}
\`\`\`
\`\`\`bash
yarn add cherry-markdown@npm:${name}@${version}
\`\`\`
\`\`\`bash
npm i cherry-markdown@npm:${name}@${version}
\`\`\`
**peer dependency 覆盖方式:**
npm: \`"overrides": { "cherry-markdown": "npm:${name}@${version}" }\`
yarn: \`"resolutions": { "cherry-markdown": "npm:${name}@${version}" }\`
pnpm: \`"pnpm": { "overrides": { "cherry-markdown": "npm:${name}@${version}" } }\`
`
});