diff --git a/.github/actions/npm-publish/action.yml b/.github/actions/npm-publish/action.yml new file mode 100644 index 0000000..0f57b14 --- /dev/null +++ b/.github/actions/npm-publish/action.yml @@ -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 diff --git a/.github/workflows/code-review.yml b/.github/workflows/code-review.yml index de53a6a..20a6328 100644 --- a/.github/workflows/code-review.yml +++ b/.github/workflows/code-review.yml @@ -1,4 +1,5 @@ name: code review +description: 代码格式检查 on: push: @@ -21,6 +22,7 @@ jobs: - uses: ./.github/actions/node-env - run: npm ci - run: npm run lint + test: runs-on: ubuntu-latest steps: diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index f5a8bc1..04f1b23 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -1,4 +1,7 @@ name: release please +description: | + 如果是开发合并请求到主干,则会根据约定式提交创建一个 releasePR,是一个新版本合并请求。 + 如果是新版本合并请求合并到主干,则会触发版本发布到 npm/github 等仓库。 on: push: @@ -22,6 +25,7 @@ jobs: with: release-type: node bump-minor-pre-major: true + test-coverage: runs-on: ubuntu-latest needs: release @@ -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 @@ -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 @@ -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