integration-tests.yml 2.9 KB

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