xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

GitHub 上如何使用 GitHub Packages 发布 npm 包 All In One

GitHub 上如何使用 GitHub Packages 发布 npm 包 All In One

npm publish

PAT === Personal Access Token

# xgqfrms
$ npm login --registry=https://npm.pkg.github.com
# 输入 PAT 密码

$ npm publish

# 指定 scope @xgqfrms
$ npm login --registry=https://npm.pkg.github.com --scope=@xgqfrms
# 输入 PAT 密码

$ npm publish

https://github.com/xgqfrms/wcui/packages/1587375

GitHub Packages only supports scoped npm packages.

https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry#publishing-a-package

GitHub Actions

CI/CD

https://github.com/xgqfrms/wcui/actions/new

https://github.com/xgqfrms/wcui/actions/new?category=none&query=npm

# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages

name: Node.js Package

on:
  release:
    types: [created]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 16
      - run: npm ci
      - run: npm test

  publish-gpr:
    needs: build
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 16
          registry-url: https://npm.pkg.github.com/
      - run: npm ci
      - run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}


GITHUB_TOKEN

https://github.com/xgqfrms/wcui/settings/secrets/actions

https://github.com/xgqfrms/wcui/releases/new

https://github.com/xgqfrms/wcui/runs/7739088278?check_suite_focus=true#step:4:26

https://github.com/xgqfrms/wcui/blob/main/.github/workflows/npm-publish-github-packages.yml

demo

before

after ✅

git delete tags

# delete local tag '12345'
$ git tag -d 12345

# delete remote tag '12345' (eg, GitHub version too)
$ git push origin :refs/tags/12345

# alternative approach
$ git push --delete origin tagName
$ git tag -d tagName

https://github.com/xgqfrms/wcui/issues/9

# 查看所有 tags
$ git tag

# 删除 tag v1.1.1 ❌
$ git tag -d v1.1.1
$ git push origin :refs/tags/v1.1.1


# 删除 tag v1.1.2 ❌
$ git tag -d v1.1.2
$ git push origin :refs/tags/v1.1.2


image

.npmrc & publishConfig

https://docs.github.com/en/packages/quickstart

docs

https://github.com/features/packages

https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry

token

https://docs.github.com/en/actions/security-guides/automatic-token-authentication#using-the-github_token-in-a-workflow

https://docs.github.com/en/packages/learn-github-packages/about-permissions-for-github-packages#about-scopes-and-permissions-for-package-registries

GitHub package bugs All In One

https://gist.github.com/xgqfrms/c837e1b27674eeea350f2db7d401ee0f

https://github.com/xgqfrms/wcui/issues/10

https://github.com/orgs/community/discussions/28844

refs

https://gist.github.com/xgqfrms/795719e59dbb7f7be562307a3c1cbe51

https://docs.github.com/cn/packages



©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2022-08-09 14:21  xgqfrms  阅读(428)  评论(2编辑  收藏  举报