Merge pull request #840 from PrivateBin/ci-cache

Cache PHP modules, composer and NodeJS stuff in CI
This commit is contained in:
El RIDO 2021-10-04 10:03:31 +02:00 committed by GitHub
commit 981304848f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@ name: Tests
on: [push] on: [push]
jobs: jobs:
Composer: Composer:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
@ -11,43 +12,109 @@ jobs:
run: composer validate run: composer validate
- name: Install dependencies - name: Install dependencies
run: composer install --prefer-dist --no-dev run: composer install --prefer-dist --no-dev
PHPunit: PHPunit:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4'] php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4']
name: PHP ${{ matrix.php-versions }} unit tests on ${{ matrix.operating-system }} name: PHP ${{ matrix.php-versions }} unit tests on ${{ matrix.operating-system }}
env:
extensions: gd, sqlite3
extensions-cache-key-name: phpextensions
steps: steps:
# let's get started!
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
# cache PHP extensions
- name: Setup cache environment
id: extcache
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php-versions }}
extensions: ${{ env.extensions }}
key: ${{ runner.os }}-${{ env.extensions-cache-key }}
- name: Cache extensions
uses: actions/cache@v2
with:
path: ${{ steps.extcache.outputs.dir }}
key: ${{ steps.extcache.outputs.key }}
restore-keys: ${{ runner.os }}-${{ env.extensions-cache-key }}
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v2 uses: shivammathur/setup-php@v2
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: gd, sqlite3 extensions: ${{ env.extensions }}
# Setup GitHub CI PHP problem matchers
# https://github.com/shivammathur/setup-php#problem-matchers
- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
# composer cache
- name: Remove composer lock - name: Remove composer lock
run: rm composer.lock run: rm composer.lock
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
# http://man7.org/linux/man-pages/man1/date.1.html
# https://github.com/actions/cache#creating-a-cache-key
- name: Get Date
id: get-date
run: |
echo "::set-output name=date::$(/bin/date -u "+%Y%m%d")"
shell: bash
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-${{ steps.get-date.outputs.date }}-
# composer installation
- name: Setup PHPunit - name: Setup PHPunit
run: composer install -n run: composer install -n
- name: Install Google Cloud Storage - name: Install Google Cloud Storage
run: composer require google/cloud-storage run: composer require google/cloud-storage
# testing
- name: Run unit tests - name: Run unit tests
run: ../vendor/bin/phpunit --no-coverage run: ../vendor/bin/phpunit --no-coverage
working-directory: tst working-directory: tst
Mocha: Mocha:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup Node - name: Setup Node
uses: actions/setup-node@v1 uses: actions/setup-node@v2
with: with:
node-version: '12' node-version: '12'
cache: 'npm'
cache-dependency-path: 'js/package.json'
- name: Setup Mocha - name: Setup Mocha
run: npm install -g mocha run: npm install -g mocha
- name: Setup Node modules - name: Setup Node modules
run: npm install run: npm install
working-directory: js working-directory: js
- name: Run unit tests - name: Run unit tests
run: mocha run: mocha
working-directory: js working-directory: js