[英]Github actions/cache has no effect on my workflow
I am trying to run the following Github workflow for a php project:我正在尝试为 php 项目运行以下 Github 工作流程:
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
env:
DB_NAME: ${{ secrets.DB_NAME }}
DB_USER: ${{ secrets.DB_USER }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
MYSQL_ROOT_PASSWORD: ${{ secrets.MYSQL_ROOT_PASSWORD }}
steps:
- uses: actions/checkout@v2
- name: Set up the CI environment
run: |
envsubst < src/.env.ci > src/.env
docker pull composer
alias composer="docker run --rm --interactive --tty --volume $(pwd):/app --volume ${COMPOSER_HOME:-$HOME/.composer}:/tmp --user $(id -u):$(id -g) composer"
composer --version
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install composer dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install
The scenario is the following.场景如下。 I have a docker based development environment orchestrated with docker-compose.
我有一个使用 docker-compose 编排的基于 docker 的开发环境。 Php composer and other tools are run from docker images.
Php composer 和其他工具是从 docker 镜像运行的。
It seems that i am missing something here because the cache-hit
is taking place as I see in logs:似乎我在这里遗漏了一些东西,因为正如我在日志中看到的那样,正在发生
cache-hit
:
2020-03-28T10:37:07.2837003Z Cache restored from key: Linux-composer-0dffe7e110c8249b30d4e46844fede7ea6b8e1433061bed12cbb9a2ae964e2bb
But is not taking effect because the step Install composer dependencies
is still running and downloading artifacts.但未生效,因为
Install composer dependencies
步骤仍在运行并正在下载工件。 My expectation is that either does not run or run but does not download anything since it takes all from restored cached.我的期望是要么不运行,要么不运行但不下载任何东西,因为它从恢复的缓存中获取所有内容。
Does anyone have an idea of what I am missing?有没有人知道我缺少什么?
UPDATE更新
I did accepted @edric answer because on this context where i asked my question his answer provided the solution for my question.我确实接受了@edric 的回答,因为在我提出问题的上下文中,他的回答为我的问题提供了解决方案。 Although I muss say it was not completely the solution.
虽然我必须说这不是完全的解决方案。
I needed to delete the condition: if: steps.composer-cache.outputs.cache-hit != 'true'
from last step to get the rest of my workflow running.我需要删除条件:
if: steps.composer-cache.outputs.cache-hit != 'true'
从最后一步开始运行我的工作流程的其余部分。 I did noticed that the composer cache was restored and that composer install
was not run, causing problems later on due to missing dependencies.我确实注意到 Composer 缓存已恢复,并且
composer install
未运行,由于缺少依赖项而导致稍后出现问题。 Without the if condition composer install run always but using the restored cache.没有 if 条件 composer install 总是运行但使用恢复的缓存。
That's because you didn't set an ID on the step that caches your lock file and you're also using the wrong ID in the following step to check if a cache was hit.那是因为您没有在缓存锁定文件的步骤上设置 ID,并且您还在以下步骤中使用了错误的 ID 来检查是否命中了缓存。 I suggest that you should rename the ID of the step that retrieves the cache directory to a different ID so as to not confuse yourself:
我建议您将检索缓存目录的步骤的 ID 重命名为不同的 ID,以免混淆:
- name: Get Composer Cache Directory
id: get-composer-cache-dir # Instead of composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache Composer
uses: actions/cache@v1
id: composer-cache
with:
path: ${{ steps.get-composer-cache-dir.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install composer dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.