侥幸汇成河

发布于     更新于
使用 github Action 发布 npm 包

说不定我一生涓滴意念,侥幸汇成河

使用 github Action 发布 npm 包 + github npm 包 + github container 包:

name: Publish NPM Package # 名称
on:
  push: # 推送方式:push tag 或者 push master 分支 或者 发布 release
    # tags:
    #   - '*'
    branches:
        - master
  # release:
  #   types: [created]
jobs:
  build:
    runs-on: ubuntu-latest # 使用镜像
    steps:
    - uses: actions/checkout@v2 # 检出文件
    # 发布到 npm
    - uses: actions/setup-node@v1
      with:
        node-version: '12.x'
        registry-url: 'https://registry.npmjs.org'
    # - run: npm install --registry https://registry.npmjs.org
    # 发布 npm 包
    - run: npm publish --access public
      env:
        NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
    # 通知电报频道
    - run: curl -X POST "${{ secrets.TG_URL }}" -d "chat_id=${{ secrets.TG_CHAT_ID }}&text="
    # 发布到 GitHub 包
    - uses: actions/setup-node@v1
      with:
        node-version: '12.x'
        registry-url: 'https://npm.pkg.github.com'
        scope: 'hz2'
    # - run: npm install
    # github 只能发布带作域的包,故而需要替换包名
    - run: sed -i 's/"pub.css"/"@hz2\/pub.css"/g' package.json
    # 发布到 GitHub 包
    - run: npm publish
      env:
        NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    # 通知电报频道
    - run: curl -X POST "${{ secrets.TG_URL }}" -d "chat_id=${{ secrets.TG_CHAT_ID }}&text="    
    # 先获取 npm 包的版本号作为 docker 镜像的 tag 版本号
    - uses: martinbeentjes/npm-get-version-action@master
      id: package-version
      with:
        path: ./
    # 登录到 github 的容器源
    - name: Log in to GitHub Docker Registry
      uses: docker/login-action@v1
      with:
        registry: ghcr.io
        username: hz2
        password: ${{ secrets.GITHUB_TOKEN }}
    - name: Build container image
      uses: docker/build-push-action@v2
      with:
        push: true
        tags: |
          ghcr.io/${{ github.repository_owner }}/pub_css:${{ steps.package-version.outputs.current-version}}
    # 通知电报频道
    - run: curl -X POST "${{ secrets.TG_URL }}" -d "chat_id=${{ secrets.TG_CHAT_ID }}&text="