paste.chapril.org-privatebin/.github/workflows/tests.yml

180 lines
5.1 KiB
YAML
Raw Normal View History

name: Tests
2022-10-26 05:30:37 +02:00
on:
push:
workflow_dispatch:
jobs:
Composer:
runs-on: ubuntu-latest
# https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs#handling-failures
continue-on-error: ${{ matrix.experimental }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Validate composer.json and composer.lock
run: composer validate
- name: Install dependencies
2021-05-30 09:17:23 +02:00
run: composer install --prefer-dist --no-dev
2022-10-25 06:53:26 +02:00
PHPunit:
2020-05-31 15:53:57 +02:00
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
include:
# 8.4 is experimental due to Guzzle causing failures https://github.com/PrivateBin/PrivateBin/issues/1301
- php-versions: '8.4'
experimental: true
name: PHP ${{ matrix.php-versions }} unit tests on ${{ matrix.operating-system }}
env:
extensions: gd, sqlite3
extensions-cache-key-name: phpextensions
2022-10-25 06:53:26 +02:00
steps:
2022-10-25 06:53:26 +02:00
# let's get started!
- name: Checkout
uses: actions/checkout@v4
2022-10-25 06:53:26 +02:00
# 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@v4
with:
path: ${{ steps.extcache.outputs.dir }}
key: ${{ steps.extcache.outputs.key }}
restore-keys: ${{ runner.os }}-${{ env.extensions-cache-key }}
2022-10-25 06:53:26 +02:00
- name: Setup PHP
2020-05-31 15:53:57 +02:00
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: ${{ env.extensions }}
2022-10-25 06:53:26 +02:00
2021-10-02 01:07:57 +02:00
# Setup GitHub CI PHP problem matchers
# https://github.com/shivammathur/setup-php#problem-matchers
- name: Setup problem matchers for PHP
2022-10-25 06:53:26 +02:00
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
2021-10-02 01:07:57 +02:00
- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
2022-10-25 06:53:26 +02:00
# composer cache
- name: Remove composer lock
run: rm composer.lock
2022-10-25 06:53:26 +02:00
- name: Get composer cache directory
id: composer-cache
2022-10-26 05:51:36 +02:00
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
# 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
2022-10-26 05:51:36 +02:00
run: echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
shell: bash
2022-10-25 06:53:26 +02:00
- name: Cache dependencies
uses: actions/cache@v4
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 }}-
2022-10-25 06:53:26 +02:00
2021-10-02 01:12:08 +02:00
# composer installation
- name: Setup PHPunit
run: composer install -n
2021-10-02 01:12:08 +02:00
2021-05-28 22:39:50 +02:00
- name: Install Google Cloud Storage
run: composer require google/cloud-storage
2022-10-25 06:53:26 +02:00
# testing
- name: Run unit tests
run: ../vendor/bin/phpunit --no-coverage --log-junit results.xml
working-directory: tst
2022-10-25 06:53:26 +02:00
- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v4
with:
name: Test Results (PHP ${{ matrix.php-versions }})
path: tst/results.xml
Mocha:
runs-on: ubuntu-latest
steps:
2022-10-25 06:53:26 +02:00
- name: Checkout
uses: actions/checkout@v4
2022-10-25 06:53:26 +02:00
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '20'
2021-10-02 00:55:08 +02:00
cache: 'npm'
cache-dependency-path: 'js/package-lock.json'
2022-10-25 06:53:26 +02:00
- name: Setup Mocha
run: npm install -g mocha
2022-10-25 06:53:26 +02:00
- name: Setup Node modules
run: npm ci
working-directory: js
2022-10-25 06:53:26 +02:00
- name: Run unit tests
2024-05-04 13:14:25 +02:00
run: npm run ci-test
working-directory: js
- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v4
with:
name: Test Results (Mocha)
2024-05-04 13:13:22 +02:00
path: js/mocha-results.xml
event_file:
name: "Event File"
runs-on: ubuntu-latest
steps:
- name: Upload
uses: actions/upload-artifact@v4
with:
name: Event File
path: ${{ github.event_path }}
publish-test-results:
name: "Publish Tests Results"
needs: ['PHPunit', 'Mocha']
runs-on: ubuntu-latest
permissions:
checks: write
# only needed unless run with comment_mode: off
pull-requests: write
if: always()
steps:
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
with:
check_name: "Test Results (${{ github.event.workflow_run.event || github.event_name }})"
commit: ${{ github.event.workflow_run.head_sha }}
event_file: artifacts/Event File/event.json
event_name: ${{ github.event.workflow_run.event }}
files: |
artifacts/**/*.xml
artifacts/**/*.trx
artifacts/**/*.json