tests.yml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 --log-junit results.xml
  85. working-directory: tst
  86. - name: Upload Test Results
  87. if: always()
  88. uses: actions/upload-artifact@v4
  89. with:
  90. name: Test Results (PHP ${{ matrix.php-versions }})
  91. path: tst/results.xml
  92. Mocha:
  93. runs-on: ubuntu-latest
  94. steps:
  95. - name: Checkout
  96. uses: actions/checkout@v4
  97. - name: Setup Node
  98. uses: actions/setup-node@v4
  99. with:
  100. node-version: '20'
  101. cache: 'npm'
  102. cache-dependency-path: 'js/package-lock.json'
  103. - name: Setup Mocha
  104. run: npm install -g mocha
  105. - name: Setup Node modules
  106. run: npm ci
  107. working-directory: js
  108. - name: Run unit tests
  109. run: npm run ci-test
  110. working-directory: js
  111. - name: Upload Test Results
  112. if: always()
  113. uses: actions/upload-artifact@v4
  114. with:
  115. name: Test Results (Mocha)
  116. path: js/mocha-results.xml
  117. publish-test-results:
  118. name: "Publish Tests Results"
  119. needs: ['PHPunit', 'Mocha']
  120. runs-on: ubuntu-latest
  121. permissions:
  122. checks: write
  123. # only needed unless run with comment_mode: off
  124. pull-requests: write
  125. if: always()
  126. steps:
  127. - name: Download Artifacts
  128. uses: actions/download-artifact@v4
  129. with:
  130. path: artifacts
  131. - name: Publish Test Results
  132. uses: EnricoMi/publish-unit-test-result-action@v2
  133. with:
  134. check_name: "Test Results (${{ github.event.workflow_run.event || github.event_name }})"
  135. files: |
  136. artifacts/**/*.xml
  137. artifacts/**/*.trx
  138. artifacts/**/*.json