tests.yml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. name: PHP ${{ matrix.php-versions }} unit tests on ${{ matrix.operating-system }}
  17. runs-on: ubuntu-latest
  18. # https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs#handling-failures
  19. continue-on-error: "${{ matrix.experimental }}"
  20. strategy:
  21. matrix:
  22. php-versions: ['7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
  23. experimental: [false]
  24. include:
  25. - php-versions: '8.4' # development release, things can break
  26. experimental: true
  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: Unset platform requirement
  79. run: composer config --unset platform
  80. - name: Setup PHPunit
  81. run: composer install -n
  82. - name: Install Google Cloud Storage
  83. run: composer require google/cloud-storage
  84. # testing
  85. - name: Run unit tests
  86. run: ../vendor/bin/phpunit --no-coverage --log-junit results.xml
  87. working-directory: tst
  88. - name: Upload Test Results
  89. if: always()
  90. uses: actions/upload-artifact@v4
  91. with:
  92. name: Test Results (PHP ${{ matrix.php-versions }})
  93. path: tst/results.xml
  94. Mocha:
  95. runs-on: ubuntu-latest
  96. steps:
  97. - name: Checkout
  98. uses: actions/checkout@v4
  99. - name: Setup Node
  100. uses: actions/setup-node@v4
  101. with:
  102. node-version: '20'
  103. cache: 'npm'
  104. cache-dependency-path: 'js/package-lock.json'
  105. - name: Setup Mocha
  106. run: npm install -g mocha
  107. - name: Setup Node modules
  108. run: npm ci
  109. working-directory: js
  110. - name: Run unit tests
  111. run: npm run ci-test
  112. working-directory: js
  113. - name: Upload Test Results
  114. if: always()
  115. uses: actions/upload-artifact@v4
  116. with:
  117. name: Test Results (Mocha)
  118. path: js/mocha-results.xml
  119. event_file:
  120. name: "Event File"
  121. runs-on: ubuntu-latest
  122. steps:
  123. - name: Upload
  124. uses: actions/upload-artifact@v4
  125. with:
  126. name: Event File
  127. path: "${{ github.event_path }}"