From 9e73ffcaf172a1ef0034425339018f269041df3b Mon Sep 17 00:00:00 2001 From: Christian Kolb Date: Wed, 14 Feb 2024 13:24:07 +0100 Subject: [PATCH] Add caching to github actions --- .github/workflows/ci.yml | 89 ++++++++++++++++++++++++++++++++++------ Makefile | 8 ++-- 2 files changed, 81 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 25aafa4..9a4de8e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,13 +6,32 @@ jobs: name: "Tests on PHP 8.2" runs-on: ubuntu-latest steps: + - uses: actions/checkout@v2 + + - name: Setup env + run: cp .github/workflows/.env .env + + - name: Cache PHP 8.2 dependencies + id: cache-php-8-2-dependencies + uses: actions/cache@v3 + env: + cache-name: cache-php-8-2-dependencies + with: + path: | + ~/.cache + vendor + key: ${{ runner.os }}-php-8-2-cache-${{ hashFiles('composer.lock') }} + restore-keys: | + ${{ runner.os }}-php-8-2-cache-${{ hashFiles('composer.lock') }} + - name: Install - run: | - cp .github/workflows/.env .env - make install-8.2 + if: steps.cache-php-8-2-dependencies.outputs.cache-hit != 'true' + run: make install-8.2 + - name: Run PHP tests run: make php-8.2-tests-ci + - name: Upload to Codecov uses: codecov/codecov-action@v2 with: @@ -24,11 +43,29 @@ jobs: name: "Tests on PHP 8.3" runs-on: ubuntu-latest steps: + - uses: actions/checkout@v2 + + - name: Setup env + run: cp .github/workflows/.env .env + + - name: Cache PHP 8.3 dependencies + id: cache-php-8-3-dependencies + uses: actions/cache@v3 + env: + cache-name: cache-php-8-3-dependencies + with: + path: | + ~/.cache + vendor + key: ${{ runner.os }}-php-8-3-cache-${{ hashFiles('composer.lock') }} + restore-keys: | + ${{ runner.os }}-php-8-3-cache-${{ hashFiles('composer.lock') }} + - name: Install - run: | - cp .github/workflows/.env .env - make install-8.3 + if: steps.cache-php-8-3-dependencies.outputs.cache-hit != 'true' + run: make install-8.3 + - name: Run PHP tests run: make php-8.3-tests-ci @@ -36,11 +73,25 @@ jobs: name: "Mutation tests" runs-on: ubuntu-latest steps: + - uses: actions/checkout@v2 + + - name: Setup env + run: cp .github/workflows/.env .env + + - name: Restore cache for PHP 8.3 dependencies + id: cache-php-8-3-dependencies + uses: actions/cache/restore@v3 + with: + path: | + ~/.cache + vendor + key: ${{ runner.os }}-php-8-3-cache-${{ hashFiles('composer.lock') }} + - name: Install - run: | - cp .github/workflows/.env .env - make install-8.2 + if: steps.cache-php-8-3-dependencies.outputs.cache-hit != 'true' + run: make install-8.3 + - name: Run mutation testing run: make php-mutation-testing-ci @@ -48,10 +99,24 @@ jobs: name: "Code validation" runs-on: ubuntu-latest steps: + - uses: actions/checkout@v2 + + - name: Setup env + run: cp .github/workflows/.env .env + + - name: Restore cache for PHP 8.3 dependencies + id: cache-php-8-3-dependencies + uses: actions/cache/restore@v3 + with: + path: | + ~/.cache + vendor + key: ${{ runner.os }}-php-8-3-cache-${{ hashFiles('composer.lock') }} + - name: Install - run: | - cp .github/workflows/.env .env - make install + if: steps.cache-php-8-3-dependencies.outputs.cache-hit != 'true' + run: make install-8.3 + - name: Run code validation run: make php-code-validation diff --git a/Makefile b/Makefile index 0689b6f..fe68b25 100644 --- a/Makefile +++ b/Makefile @@ -52,9 +52,9 @@ reset: .reset .PHONY: .reset .reset: .down .install .up -## install Install PHP dependencies with the default PHP version (8.1). +## install Install PHP dependencies with the default PHP version (8.3). .PHONY: .install -install: install-8.2 +install: install-8.3 ## install-8.2 Install PHP dependencies with PHP 8.2. .PHONY: install-8.2 @@ -66,9 +66,9 @@ install-8.2: install-8.3: docker-compose run --rm php-8.3 composer install -## php-cli Enter a shell for the default PHP version (8.2). +## php-cli Enter a shell for the default PHP version (8.3). .PHONY: php-cli -php-cli: php-8.2-cli +php-cli: php-8.3-cli ## php-8.2-cli Enter a shell for PHP 8.2. .PHONY: php-8.2-cli