语义放出预设.
Daniel Bannert的开源工作得到了社区的支持 GitHub 赞助商
可分享 语义释放 配置,用于在您的项目中执行一致的 GitHub/ NPM 发布 .
目的
- 这种配置还包括一个语义-放行配置,它可以根据您的承诺消息自动GitHub/NPM发布.
安装
npm install --dev-save semantic-release @anolilab/semantic-release-preset
yarn add -D semantic-release @anolilab/semantic-release-preset
pnpm add -D semantic-release @anolilab/semantic-release-preset
插件
我们使用语义释放生态系统中的以下插件:
- @ semmantic-release/changelog (英语)
- @semantic-release/承诺分析器
- @ semmantic-release/执行
- @semantic-release/ git (英语)
- @semantic-release/ github (英语)
- @ semmantic-release/ npm (英语) (可选)
- @ semetic-release/release-note-generator (英语)
- @anolilab/语义化-释放-pnpm (可选)
- 语义 -- -- 释放 -- -- 亚伦 (可选)
内容提要
此可共享配置执行以下动作 :
- 分析承诺@semantic-release/承诺分析器(中文(简体) )
- 生成更改日志内容( E)@ semetic-release/release-note-generator (英语)(中文(简体) )
- 创建或更新步骤2生成的更改日志文件( S)@ semmantic-release/changelog (英语)(中文(简体) )
- 将软件包版本更新到下一个发行版本
- 将资产交给项目的 git 存储器, 并带有承诺信息 core( 释放): ${nextrelease. version} [skip ci] ${nextrelease. notes} .
- 发布 npm 发布方式 :@ semmantic-release/ npm (英语) 或者说 @anolilab/语义化-释放-pnpm 或者说 语义 -- -- 释放 -- -- 亚伦) (可选)
- 发布一个 GitHub 发布并评论已发布的 Pull Request/ Issues(@semantic-release/ github (英语)(中文(简体) )
使用量
当首次安装此软件包时, 以下可共享配置 .releaserc.json 自动添加到您的工程文件夹中 :
注意: 如果脚本检测到已有的
.releaserc.json文件,它不会覆盖它.
说明: 邮局的脚本不运行,你就得加上
.releaserc.json手动.
Npm 发布方式 @ semmantic-release/ npm (英语)数字 :
{
"extends": "@anolilab/semantic-release-preset/npm"
}
Npm 发布方式 @anolilab/语义化-释放-pnpm数字 :
{
"extends": "@anolilab/semantic-release-preset/pnpm"
}
Npm 发布方式 语义 -- -- 释放 -- -- 亚伦数字 :
{
"extends": "@anolilab/semantic-release-preset/yarn"
}
没有 npm 发布 :
{
"extends": "@anolilab/semantic-release-preset"
}
扩展预设的文件内容
{
branches: [
"+([0-9])?(.{+([0-9]),x}).x",
"main",
"next",
"next-major",
{
name: "beta",
prerelease: true,
},
{
name: "alpha",
prerelease: true,
},
],
plugins: [
[
"@semantic-release/commit-analyzer",
{
preset: "conventionalcommits",
},
],
[
"@semantic-release/release-notes-generator",
{
preset: "conventionalcommits",
},
],
"@semantic-release/changelog",
"@semantic-release/npm", // optional
[
"@semantic-release/git",
{
message: "chore(release): ${nextRelease.gitTag} [skip ci]\n\n${nextRelease.notes}",
},
],
[
"@semantic-release/github",
{
successComment: false,
failComment: false,
},
],
],
}
折旧
你想贬低旧版本的套件吗?
选项一是语义-放行-npm-去除-旧版本
安装
npm install --dev-save semantic-release-npm-deprecate-old-versions
pnpm add -D semantic-release-npm-deprecate-old-versions
yarn add -D semantic-release-npm-deprecate-old-versions
没问题,你只要把下面加进去 .releaserc.json数字 :
{
"extends": "@anolilab/semantic-release-preset/npm",
"plugins": [
[
"semantic-release-npm-deprecate-old-versions",
{
"rules": [
{
"rule": "supportLatest",
"options": {
"numberOfMajorReleases": 1,
"numberOfMinorReleases": 1,
"numberOfPatchReleases": 1
}
},
{
"rule": "supportPreReleaseIfNotReleased",
"options": {
"numberOfPreReleases": 1
}
},
"deprecateAll"
]
}
]
]
}
找到如何配置插件 这里。 。 。 .
选项一是语义解说 -释放 -npm - 解说
安装
npm install --dev-save semantic-release-npm-deprecate-old-versions
pnpm add -D semantic-release-npm-deprecate-old-versions
yarn add -D semantic-release-npm-deprecate-old-versions
没问题,你只要把下面加进去 .releaserc.json数字 :
{
"extends": "@anolilab/semantic-release-preset/npm",
"plugins": [
[
"semantic-release-npm-deprecate",
{
"deprecations": [
{
"version": "< ${nextRelease.version.split('.')[0]}",
"message": "Please use ^${nextRelease.version.split('.')[0]}.0.0."
}
]
}
]
]
}
找到如何配置插件 这里。 。 。 .
环境变量配置
确保您的 CI 配置包含以下环境变量 :
- 吉图布: GitHub 个人访问符
- 当发布新版本时,此插件将尝试承诺并推入所发布的分支. 确保正在运行发行版的用户有按权限并可以绕过分支保护规则.
- 国家防范机制: Npm 个人访问符
- 国家防范机制标志,这样可以将软件包发布给国家防范机制(一个有额外配置的.npmrc文件也可以被使用)
您可以用干跑来测试您的配置 :
npx semantic-release --dry-run
GitHub 工作流程
狦琌 配置 GitHub 工作流程 您可能想要先做一个测试构建矩阵,然后只有在这些测试在所有环境中都成功时才会发布.
接下来的就是,在某件事被合并到 main。 。 。 .
以下是运行您测试并发布新版本的新承诺的工作流程配置示例 main 分支 :
单语义- 释放实例与纱线, (您也可以使用 pnpm 或 npm )
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions
name: "Semantic Release"
on: # yamllint disable-line rule:truthy
push:
branches:
- "([0-9])?(.{+([0-9]),x}).x"
- "main"
- "next"
- "next-major"
- "alpha"
- "beta"
jobs:
test:
name: "Semantic Release"
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v2"
with:
fetch-depth: 0
persist-credentials: false
env:
GIT_COMMITTER_NAME: "GitHub Actions Shell"
GIT_AUTHOR_NAME: "GitHub Actions Shell"
EMAIL: "github-actions[bot]@users.noreply.github.com"
- name: "Use Node.js 12.x"
uses: "actions/setup-node@v2"
with:
node-version: "12.x"
- name: "Get yarn cache directory path"
id: "yarn-cache-dir-path"
run: 'echo "::set-output name=dir::$(yarn config get cacheFolder)"'
- uses: "actions/cache@v2"
id: "yarn-cache" # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: "${{ steps.yarn-cache-dir-path.outputs.dir }}"
key: "${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}"
restore-keys: |
${{ runner.os }}-yarn-
- name: "install"
run: "yarn install --immutable"
- name: "Build packages"
run: "yarn build"
- name: "test"
run: "yarn run test"
semantic-release:
name: "Semantic Release"
runs-on: "ubuntu-latest"
needs: ["test"]
steps:
- uses: "actions/checkout@v2"
with:
fetch-depth: 0
persist-credentials: false
env:
GIT_COMMITTER_NAME: "GitHub Actions Shell"
GIT_AUTHOR_NAME: "GitHub Actions Shell"
EMAIL: "github-actions[bot]@users.noreply.github.com"
- name: "Use Node.js 12.x"
uses: "actions/setup-node@v2"
with:
node-version: "12.x"
- name: "Get yarn cache directory path"
id: "yarn-cache-dir-path"
run: 'echo "::set-output name=dir::$(yarn config get cacheFolder)"'
- uses: "actions/cache@v2"
id: "yarn-cache" # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: "${{ steps.yarn-cache-dir-path.outputs.dir }}"
key: "${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}"
restore-keys: |
${{ runner.os }}-yarn-
- name: "install"
run: "yarn install --immutable"
- name: "Build packages"
if: "success()"
run: "yarn build"
- name: "Semantic Release"
if: "success()"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
NPM_TOKEN: "${{ secrets.NPM_AUTH_TOKEN }}"
GIT_AUTHOR_NAME: "github-actions-shell"
GIT_AUTHOR_EMAIL: "github-actions[bot]@users.noreply.github.com"
GIT_COMMITTER_NAME: "github-actions-shell"
GIT_COMMITTER_EMAIL: "github-actions[bot]@users.noreply.github.com"
run: "npx semantic-release"
要发布多软件包寄存器, 您需要安装 @anolilab/multi-semantic-release 财务报告和审定财务报表 semantic-release。 。 。 .
多包语义放出以 pnpm 为例
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions
name: "Semantic Release"
on: # yamllint disable-line rule:truthy
push:
branches:
- "([0-9])?(.{+([0-9]),x}).x"
- "main"
- "next"
- "next-major"
- "alpha"
- "beta"
# Enable this to use the github packages
# yamllint disable-line rule:comments
#env:
# package: "@${{ github.repository }}"
# registry_url: "https://npm.pkg.github.com"
# scope: "${{ github.repository_owner }}"
jobs:
test:
strategy:
matrix:
os: ["ubuntu-latest"]
node_version: ["16", "18", "19", "20"]
fail-fast: false
name: "Build & Unit Test: node-${{ matrix.node_version }}, ${{ matrix.os }}"
runs-on: "${{ matrix.os }}"
steps:
- name: "Git checkout"
uses: "actions/checkout@v3"
env:
GIT_COMMITTER_NAME: "GitHub Actions Shell"
GIT_AUTHOR_NAME: "GitHub Actions Shell"
EMAIL: "github-actions[bot]@users.noreply.github.com"
- uses: "pnpm/[email protected]"
with:
version: 8
run_install: false
- name: "Set node version to ${{ matrix.node_version }}"
uses: "actions/setup-node@v3"
with:
node-version: "${{ matrix.node_version }}"
cache: "pnpm"
- name: "Check npm version"
run: "npm -v"
env:
SKIP_CHECK: "true"
- name: "Install packages"
run: "pnpm install --frozen-lockfile"
env:
SKIP_CHECK: "true"
# - name: "Build"
# run: "pnpm run build:packages"
# - name: "test and coverage"
# run: "pnpm run test:coverage"
semantic-release:
name: "Semantic Release"
runs-on: "ubuntu-latest"
needs: ["test", "eslint"]
steps:
- name: "Git checkout"
uses: "actions/checkout@v3"
with:
fetch-depth: 0
persist-credentials: false
env:
GIT_COMMITTER_NAME: "GitHub Actions Shell"
GIT_AUTHOR_NAME: "GitHub Actions Shell"
EMAIL: "github-actions[bot]@users.noreply.github.com"
- uses: "pnpm/[email protected]"
with:
version: 8
run_install: false
- name: "Use Node.js 16.x"
uses: "actions/setup-node@v3"
with:
node-version: "16.x"
cache: "pnpm"
- name: "Check npm version"
run: "npm -v"
env:
SKIP_CHECK: "true"
- name: "Install packages"
run: "pnpm install --frozen-lockfile"
# - name: "Build Production"
# run: "pnpm run build:prod:packages"
- name: "npm v8.5+ requires workspaces-update to be set to false"
run: "echo 'workspaces-update=false' >> .npmrc"
- name: "Semantic Release"
if: "success()"
env:
GITHUB_TOKEN: "${{ secrets.SEMANTIC_RELEASE_GITHUB_TOKEN }}"
NPM_TOKEN: "${{ secrets.NPM_AUTH_TOKEN }}"
GIT_AUTHOR_NAME: "github-actions-shell"
GIT_AUTHOR_EMAIL: "github-actions[bot]@users.noreply.github.com"
GIT_COMMITTER_NAME: "github-actions-shell"
GIT_COMMITTER_EMAIL: "github-actions[bot]@users.noreply.github.com"
run: "pnpm exec multi-semantic-release"
pnpm-lock-update:
name: "pnpm-lock.yaml update"
runs-on: "ubuntu-latest"
needs: ["semantic-release"]
steps:
- name: "Git checkout"
uses: "actions/checkout@v3"
with:
fetch-depth: 2
env:
GIT_COMMITTER_NAME: "GitHub Actions Shell"
GIT_AUTHOR_NAME: "GitHub Actions Shell"
EMAIL: "github-actions[bot]@users.noreply.github.com"
- uses: "pnpm/[email protected]"
with:
version: 8
- name: "Use Node.js 16.x"
uses: "actions/setup-node@v3"
with:
node-version: "16.x"
- name: "Update pnpm lock"
run: "pnpm install --no-frozen-lockfile"
- name: "Commit modified files"
uses: "stefanzweifel/[email protected]"
with:
commit_message: "chore: updated pnpm-lock.yaml"
commit_author: "prisis <[email protected]>"
commit_user_email: "[email protected]"
commit_user_name: "prisis"
branch: "${{ github.head_ref }}"
关于 GitHub 保护分支的说明
如果你要释放一个 GitHub 保护分支 您需要更改 git 承诺给所有者/ 管理员, 并允许 repo 管理员绕过分支保护( 确保分支保护规则中禁用“ 包含管理员 ” )
如果你的Repo属于一个组织,你可以创建一个bot账户,并在repo上赋予它管理权. 如果你的Repo在个人帐户下,你没有选择让Repo所有者成为释放的罪犯.
无论是哪种方式,你都要为承诺者账户创建一个GitHub个人访问符并赋予其"repo"访问权限. 然后把它放到您的 GitHub 仓库里的 GH Token 秘密中 .
注意: GitHub 不与叉子分享秘密并拉动请求.
支持的节点.js版本
这一生态系统中的图书馆尽最大努力追踪 Node.js的释放时间表。这里 (单位:千美元) 贴上我们为什么认为 这很重要。 。 。 .
捐款
说明: 请注意,该项目已连同《协助者行为守则》一起公布。 通过参加这个项目,你同意遵守其条款.
贷项
在阿诺利拉布制造的
这是一个开源项目,将永远可以自由使用。 如果你觉得这很酷,请 显示它. 阿诺利拉布 是一个开发与AI工作室。 联系我们 你好@anolilab.com 如果你需要任何帮助 这些技术 或者只是想打个招呼!
许可证
Anolilab语义 -- -- 释放 -- -- 预设是开源软件,根据 麻省理工学院