【问题标题】:Saving cache on job failure in GitHub Actions在 GitHub Actions 中保存作业失败的缓存
【发布时间】:2020-06-14 22:12:57
【问题描述】:

我正在使用 GitHub cache 操作,但我注意到如果作业失败,将不会创建缓存。来自docs

如果作业成功完成,该操作会使用路径目录的内容创建一个新缓存。

我的工作流程 YAML 文件的精简版:

name: Build

on: [push]

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v1

      - name: Setup Node.js
        uses: actions/setup-node@master
        with:
          node-version: '10.x'

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

      - name: Restore yarn cache
        uses: actions/cache@v1
        id: yarn-cache
        with:
          path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-

      - name: Install yarn dependencies
        run: yarn install

      - name: Build
        run: yarn build

我注意到如果我的Build 步骤失败,cache 后步骤将被不必要地跳过,这会导致安装的依赖项不会被缓存。这需要后续运行以再次下载依赖项,从而减慢工作速度。

有没有办法始终缓存依赖项,即使构建步骤失败?

【问题讨论】:

    标签: github continuous-integration continuous-deployment github-actions


    【解决方案1】:

    在官方版本的action中,如果构建失败,是不可能缓存依赖的。请参阅缓存操作清单中的this line

    runs:
      using: 'node12'
      main: 'dist/restore/index.js'
      post: 'dist/save/index.js'
      post-if: 'success()'
    

    如果作业成功,它只会运行后步骤。我不知道最初的原因,但是围绕这个想法存在一些问题。在this issue 中,用户forked the actionpost-if 更改为always(),这可能是您所追求的,假设您愿意执行非官方操作。

    【讨论】:

    • 官方动作中不能配置有什么原因吗?
    猜你喜欢
    • 2021-07-12
    • 2020-12-10
    • 2020-04-03
    • 2020-07-19
    • 1970-01-01
    • 2023-01-27
    • 1970-01-01
    • 2020-07-15
    • 2021-11-18
    相关资源
    最近更新 更多