tests.yml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. name: Tests
  2. on:
  3. push:
  4. workflow_dispatch:
  5. jobs:
  6. Composer:
  7. runs-on: ubuntu-latest
  8. # https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs#handling-failures
  9. continue-on-error: ${{ matrix.experimental }}
  10. steps:
  11. - name: Checkout
  12. uses: actions/checkout@v4
  13. - name: Validate composer.json and composer.lock
  14. run: composer validate
  15. - name: Install dependencies
  16. run: composer install --prefer-dist --no-dev
  17. PHPunit:
  18. runs-on: ubuntu-latest
  19. strategy:
  20. matrix:
  21. php-versions: ['7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
  22. include:
  23. # 8.4 is experimental due to Guzzle causing failures https://github.com/PrivateBin/PrivateBin/issues/1301
  24. - php-versions: '8.4'
  25. experimental: true
  26. name: PHP ${{ matrix.php-versions }} unit tests on ${{ matrix.operating-system }}
  27. env:
  28. extensions: gd, sqlite3
  29. extensions-cache-key-name: phpextensions
  30. steps:
  31. # let's get started!
  32. - name: Checkout
  33. uses: actions/checkout@v4
  34. # cache PHP extensions
  35. - name: Setup cache environment
  36. id: extcache
  37. uses: shivammathur/cache-extensions@v1
  38. with:
  39. php-version: ${{ matrix.php-versions }}
  40. extensions: ${{ env.extensions }}
  41. key: ${{ runner.os }}-${{ env.extensions-cache-key }}
  42. - name: Cache extensions
  43. uses: actions/cache@v4
  44. with:
  45. path: ${{ steps.extcache.outputs.dir }}
  46. key: ${{ steps.extcache.outputs.key }}
  47. restore-keys: ${{ runner.os }}-${{ env.extensions-cache-key }}
  48. - name: Setup PHP
  49. uses: shivammathur/setup-php@v2
  50. with:
  51. php-version: ${{ matrix.php-versions }}
  52. extensions: ${{ env.extensions }}
  53. # Setup GitHub CI PHP problem matchers
  54. # https://github.com/shivammathur/setup-php#problem-matchers
  55. - name: Setup problem matchers for PHP
  56. run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
  57. - name: Setup problem matchers for PHPUnit
  58. run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
  59. # composer cache
  60. - name: Remove composer lock
  61. run: rm composer.lock
  62. - name: Get composer cache directory
  63. id: composer-cache
  64. run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
  65. # http://man7.org/linux/man-pages/man1/date.1.html
  66. # https://github.com/actions/cache#creating-a-cache-key
  67. - name: Get Date
  68. id: get-date
  69. run: echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
  70. shell: bash
  71. - name: Cache dependencies
  72. uses: actions/cache@v4
  73. with:
  74. path: ${{ steps.composer-cache.outputs.dir }}
  75. key: ${{ runner.os }}-composer-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/composer.json') }}
  76. restore-keys: ${{ runner.os }}-composer-${{ steps.get-date.outputs.date }}-
  77. # composer installation
  78. - name: Setup PHPunit
  79. run: composer install -n
  80. - name: Install Google Cloud Storage
  81. run: composer require google/cloud-storage
  82. # testing
  83. - name: Run unit tests
  84. run: ../vendor/bin/phpunit --no-coverage
  85. working-directory: tst
  86. Mocha:
  87. runs-on: ubuntu-latest
  88. steps:
  89. - name: Checkout
  90. uses: actions/checkout@v4
  91. - name: Setup Node
  92. uses: actions/setup-node@v4
  93. with:
  94. node-version: '20'
  95. cache: 'npm'
  96. cache-dependency-path: 'js/package-lock.json'
  97. - name: Setup Mocha
  98. run: npm install -g mocha
  99. - name: Setup Node modules
  100. run: npm ci
  101. working-directory: js
  102. - name: Run unit tests
  103. run: npm test
  104. working-directory: js