Skip to content

Commit

Permalink
fix: 优化 actions 27
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudcome committed Mar 17, 2023
1 parent 7998ef9 commit fc6c400
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions .github/actions/npm-publish/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,48 @@ inputs:
runs:
using: composite
steps:
- id: pkg
uses: jaywcjlove/github-action-package@main
- id: name
shell: bash
# originName -> underscoreName
# my-pkg -> my-pkg
# @my-scope/my-pkg -> my-scope__my-pkg
run: |
_n1="${{ steps.pkg.outputs.name }}"
# 删除 @ 开头
_n2="${_n1/@/}"
# 将 / 替换为 __
_n3="${_n2/\//__}"
echo "origin=${{ _n1 }}" >> "$GITHUB_OUTPUT"
echo "underscore=${{ _n3 }}" >> "$GITHUB_OUTPUT"
- name: 仓库类型是 npm
if: inputs.type == 'npm'
shell: bash
run: |
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'
shell: bash
run: |
echo "//npm.pkg.github.com/:_authToken=${{ github.token }}" > .npmrc
echo "registry=https://npm.pkg.github.com/" >> .npmrc
echo "always-auth=true" >> .npmrc
shell: bash
- name: 修改 package.json name 为 @${{ github.repository }}
- name: 将 package.json name 修改为符合 GitHub 要求
if: inputs.type == 'github'
uses: jaywcjlove/github-action-package@main
with:
data: |
{
"name": "@${{ github.repository }}"
"name": "@${{ steps.name.outputs.underscore }}"
}
- name: 仓库类型是 npm
if: inputs.type == 'npm'
run: |
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
shell: bash
- id: pkg
if: inputs.type == 'npm'
uses: jaywcjlove/github-action-package@main
- name: 同步新版本到 npmmirror.com
if: inputs.type == 'npm'
run: curl --silent -X PUT https://registry-direct.npmmirror.com/${{ steps.pkg.outputs.name }}/sync?sync_upstream=true
shell: bash

0 comments on commit fc6c400

Please sign in to comment.