Skip to content

Commit

Permalink
Merge pull request #18 from php-openapi/17-use-cache-in-tests-in-gith…
Browse files Browse the repository at this point in the history
…ub-action

Resolve: Use cache in tests in Github actions
  • Loading branch information
cebe authored Nov 12, 2024
2 parents 309f7b2 + 4b8c742 commit 6e41c29
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
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

0 comments on commit 6e41c29

Please sign in to comment.