Skip to content

Commit

Permalink
fix: 优化 actions 21
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudcome committed Mar 17, 2023
1 parent cb77bf8 commit 2725059
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 17 deletions.
47 changes: 47 additions & 0 deletions .github/actions/npm-publish/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: npm publish
description: |
按仓库类型执行 npm publish,可以将包发布到 npm、github 等仓库
如果是发布到 github 则会将 package.name 替换为 @${{ github.repository }}
inputs:
type:
description: 仓库类型,可选 npm/github
required: true
token:
description: 仓库授权令牌,如果是非 github 仓库则需要指定
required: false

runs:
using: composite
steps:
- name: 仓库类型是 github
if: inputs.type == "github"
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 }}
if: inputs.type == "github"
uses: jaywcjlove/github-action-package@main
with:
data: |
{
"name": "@${{ github.repository }}"
}
- 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
2 changes: 2 additions & 0 deletions .github/workflows/code-review.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: code review
description: 代码格式检查

on:
push:
Expand All @@ -21,6 +22,7 @@ jobs:
- uses: ./.github/actions/node-env
- run: npm ci
- run: npm run lint

test:
runs-on: ubuntu-latest
steps:
Expand Down
29 changes: 12 additions & 17 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
name: release please
description: |
如果是开发合并请求到主干,则会根据约定式提交创建一个 releasePR,是一个新版本合并请求。
如果是新版本合并请求合并到主干,则会触发版本发布到 npm/github 等仓库。
on:
push:
Expand All @@ -22,6 +25,7 @@ jobs:
with:
release-type: node
bump-minor-pre-major: true

test-coverage:
runs-on: ubuntu-latest
needs: release
Expand All @@ -35,6 +39,7 @@ jobs:
with:
api-token: ${{ secrets.CODACY_API_TOKEN }}
coverage-reports: coverage/lcov.info

publish-npm:
runs-on: ubuntu-latest
needs: test-coverage
Expand All @@ -43,14 +48,11 @@ jobs:
- uses: ./.github/actions/node-env
- run: npm ci
- run: npm run build
- run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
- run: echo "registry=https://registry.npmjs.org/" >> .npmrc
- run: echo "always-auth=true" >> .npmrc
- run: npm publish
- uses: jaywcjlove/github-action-package@main
id: pkg
- run: curl --silent -X PUT https://registry-direct.npmmirror.com/${{ steps.pkg.outputs.name }}/sync?sync_upstream=true
name: Sync the new version to npmmirror.com
- uses: ./.github/actions/npm-publish
with:
type: npm
token: ${{ secrets.NPM_TOKEN }}

publish-github:
runs-on: ubuntu-latest
needs: test-coverage
Expand All @@ -59,13 +61,6 @@ jobs:
- uses: ./.github/actions/node-env
- run: npm ci
- run: npm run build
- run: echo "//npm.pkg.github.com/:_authToken=${{ github.token }}" > .npmrc
- run: echo "registry=https://npm.pkg.github.com/" >> .npmrc
- run: echo "always-auth=true" >> .npmrc
- uses: jaywcjlove/github-action-package@main
- uses: ./.github/actions/npm-publish
with:
data: |
{
"name": "@${{ github.repository }}"
}
- run: npm publish
type: github

0 comments on commit 2725059

Please sign in to comment.