I am trying to run the following Github workflow for a php project:
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. Php composer and other tools are run from docker images.
It seems that i am missing something here because the cache-hit is taking place as I see in logs:
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. 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. 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. I did noticed that the composer cache was
restored and that composer install was not run, causing problems later on due to missing dependencies. Without the if condition composer install run always but using the restored cache.