Giter VIP home page Giter VIP logo

github-actions's Introduction

artusjs/github-actions

为开源项目提供常见的可复用的 GitHub Actions Workflow

功能列表

  • 单元测试
  • 自动发包
  • 自动初始化仓库配置

单元测试

自动跑 Lint 和 Cov 单测

参考示例:https://github.com/artus-cli/examples/actions

  • 配置 npm scripts
{
  "name": "your-project",
  "scripts": {
    "lint": "eslint .",
    "test": "mocha",
    "ci": "c8 npm test"
  }
}
  • 创建 .github/workflows/ci.yml
name: CI

on:
  push:
    branches: [ master, main ]

  pull_request:
    branches: [ master, main, next, beta, '*.x' ]

  schedule:
    - cron: '0 2 * * *'

  workflow_dispatch: {}

jobs:
  Job:
    name: Node.js
    uses: artusjs/github-actions/.github/workflows/node-test.yml@v1
    # 支持以下自定义配置,一般用默认值即可
    # with:
    #   os: 'ubuntu-latest, macos-latest, windows-latest'
    #   version: '16, 18'

发布 NPM 包

使用 semantic-release 自动发布 NPM 包。

功能详情

  • 根据 Git 日志自动计算版本号
  • 自动生成 ChangeLog 文件
  • 自动创建 GitHub Release 说明
  • 自动打 Tag 标签
  • 自动发布到 Registry,支持 NPM 和 GitHub
  • 自动触发 CNPM 同步

支持合并到主干分支后自动发布,也支持手动发布。

手动发布方式:访问仓库的 Actions 页面,左侧选择 Release Workflow,点击右侧的 Run Workflow 即可。

版本号规则

根据 Commit Message 自动计算下一个版本号:

注意:

  • 不支持发布 0.x 版本,master 首次发布将是 1.0.0 版本
  • 如果你不期望直接发布,请在 beta 分支提交代码运行,将发布 1.0.0-beta.1 版本
  • 多版本发布实践参见 semantic-release 文档

配置方式

  • 创建 NPM Token

    • NPM Registry 需创建 Automation Token,参见文档
    • GitHub Package 无需创建,默认支持
  • 创建 GitHub Token

    • 因为生成的 CHANGELOG.md 和 package.json 需回写 GitHub,而默认的 GITHUB_TOKEN 没有该权限
    • 因此需要创建一个新的 Token,参见文档
  • 配置 Token

    • 在项目或组织维度配置 2 个 secretsNPM_TOKENGIT_TOKEN
    • 参见文档
  • 创建 .github/workflows/release.yml

name: Release
on:
  # 合并后自动发布
  push:
    branches: [ master, main, next, beta, '*.x' ]

  # 手动发布
  workflow_dispatch: {}

jobs:
  release:
    name: Node.js
    uses: artusjs/github-actions/.github/workflows/node-release.yml@v1
    secrets:
      NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
      GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
    # with:
      # checkTest: false
      # dryRun: true

发布到 GitHub Package

修改 release.yml 的 secrets:

secrets:
  NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }}

修改 package.json

{
  "publishConfig": {
    "access": "public",
    "registry": "https://npm.pkg.github.com"
  },
}

github-actions's People

Contributors

atian25 avatar fengmk2 avatar

Stargazers

 avatar

Forkers

node-modules

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.