Skip to content

Resolve: Use cache in tests in Github actions #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Nov 12, 2024
16 changes: 15 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ jobs:
matrix:
php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3']

# TODO use cache
steps:
- uses: actions/checkout@v3

Expand All @@ -42,6 +41,21 @@ jobs:
- name: docker-compose up
run: make up

# https://github.com/shivammathur/setup-php?tab=readme-ov-file#cache-composer-dependencies
- name: Get composer cache directory
id: composer-cache
run: echo "dir=./tests/tmp/.composer/cache/files" >> $GITHUB_OUTPUT

- name: Make tests dir writable for restoring cache in next step
run: make tests_dir_write_permission

- name: Cache dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install Docker and composer dependencies
run: docker-compose exec php php -v && make installdocker

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cd yii2-openapi
make clean_all
make up
make installdocker
sudo chmod -R 777 tests/tmp/ # https://github.com/cebe/yii2-openapi/issues/156
sudo chmod -R 777 tests/tmp/ # TODO avoid 777 https://github.com/cebe/yii2-openapi/issues/156
make migrate

# to check everything is setup up correctly ensure all tests passes
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ migrate:
installdocker:
docker-compose run --user=$(UID) --rm php composer install && chmod +x tests/yii

tests_dir_write_permission:
docker-compose run --user="root" --rm php chmod -R 777 tests/tmp/ # TODO avoid 777 https://github.com/cebe/yii2-openapi/issues/156

testdocker:
docker-compose run --user=$(UID) --rm php sh -c 'vendor/bin/phpunit --repeat 3'

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ services:
ports:
- '23306:3306'
volumes:
- ./tests/tmp/maria:/var/lib/mysql:rw
- ./tests/tmp/mariadb:/var/lib/mariadb:rw
environment:
# TZ: UTC
# MARIADB_ALLOW_EMPTY_PASSWORD: 1
Expand Down
Loading