|
| 1 | +name: External Dependency Test |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + triggering_repo: |
| 7 | + description: 'Repository that triggered this test' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + triggering_pr: |
| 11 | + description: 'PR number from triggering repository' |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + preview_url: |
| 15 | + description: 'Preview package URL' |
| 16 | + required: true |
| 17 | + type: string |
| 18 | + package_name: |
| 19 | + description: 'Package name being tested' |
| 20 | + required: true |
| 21 | + type: string |
| 22 | + triggering_sha: |
| 23 | + description: 'SHA from triggering repository' |
| 24 | + required: true |
| 25 | + type: string |
| 26 | + |
| 27 | +env: |
| 28 | + NODE_VERSION: '20' |
| 29 | + |
| 30 | +jobs: |
| 31 | + test-with-preview-dependency: |
| 32 | + name: Test supabase-js with preview dependency |
| 33 | + runs-on: ubuntu-latest |
| 34 | + timeout-minutes: 30 # Overall job timeout |
| 35 | + steps: |
| 36 | + - name: Generate GitHub App token |
| 37 | + id: generate-token |
| 38 | + uses: actions/create-github-app-token@v1 |
| 39 | + with: |
| 40 | + app-id: ${{ vars.CROSS_REPO_APP_ID }} |
| 41 | + private-key: ${{ secrets.CROSS_REPO_APP_PRIVATE_KEY }} |
| 42 | + owner: supabase |
| 43 | + repositories: ${{ inputs.triggering_repo }} |
| 44 | + |
| 45 | + - name: Post initial comment |
| 46 | + uses: actions/github-script@v7 |
| 47 | + with: |
| 48 | + github-token: ${{ steps.generate-token.outputs.token }} |
| 49 | + script: | |
| 50 | + // Unique identifier for this bot's comments |
| 51 | + const commentIdentifier = '<!-- supabase-js-test-results -->'; |
| 52 | +
|
| 53 | + const body = `${commentIdentifier} |
| 54 | + ## 🔄 supabase-js CI Tests Running... |
| 55 | +
|
| 56 | + **Status:** Tests in progress |
| 57 | +
|
| 58 | + Tests triggered by preview release of \`${{ inputs.package_name }}\` |
| 59 | +
|
| 60 | + | Test Suite | Status | |
| 61 | + |------------|--------| |
| 62 | + | Type Check | ⏳ Running... | |
| 63 | + | Unit Tests | ⏳ Pending... | |
| 64 | + | Integration Tests | ⏳ Pending... | |
| 65 | +
|
| 66 | + **Preview Package:** \`${{ inputs.preview_url }}\` |
| 67 | + **Commit:** [\`${{ inputs.triggering_sha }}\`](https://github.com/supabase/${{ inputs.triggering_repo }}/commit/${{ inputs.triggering_sha }}) |
| 68 | +
|
| 69 | + [View workflow run](https://github.com/supabase/supabase-js/actions/runs/${{ github.run_id }}) |
| 70 | +
|
| 71 | + _This comment will update when tests complete._`; |
| 72 | +
|
| 73 | + try { |
| 74 | + // First, try to find an existing comment from this bot |
| 75 | + const { data: comments } = await github.rest.issues.listComments({ |
| 76 | + owner: 'supabase', |
| 77 | + repo: '${{ inputs.triggering_repo }}', |
| 78 | + issue_number: parseInt('${{ inputs.triggering_pr }}') |
| 79 | + }); |
| 80 | + |
| 81 | + // Look for a comment with our identifier |
| 82 | + const botComment = comments.find(comment => |
| 83 | + comment.body && comment.body.includes(commentIdentifier) |
| 84 | + ); |
| 85 | + |
| 86 | + if (botComment) { |
| 87 | + // Update existing comment |
| 88 | + await github.rest.issues.updateComment({ |
| 89 | + owner: 'supabase', |
| 90 | + repo: '${{ inputs.triggering_repo }}', |
| 91 | + comment_id: botComment.id, |
| 92 | + body: body |
| 93 | + }); |
| 94 | + console.log('Successfully updated existing comment with running status'); |
| 95 | + } else { |
| 96 | + // Create new comment if none exists |
| 97 | + await github.rest.issues.createComment({ |
| 98 | + owner: 'supabase', |
| 99 | + repo: '${{ inputs.triggering_repo }}', |
| 100 | + issue_number: parseInt('${{ inputs.triggering_pr }}'), |
| 101 | + body: body |
| 102 | + }); |
| 103 | + console.log('Successfully posted new comment with running status'); |
| 104 | + } |
| 105 | + } catch (error) { |
| 106 | + console.log('Failed to post/update initial comment:', error.message); |
| 107 | + } |
| 108 | +
|
| 109 | + - name: Checkout supabase-js |
| 110 | + uses: actions/checkout@v4 |
| 111 | + |
| 112 | + - name: Setup Node.js |
| 113 | + uses: actions/setup-node@v4 |
| 114 | + with: |
| 115 | + node-version: ${{ env.NODE_VERSION }} |
| 116 | + cache: 'npm' |
| 117 | + |
| 118 | + - name: Install dependencies and build supabase-js |
| 119 | + run: | |
| 120 | + npm ci |
| 121 | + npm run build |
| 122 | + - name: Install preview dependency |
| 123 | + run: | |
| 124 | + # Install the preview package |
| 125 | + PREVIEW_PACKAGE="${{ inputs.preview_url }}" |
| 126 | + echo "Installing preview package: $PREVIEW_PACKAGE" |
| 127 | + npm install "$PREVIEW_PACKAGE" --no-save |
| 128 | + - name: Run Type Check |
| 129 | + id: type-check |
| 130 | + continue-on-error: true |
| 131 | + timeout-minutes: 5 |
| 132 | + run: | |
| 133 | + if npm run test:types; then |
| 134 | + echo "result=success" >> $GITHUB_OUTPUT |
| 135 | + else |
| 136 | + echo "result=failure" >> $GITHUB_OUTPUT |
| 137 | + fi |
| 138 | + - name: Setup Supabase CLI |
| 139 | + uses: supabase/setup-cli@v1 |
| 140 | + with: |
| 141 | + version: latest |
| 142 | + |
| 143 | + - name: Start Supabase |
| 144 | + timeout-minutes: 10 |
| 145 | + run: supabase start |
| 146 | + |
| 147 | + - name: Install jq for JSON parsing |
| 148 | + run: sudo apt-get update && sudo apt-get install -y jq |
| 149 | + |
| 150 | + - name: Run Unit Tests |
| 151 | + id: unit-tests |
| 152 | + continue-on-error: true |
| 153 | + timeout-minutes: 10 |
| 154 | + run: | |
| 155 | + if npm run test:coverage; then |
| 156 | + echo "result=success" >> $GITHUB_OUTPUT |
| 157 | + else |
| 158 | + echo "result=failure" >> $GITHUB_OUTPUT |
| 159 | + fi |
| 160 | + - name: Run Integration Tests |
| 161 | + id: integration-tests |
| 162 | + continue-on-error: true |
| 163 | + timeout-minutes: 10 |
| 164 | + run: | |
| 165 | + export SUPABASE_SERVICE_ROLE_KEY="$(supabase status --output json | jq -r '.SERVICE_ROLE_KEY')" |
| 166 | + if npm run test:integration; then |
| 167 | + echo "result=success" >> $GITHUB_OUTPUT |
| 168 | + else |
| 169 | + echo "result=failure" >> $GITHUB_OUTPUT |
| 170 | + fi |
| 171 | + - name: Stop Supabase |
| 172 | + if: always() |
| 173 | + run: supabase stop |
| 174 | + |
| 175 | + - name: Report results to triggering PR |
| 176 | + if: always() |
| 177 | + uses: actions/github-script@v7 |
| 178 | + with: |
| 179 | + github-token: ${{ steps.generate-token.outputs.token }} |
| 180 | + script: | |
| 181 | + const typeCheckResult = '${{ steps.type-check.outputs.result }}' || 'failure'; |
| 182 | + const unitTestResult = '${{ steps.unit-tests.outputs.result }}' || 'failure'; |
| 183 | + const integrationTestResult = '${{ steps.integration-tests.outputs.result }}' || 'failure'; |
| 184 | + const allPassed = typeCheckResult === 'success' && |
| 185 | + unitTestResult === 'success' && |
| 186 | + integrationTestResult === 'success'; |
| 187 | + const statusIcon = allPassed ? '✅' : '❌'; |
| 188 | + const overallStatus = allPassed ? 'PASSED' : 'FAILED'; |
| 189 | +
|
| 190 | + // Unique identifier for this bot's comments (using HTML comment for cleaner look) |
| 191 | + const commentIdentifier = '<!-- supabase-js-test-results -->'; |
| 192 | +
|
| 193 | + const body = `${commentIdentifier} |
| 194 | + ## ${statusIcon} supabase-js CI Test Results |
| 195 | + **Overall Status: ${overallStatus}** |
| 196 | + Tests triggered by preview release of \`${{ inputs.package_name }}\` |
| 197 | + | Test Suite | Result | |
| 198 | + |------------|--------| |
| 199 | + | Type Check | ${typeCheckResult === 'success' ? '✅ PASSED' : '❌ FAILED'} | |
| 200 | + | Unit Tests | ${unitTestResult === 'success' ? '✅ PASSED' : '❌ FAILED'} | |
| 201 | + | Integration Tests | ${integrationTestResult === 'success' ? '✅ PASSED' : '❌ FAILED'} | |
| 202 | + **Preview Package:** \`${{ inputs.preview_url }}\` |
| 203 | + **Commit:** [\`${{ inputs.triggering_sha }}\`](https://github.com/supabase/${{ inputs.triggering_repo }}/commit/${{ inputs.triggering_sha }}) |
| 204 | + ${allPassed ? |
| 205 | + '🎉 All tests passed! This preview release is compatible with supabase-js.' : |
| 206 | + '⚠️ Some tests failed. Please review the failing tests before merging.'} |
| 207 | + <details> |
| 208 | + <summary>View workflow run</summary> |
| 209 | + <a href="https://github.com/supabase/supabase-js/actions/runs/${{ github.run_id }}">View full test results</a> |
| 210 | + </details>`; |
| 211 | + try { |
| 212 | + // First, try to find an existing comment from this bot |
| 213 | + const { data: comments } = await github.rest.issues.listComments({ |
| 214 | + owner: 'supabase', |
| 215 | + repo: '${{ inputs.triggering_repo }}', |
| 216 | + issue_number: parseInt('${{ inputs.triggering_pr }}') |
| 217 | + }); |
| 218 | + // Look for a comment with our identifier |
| 219 | + const botComment = comments.find(comment => |
| 220 | + comment.body && comment.body.includes(commentIdentifier) |
| 221 | + ); |
| 222 | + if (botComment) { |
| 223 | + // Update existing comment |
| 224 | + await github.rest.issues.updateComment({ |
| 225 | + owner: 'supabase', |
| 226 | + repo: '${{ inputs.triggering_repo }}', |
| 227 | + comment_id: botComment.id, |
| 228 | + body: body |
| 229 | + }); |
| 230 | + console.log('Successfully updated existing comment'); |
| 231 | + } else { |
| 232 | + // Create new comment if none exists |
| 233 | + await github.rest.issues.createComment({ |
| 234 | + owner: 'supabase', |
| 235 | + repo: '${{ inputs.triggering_repo }}', |
| 236 | + issue_number: parseInt('${{ inputs.triggering_pr }}'), |
| 237 | + body: body |
| 238 | + }); |
| 239 | + console.log('Successfully posted new comment to PR'); |
| 240 | + } |
| 241 | + } catch (error) { |
| 242 | + console.log('Failed to post/update comment:', error.message); |
| 243 | + // Still log the results for manual review |
| 244 | + console.log('Test Results Summary:', { |
| 245 | + typeCheck: typeCheckResult, |
| 246 | + unitTests: unitTestResult, |
| 247 | + integrationTests: integrationTestResult, |
| 248 | + overallStatus: overallStatus |
| 249 | + }); |
| 250 | + } |
0 commit comments