Home 在Github Actions中使用Yarn
Post
Cancel

在Github Actions中使用Yarn

Yarn 的呼声时不时比 npm 大,在 Github Actions 里怎么使用 Yarn 呢?

用 npm 的示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
name: Node CI

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [8.x, 10.x, 12.x]

    steps:
      - uses: actions/checkout@v1
      - name: Use Node.js $
        uses: actions/setup-node@v1
        with:
          node-version: $
      - name: npm install, build, and test
        run: |
          npm install
          npm run build --if-present
          npm test

通过 npm 来安装 Yarn

1
2
3
4
5
6
7
8
9
...
steps:
- uses: actions/checkout@v1
- name: Uses Node.js $
  uses: actions/setup-node@v1
  with:
  	node-version: $
- run: npm install -g yarn # Extra Step
...

用 Yarn 替换掉 npm

1
2
3
4
5
6
7
---
- name: yarn install, build, and test
  run: |
    yarn install
    yarn run build
    yarn test

完整的例子

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
# .github/workflows/nodejs.yml
name: Node CI

on: [push, pull_request] # Run on Push and Pull Requests

jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [10.x] # Only run the 10.x build

    steps:
      - uses: actions/checkout@v1
      - name: Use Node.js $
        uses: actions/setup-node@v1
        with:
          node-version: $
      - run: npm install -g yarn
      - name: yarn install, build, and test
        run: |
          yarn
          yarn build
          yarn test
This post is licensed under CC BY 4.0 by the author.

如何快速将SSH指纹添加到known_hosts文件中

Linux里的文件传输

Comments powered by Disqus.