integration-tests.yml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. name: API Integration Tests
  2. on:
  3. push:
  4. branches: [ main, develop ]
  5. paths:
  6. - 'src/server/api/**'
  7. - 'src/server/__test_utils__/**'
  8. - 'src/client/__integration_tests__/**'
  9. - '.github/workflows/integration-tests.yml'
  10. pull_request:
  11. branches: [ main ]
  12. paths:
  13. - 'src/server/api/**'
  14. - 'src/server/__test_utils__/**'
  15. - 'src/client/__integration_tests__/**'
  16. - '.github/workflows/integration-tests.yml'
  17. workflow_dispatch:
  18. jobs:
  19. integration-tests:
  20. runs-on: ubuntu-latest
  21. timeout-minutes: 15
  22. services:
  23. postgres:
  24. image: postgres:15
  25. env:
  26. POSTGRES_DB: test_d8dai
  27. POSTGRES_USER: postgres
  28. POSTGRES_PASSWORD: test_password
  29. options: >-
  30. --health-cmd="pg_isready -U postgres"
  31. --health-interval=10s
  32. --health-timeout=5s
  33. --health-retries=3
  34. ports:
  35. - 5432:5432
  36. steps:
  37. - name: Checkout code
  38. uses: actions/checkout@v4
  39. - name: Setup Node.js
  40. uses: actions/setup-node@v4
  41. with:
  42. node-version: '20'
  43. cache: 'pnpm'
  44. - name: Install pnpm
  45. uses: pnpm/action-setup@v2
  46. with:
  47. version: 8
  48. - name: Install dependencies
  49. run: pnpm install --frozen-lockfile
  50. - name: Setup test environment
  51. run: |
  52. cp .env.test.example .env.test
  53. echo "TEST_DATABASE_URL=postgresql://postgres:test_password@localhost:5432/test_d8dai" >> .env.test
  54. echo "NODE_ENV=test" >> .env.test
  55. echo "JWT_SECRET=test_jwt_secret_1234567890" >> .env.test
  56. - name: Run database migrations
  57. run: |
  58. export NODE_ENV=test
  59. pnpm db:migrate
  60. - name: Run integration tests
  61. run: |
  62. export NODE_ENV=test
  63. pnpm test:integration
  64. - name: Upload test results
  65. if: always()
  66. uses: actions/upload-artifact@v4
  67. with:
  68. name: integration-test-results
  69. path: |
  70. coverage/
  71. test-results/
  72. retention-days: 7
  73. - name: Generate test coverage report
  74. if: success()
  75. run: |
  76. npx vitest coverage --reporter=json-summary
  77. - name: Upload coverage to Codecov
  78. if: success()
  79. uses: codecov/codecov-action@v3
  80. with:
  81. file: ./coverage/coverage-final.json
  82. flags: integration-tests
  83. - name: Generate test summary
  84. if: always()
  85. uses: test-summary/action@v2
  86. with:
  87. paths: test-results/junit.xml
  88. - name: Notify on failure
  89. if: failure()
  90. uses: 8398a7/action-slack@v3
  91. with:
  92. status: ${{ job.status }}
  93. channel: '#ci-notifications'
  94. webhook_url: ${{ secrets.SLACK_WEBHOOK }}
  95. env:
  96. SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
  97. - name: Send test results to GitHub
  98. if: always()
  99. uses: dorny/test-reporter@v1
  100. with:
  101. name: Integration Tests
  102. path: test-results/junit.xml
  103. reporter: jest-junit
  104. fail-on-error: false