Feature/qol improve #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Test | |
| on: | |
| pull_request: | |
| branches: [main, master] | |
| push: | |
| branches: [main, master] | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| services: | |
| postgres: | |
| image: postgres:15 | |
| env: | |
| POSTGRES_DB: que_test | |
| POSTGRES_USER: que_user | |
| POSTGRES_PASSWORD: que_password | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| ports: | |
| - 5432:5432 | |
| strategy: | |
| matrix: | |
| node-version: [18.x, 20.x, 22.x] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Use Node.js ${{ matrix.node-version }} | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Set up database schema | |
| run: | | |
| PGPASSWORD=que_password psql -h localhost -U que_user -d que_test -f migrations/schema.sql | |
| env: | |
| PGPASSWORD: que_password | |
| - name: Run linter | |
| run: npm run lint | |
| - name: Run TypeScript compiler check | |
| run: npx tsc --noEmit | |
| - name: Run tests | |
| id: test-run | |
| run: | | |
| npm test 2>&1 | tee test-output.log | |
| echo "test_status=success" >> $GITHUB_OUTPUT | |
| env: | |
| TEST_DB_HOST: localhost | |
| TEST_DB_PORT: 5432 | |
| TEST_DB_NAME: que_test | |
| TEST_DB_USER: que_user | |
| TEST_DB_PASSWORD: que_password | |
| TEST_DB_SSL: false | |
| continue-on-error: true | |
| - name: Handle test failure | |
| if: failure() | |
| run: | | |
| echo "test_status=failure" >> $GITHUB_OUTPUT | |
| - name: Build package | |
| run: npm run build | |
| - name: Check package can be published | |
| run: npm pack --dry-run | |
| - name: Comment PR - Test Results | |
| if: github.event_name == 'pull_request' && matrix.node-version == '20.x' && always() | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const nodeVersion = '${{ matrix.node-version }}'; | |
| const testStatus = '${{ steps.test-run.outputs.test_status || 'failure' }}'; | |
| let testOutput = ''; | |
| try { | |
| testOutput = fs.readFileSync('test-output.log', 'utf8'); | |
| } catch (error) { | |
| testOutput = 'Could not read test output'; | |
| } | |
| // Extract test summary from output | |
| const testSummary = testOutput.match(/Test Suites:.*\n.*Tests:.*\n/g)?.[0] || 'Test summary not available'; | |
| const hasPassed = testStatus === 'success'; | |
| const comment = `## π§ͺ Test Results | |
| **Node.js Version**: ${nodeVersion} | |
| **Status**: ${hasPassed ? 'β All tests passed!' : 'β Tests failed'} | |
| ### Summary | |
| ${hasPassed ? '- β **Linting**: Passed' : '- β **Linting**: Check required'} | |
| ${hasPassed ? '- β **TypeScript Compilation**: Passed' : '- β **TypeScript Compilation**: Failed'} | |
| ${hasPassed ? '- β **Unit Tests**: All 16 tests passed' : '- β **Unit Tests**: Some tests failed'} | |
| ${hasPassed ? '- β **Package Build**: Passed' : '- β **Package Build**: Failed'} | |
| ${hasPassed ? '- β **Package Verification**: Ready for publishing' : '- β **Package Verification**: Issues found'} | |
| ### Database Tests | |
| ${hasPassed ? '- PostgreSQL connection: β Working' : '- PostgreSQL connection: β Issues detected'} | |
| ${hasPassed ? '- Advisory locks: β Functional' : '- Advisory locks: β Problems found'} | |
| ${hasPassed ? '- Job processing: β Tested' : '- Job processing: β Failures detected'} | |
| ${hasPassed ? '- Error handling: β Verified' : '- Error handling: β Issues found'} | |
| ### Test Output Summary | |
| \`\`\` | |
| ${testSummary} | |
| \`\`\` | |
| ${!hasPassed ? ` | |
| <details> | |
| <summary>π Detailed Test Output</summary> | |
| \`\`\` | |
| ${testOutput.substring(Math.max(0, testOutput.length - 1500))} | |
| \`\`\` | |
| </details> | |
| ` : ''} | |
| --- | |
| *Automated comment by GitHub Actions*`; | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: comment | |
| }); |