-
Notifications
You must be signed in to change notification settings - Fork 0
155 lines (129 loc) · 4.46 KB
/
component-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
name: Publish HankLiu-Design Components Into NPM
on:
push:
branches:
# 触发ci/cd的代码分支
- master
pull_request:
branches: [ master ]
jobs:
setup:
# 指定操作系统
runs-on: ubuntu-latest
steps:
# 将代码拉到虚拟机
- name: 获取源码 🛎️
uses: actions/checkout@v2
# 指定node版本
- name: Node环境版本 🗜️
uses: actions/setup-node@v3
with:
node-version: 18
registry-url: 'https://registry.npmjs.org'
- name: 获取lock文件 🎻
uses: actions/cache@v2
with:
path: package-temp-dir
key: lock-${{ github.sha }}
# 仅在不下载任何包的情况下,更新package-lock.json文件。
# 这个命令常用于确保所有的依赖项都是最新的,或者在你不确定更新了哪些包时刷新锁文件。
- name: 更新lock文件 📌
run: npm i --package-lock-only --force
# 缓存lock文件到package-temp-dir路径
- name: 缓存lock文件 🗼
run: |
if [ ! -d "package-temp-dir" ]; then
mkdir package-temp-dir
fi
cp package-lock.json package-temp-dir
# 依赖缓存策略
- name: Npm缓存 📁
id: node_modules_cache_id
uses: actions/cache@v2
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
# 依赖下载
- name: 安装依赖 📦
if: steps.node_modules_cache_id.outputs.cache-hit != 'true'
run: npm ci --force
compile:
runs-on: ubuntu-latest
steps:
# 将代码拉到虚拟机
- name: 获取源码 🛎️
uses: actions/checkout@v2
# 指定node版本
- name: Node环境版本 🗜️
uses: actions/setup-node@v3
with:
node-version: 18
registry-url: 'https://registry.npmjs.org'
# 获取或存的lock文件
- name: 获取lock文件 🎻
uses: actions/cache@v2
with:
path: package-temp-dir
key: lock-${{ github.sha }}
# 依赖缓存策略
- name: Npm缓存 📁
uses: actions/cache@v2
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
# 打包
- name: 打包 🏗️
run: npm run compile
# 发布
- name: 发布 🚀
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
needs: setup
site:
runs-on: ubuntu-latest
steps:
# 将代码拉到虚拟机
- name: 获取源码 🛎️
uses: actions/checkout@v2
# 获取或存的lock文件
- name: 获取lock文件 🎻
uses: actions/cache@v2
with:
path: package-temp-dir
key: lock-${{ github.sha }}
# 依赖缓存策略
- name: Npm缓存 📁
uses: actions/cache@v2
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
# 生成文档
- name: 生成文档 🍚
run: npm run site && touch ./_site/.nojekyll # run: touch ./_website/.nojekyll是因为由于 Jekyll 处理,GitHub 默认不提供_next文件夹,.nojekyll文件阻止了这种情况,
- name: 部署 🚀
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages # 部署后提交到那个分支
folder: _site # 这里填打包好的目录名称
clean: true
needs: compile
tag:
runs-on: ubuntu-latest
steps:
# 将代码拉到虚拟机
- name: 获取源码 🛎️
uses: actions/checkout@v2
- name: 从 package.json 中获得版本 ⭐
id: version
run: echo "VERSION=$(node -p 'require(`./package.json`).version')" >> $GITHUB_ENV
- name: 提交 Tag 🏄
id: tag
run: |
git config --local user.email "${{ secrets.MY_GIT_USER_EMAIL }}"
git config --local user.name "${{ secrets.MY_GIT_USER_NAME }}"
git tag -a v${{ env.VERSION }} -m "create tag v${{ env.VERSION }}"
git push origin v${{ env.VERSION }}
needs: site