Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions .github/actions/npm-publish/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ runs:
using: composite
steps:
- id: pkg
name: 获取 package.json 信息
uses: jaywcjlove/github-action-package@main

- id: naming
name: 命名规则变更
shell: bash
# originName -> underscoreName
# my-pkg -> my-pkg
# @my-scope/my-pkg -> my-scope__my-pkg
env:
UNDERSCORE_NAME: ${${n1/@/}/\//__}
run: |
# 原始名称
echo "N1=${{ steps.pkg.outputs.name }}" >> $GITHUB_ENV
# 删除 @ 开头
echo "N2=${N1/@/}" >> $GITHUB_ENV
# 将 / 替换为 __
echo "N3=${N2/\//__}" >> $GITHUB_ENV
echo "origin=$N1" >> "$GITHUB_OUTPUT"
echo "underscore=$N3" >> "$GITHUB_OUTPUT"
echo "underscore=${${N1/@/}/\//__}" >> "$GITHUB_OUTPUT"

- name: 仓库类型是 npm
if: inputs.type == 'npm'
Expand All @@ -36,12 +36,6 @@ runs:
echo "//registry.npmjs.org/:_authToken=${{ inputs.token }}" > .npmrc
echo "registry=https://registry.npmjs.org/" >> .npmrc
echo "always-auth=true" >> .npmrc
- shell: bash
run: npm publish
- name: 同步新版本到 npmmirror.com
if: inputs.type == 'npm'
shell: bash
run: curl --silent -X PUT https://registry-direct.npmmirror.com/${{ steps.pkg.outputs.name }}/sync?sync_upstream=true

- name: 仓库类型是 github
if: inputs.type == 'github'
Expand All @@ -50,11 +44,21 @@ runs:
echo "//npm.pkg.github.com/:_authToken=${{ github.token }}" > .npmrc
echo "registry=https://npm.pkg.github.com/" >> .npmrc
echo "always-auth=true" >> .npmrc
- name: 将 package.json name 修改为符合 GitHub 要求
- name: 将 package.json name 修改为符合 GitHub 的命名要求
if: inputs.type == 'github'
uses: jaywcjlove/github-action-package@main
with:
data: |
{
"name": "@${{ github.repository_owner }}/${{ steps.naming.outputs.underscore }}"
}

# 发布
- shell: bash
run: npm publish

# npm 发布时同步新版本
- name: 同步新版本到 npmmirror.com
if: inputs.type == 'npm'
shell: bash
run: curl --silent -X PUT https://registry-direct.npmmirror.com/${{ steps.pkg.outputs.name }}/sync?sync_upstream=true