tests.yml 3.4 KB

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