0%

2020-12-08 Github Actions 使用

2020-12-08 Github Actions 使用

在项目根目录下新建 .github 文件夹,在.github 文件夹下新建 workflows文件夹。里面放一个及以上的 yml 文件即可。

以我常用的 Node.js 项目为例,有以下模板

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
# release.yml
name: Release
on:
push:
branches:
- master
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Node.js environment # 设置 Node.js 环境
uses: actions/setup-node@v2.1.2
with:
node-version: "14"
- name: Cache multiple paths #设置缓存
uses: actions/cache@v2
with:
path: |
~/.npm
~/cache
!~/cache/exclude
**/node_modules
key: npm-${{ runner.os }}-${{ hashFiles('package.json') }}
- run: yarn
- run: npm run lint
- run: npm run build
- env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm run release # release 依旧采用了我习惯的 semantic-release

其他语言也是类似的写法,差不多就这样,剩下的看官方文档就行了

本文作者:草梅友仁
本文地址: https://blog.cmyr.ltd/archives/e86d692f.html
版权声明:转载请注明出处!

坚持原创技术分享,您的支持将鼓励我继续创作!