Skip to content

Commit 6e41c29

Browse files
authored
Merge pull request #18 from php-openapi/17-use-cache-in-tests-in-github-action
Resolve: Use cache in tests in Github actions
2 parents 309f7b2 + 4b8c742 commit 6e41c29

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

.github/workflows/test.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ jobs:
2222
matrix:
2323
php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3']
2424

25-
# TODO use cache
2625
steps:
2726
- uses: actions/checkout@v3
2827

@@ -42,6 +41,21 @@ jobs:
4241
- name: docker-compose up
4342
run: make up
4443

44+
# https://github.com/shivammathur/setup-php?tab=readme-ov-file#cache-composer-dependencies
45+
- name: Get composer cache directory
46+
id: composer-cache
47+
run: echo "dir=./tests/tmp/.composer/cache/files" >> $GITHUB_OUTPUT
48+
49+
- name: Make tests dir writable for restoring cache in next step
50+
run: make tests_dir_write_permission
51+
52+
- name: Cache dependencies
53+
uses: actions/cache@v4
54+
with:
55+
path: ${{ steps.composer-cache.outputs.dir }}
56+
key: ${{ runner.os }}-composer-${{ hashFiles('composer.json') }}
57+
restore-keys: ${{ runner.os }}-composer-
58+
4559
- name: Install Docker and composer dependencies
4660
run: docker-compose exec php php -v && make installdocker
4761

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ cd yii2-openapi
1010
make clean_all
1111
make up
1212
make installdocker
13-
sudo chmod -R 777 tests/tmp/ # https://github.com/cebe/yii2-openapi/issues/156
13+
sudo chmod -R 777 tests/tmp/ # TODO avoid 777 https://github.com/cebe/yii2-openapi/issues/156
1414
make migrate
1515

1616
# to check everything is setup up correctly ensure all tests passes

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ migrate:
5757
installdocker:
5858
docker-compose run --user=$(UID) --rm php composer install && chmod +x tests/yii
5959

60+
tests_dir_write_permission:
61+
docker-compose run --user="root" --rm php chmod -R 777 tests/tmp/ # TODO avoid 777 https://github.com/cebe/yii2-openapi/issues/156
62+
6063
testdocker:
6164
docker-compose run --user=$(UID) --rm php sh -c 'vendor/bin/phpunit --repeat 3'
6265

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ services:
4545
ports:
4646
- '23306:3306'
4747
volumes:
48-
- ./tests/tmp/maria:/var/lib/mysql:rw
48+
- ./tests/tmp/mariadb:/var/lib/mariadb:rw
4949
environment:
5050
# TZ: UTC
5151
# MARIADB_ALLOW_EMPTY_PASSWORD: 1

0 commit comments

Comments
 (0)