diff --git a/.github/actions/npm-publish/action.yml b/.github/actions/npm-publish/action.yml index 0014307..52daa7e 100644 --- a/.github/actions/npm-publish/action.yml +++ b/.github/actions/npm-publish/action.yml @@ -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