Skip to content

Commit

Permalink
feat: add workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
jmni-cn committed Nov 19, 2024
1 parent 0a53546 commit dfb5c63
Showing 1 changed file with 105 additions and 0 deletions.
105 changes: 105 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Node.js CI

on:
push:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- run: yarn
# 测试,并生成测试覆盖率文件
# - run: yarn run coveralls
- run: yarn run build
# # 上报
# - name: Coveralls
# uses: coverallsapp/github-action@master
# with:
# github-token: ${{ secrets.HUB_TOKEN }}

# publish-npm任务
publish-npm:
# 在ubuntu最新版本的虚拟机执行
runs-on: ubuntu-latest
# 设置变量
strategy:
matrix:
node-version: [ 20.x ]
steps:
# 检查并切换到main分支
- name: 检查main分支
# 使用actions/checkout插件
uses: actions/checkout@v3

# 初始化缓存
- name: 缓存
uses: actions/cache@v3
id: cache-dependencies
with:
path: node_modules
key: ${{runner.OS}}-${{hashFiles('**/yarn.lock')}}

# 安装node
- name: 设置Node.js
# 使用actions/setup-node插件
uses: actions/setup-node@v3
with:
# node版本
node-version: ${{ matrix.node-version }}
- run: yarn
- run: yarn run build

# 读取当前版本号
- name: 读取当前版本号
id: version
uses: notiz-dev/github-action-json-property@release
with:
# 读取版本号
path: './package.json'
prop_path: 'version'

- run: echo ${{steps.version.outputs.prop}}

# 创建Release
- name: release
# 原本使用的 actions/create-release@latest来发版, actions/upload-release-asset@v1上传release-asset
# 不过这两个action官方已经停止维护了,所以换成如下
uses: softprops/action-gh-release@v1
with:
files: ./lib
name: v${{steps.version.outputs.prop}}
tag_name: v${{steps.version.outputs.prop}}
env:
GITHUB_TOKEN: ${{ secrets.HUB_TOKEN }}

# 发布NPM包
- name: 发布NPM包
# 执行发布代码
run: |
npm config set //registry.npmjs.org/:_authToken=$NPM_TOKEN
npm publish
env:
# 配置 npm access token 环境变量
NPM_TOKEN: ${{secrets.NPM_JMNI_CN}}

# 刷新缓存
- name: 刷新缓存
run: |
curl https://purge.jsdelivr.net/npm/iemotion-pic@latest/lib/name.json

0 comments on commit dfb5c63

Please sign in to comment.