我正在使用GitHub操作来构建我的TypeScript项目.

有没有办法缓存Yarn 相关性,这样构建时间会更快?

我试过这个:

     - name: Get yarn cache directory path
       id: yarn-cache-dir-path
       run: echo "::set-output name=dir::$(yarn cache dir)"

     - uses: actions/cache@v1
       id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
       with:
         path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
         key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
         restore-keys: |
           ${{ runner.os }}-yarn-

    - name: Install yarn
      run: npm install -g yarn

    - name: Install project dependencies
      run: yarn

但构建时间仍然是一样的.

推荐答案

如缓存步骤id字段旁边的注释所述:

用这个判断cache-hit(steps.yarn-cache.outputs.cache-hit != 'true')

您缺少一个决定是否应运行该步骤的条件if属性:

- name: Install yarn
  run: npm install -g yarn

- name: Install project dependencies
  if: steps.yarn-cache.outputs.cache-hit != 'true' # Over here!
  run: yarn

另外,您可能应该使用Setup NodeJS GitHub操作,为您额外设置Yarn :

- uses: actions/setup-node@v1
  with:
    node-version: '10.x' # The version spec of the version to use.

有关有效输入的完整列表,请参见action.yml file.


编辑:事实证明,Yarn 包含在software installed on the GitHub-hosted Ubuntu 18.04.4 LTS (ubuntu-latest/ubuntu-18.04) runner个列表中,因此无需包括全球安装Yarn 的步骤.

Typescript相关问答推荐

与Prettify助手类型中的对象相交?

推断类型

如何修复VueJS中的val类型不能赋给函数

VS代码1.88.0中未出现自动导入建议

类型安全JSON解析

在Typescribe中,extends工作,但当指定派生给super时出错""

如何为父类构造函数中的修饰属性赋值?

如何在使用`Next—intl`和`next/link`时导航

类型脚本返回的类型包含无意义的泛型类型名称

从TypeScrip中的其他类型检索泛型类型

嵌套对象的类型

如何在Reaction Query Builder中添加其他字段?

在排版修饰器中推断方法响应类型

Angular:ngx-echart 5.2.2与Angular 9集成错误:NG 8002:无法绑定到选项,因为它不是div的已知属性'

下载量怎么会超过下载量?

ANGLE订阅要么不更新价值,要么不识别价值变化

如何使这种一对一关系在旧表上起作用?

从以下内容之一提取属性类型

定义一个只允许来自另一个类型的特定字符串文字的类型的最佳方式

对象只能使用 Typescript 中另一个对象的键