Skip to content

Commit 355823f

Browse files
committed
chore: 更新 release.yml,添加版本检查和发布到 npm 的逻辑,优化 GitHub Release 创建步骤;在 index.ts 中更新 dataField 配置,支持空字符串和详细描述
1 parent 994b740 commit 355823f

File tree

2 files changed

+39
-22
lines changed

2 files changed

+39
-22
lines changed

.github/workflows/release.yml

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121

2222
steps:
2323
- name: 检出代码
24-
uses: actions/checkout@v4
24+
uses: actions/checkout@v5
2525
with:
2626
fetch-depth: 0
2727

@@ -77,14 +77,19 @@ jobs:
7777
- name: 更新版本号 (手动触发时)
7878
if: github.event_name == 'workflow_dispatch'
7979
run: |
80-
npm version ${{ steps.get_version.outputs.version }} --no-git-tag-version
81-
git config --local user.email "action@github.com"
82-
git config --local user.name "GitHub Action"
83-
git add package.json
84-
git commit -m "chore: bump version to ${{ steps.get_version.outputs.version }}"
85-
git tag ${{ steps.get_version.outputs.tag_name }}
86-
git push origin HEAD:${{ github.ref_name }}
87-
git push origin ${{ steps.get_version.outputs.tag_name }}
80+
# 检查 tag 是否已经存在
81+
if git show-ref --tags --verify --quiet "refs/tags/${{ steps.get_version.outputs.tag_name }}"; then
82+
echo "⚠️ Tag ${{ steps.get_version.outputs.tag_name }} 已存在,跳过创建"
83+
else
84+
npm version ${{ steps.get_version.outputs.version }} --no-git-tag-version
85+
git config --local user.email "action@github.com"
86+
git config --local user.name "GitHub Action"
87+
git add package.json
88+
git commit -m "chore: bump version to ${{ steps.get_version.outputs.version }}"
89+
git tag ${{ steps.get_version.outputs.tag_name }}
90+
git push origin HEAD:${{ github.ref_name }}
91+
git push origin ${{ steps.get_version.outputs.tag_name }}
92+
fi
8893
8994
- name: 生成变更日志
9095
id: changelog
@@ -94,20 +99,28 @@ jobs:
9499
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
95100

96101
- name: 发布到 npm
97-
run: pnpm publish --no-git-checks
102+
run: |
103+
# 检查版本是否已经发布到 npm
104+
PACKAGE_NAME=$(node -p "require('./package.json').name")
105+
CURRENT_VERSION=$(node -p "require('./package.json').version")
106+
107+
# 尝试获取 npm 上的版本信息
108+
if npm view "${PACKAGE_NAME}@${CURRENT_VERSION}" version 2>/dev/null; then
109+
echo "⚠️ 版本 ${CURRENT_VERSION} 已存在于 npm,跳过发布"
110+
else
111+
echo "📦 发布版本 ${CURRENT_VERSION} 到 npm..."
112+
pnpm publish --no-git-checks
113+
fi
98114
env:
99115
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
100116

101-
- name: 创建 GitHub Release
102-
uses: actions/create-release@v1
103-
env:
104-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
117+
- name: Create GitHub Release
118+
uses: ncipollo/release-action@v1
105119
with:
106-
tag_name: ${{ steps.get_version.outputs.tag_name }}
107-
release_name: Release ${{ steps.get_version.outputs.tag_name }}
108-
body_path: ${{ steps.changelog.outputs.changelog_file }}
109-
draft: false
110-
prerelease: false
120+
generateReleaseNotes: "true"
121+
allowUpdates: true
122+
skipIfReleaseExists: false
123+
omitBodyDuringUpdate: false
111124

112125
- name: 通知发布成功
113126
run: |

src/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@ export default (api: IApi) => {
2121
key: 'request',
2222
config: {
2323
schema: ({ zod }) => {
24-
// 生成类型 dataField: '' | string
2524
return zod
2625
.object({
27-
dataField: zod.string(),
26+
dataField: zod
27+
.union([zod.string(), zod.literal('')])
28+
.describe('响应数据提取字段名。用于指定从 API 响应中提取数据的字段路径。设置为非空字符串时(如 "data"、"result"),将从响应对象中提取对应字段的值作为最终数据;设置为空字符串 "" 时,直接返回完整的响应对象不做字段提取。默认值为 "data",即从 response.data 中提取数据。此配置会影响 useRequest 和 request 方法的数据格式化行为。')
29+
.optional()
2830
})
29-
.partial();
31+
.describe('HTTP 请求插件配置。基于 axios 和 vue-hooks-plus 提供统一的 HTTP 请求解决方案,支持 Vue3 的 useRequest hook、请求/响应拦截器、错误处理和数据格式化等功能。集成运行时插件系统,支持动态配置请求实例和拦截器。')
32+
.optional()
33+
.default({});
3034
},
3135
},
3236
enableBy: api.EnableBy.config,

0 commit comments

Comments
 (0)