Skip to content

Merge pull request #17 from Gaohaoyang/feature/ci #20

Merge pull request #17 from Gaohaoyang/feature/ci

Merge pull request #17 from Gaohaoyang/feature/ci #20

Workflow file for this run

name: npm build and publish
# 执行脚本的生命周期
on:
#选择在 push 到 github 时触发工作流
push:
#分支可以选择多个
branches: [main]
# 一个 workflow 可以有多个 job
jobs:
build:
# 指定操作系统为'ubuntu-latest'
runs-on: ubuntu-latest
steps:
- name: Check if version updated
uses: MontyD/package-json-updated-action@1.0.1
id: version-updated
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# 检查仓库以便作业能正常访问
- name: Setup repo
uses: actions/checkout@v4
if: steps.version-updated.outputs.has-updated
with:
fetch-depth: 2
# Setup .npmrc file to publish to npm
- name: Node env setup
uses: actions/setup-node@v4
if: steps.version-updated.outputs.has-updated
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
# npm ci命令类似于 npm install 但它旨在用于自动化环境,如测试平台,持续集成和部署
# 可以帮助捕获由大多数 npm 用户的增量安装的本地环境引起的错误或不一致
- run: npm ci
if: steps.version-updated.outputs.has-updated
# 发布命令
- run: npm run build && npm publish
if: steps.version-updated.outputs.has-updated
env:
# npm_token 就是刚刚填写 token 时取的名字
NODE_AUTH_TOKEN: ${{ secrets.NPMPUBHAOYANG }}
- name: Create a tag
uses: salsify/action-detect-and-tag-new-version@v2
if: steps.version-updated.outputs.has-updated