|
17 | 17 | (github.event_name == 'push' ||
|
18 | 18 | (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'trigger: preview')))
|
19 | 19 | runs-on: ubuntu-latest
|
| 20 | + outputs: |
| 21 | + preview-url: ${{ steps.preview.outputs.url }} |
| 22 | + package-name: ${{ steps.preview.outputs.package }} |
20 | 23 | steps:
|
21 | 24 | - name: Checkout code
|
22 | 25 | uses: actions/checkout@v4
|
|
33 | 36 | - name: Build
|
34 | 37 | run: npm run build
|
35 | 38 |
|
36 |
| - - run: npx pkg-pr-new@latest publish --compact |
| 39 | + - name: Publish preview |
| 40 | + id: preview |
| 41 | + run: | |
| 42 | + OUTPUT=$(npx pkg-pr-new@latest publish --compact) |
| 43 | + echo "$OUTPUT" |
| 44 | + # Extract the preview URL from the output |
| 45 | + PREVIEW_URL=$(echo "$OUTPUT" | grep -oE 'npm i [^[:space:]]+' | head -1 | cut -d' ' -f3) |
| 46 | + PACKAGE_NAME=$(echo "$GITHUB_REPOSITORY" | cut -d'/' -f2) |
| 47 | + echo "url=$PREVIEW_URL" >> $GITHUB_OUTPUT |
| 48 | + echo "package=$PACKAGE_NAME" >> $GITHUB_OUTPUT |
| 49 | +
|
| 50 | + trigger-supabase-js-tests: |
| 51 | + needs: preview |
| 52 | + if: needs.preview.outputs.preview-url != '' |
| 53 | + runs-on: ubuntu-latest |
| 54 | + steps: |
| 55 | + - name: Trigger supabase-js CI tests |
| 56 | + uses: actions/github-script@v7 |
| 57 | + with: |
| 58 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 59 | + script: | |
| 60 | + const prNumber = context.issue.number || 'push'; |
| 61 | + const triggeringRepo = context.repo.repo; |
| 62 | +
|
| 63 | + try { |
| 64 | + const response = await github.rest.repos.createDispatchEvent({ |
| 65 | + owner: 'supabase', |
| 66 | + repo: 'supabase-js', |
| 67 | + event_type: 'test-with-preview', |
| 68 | + client_payload: { |
| 69 | + triggering_repo: triggeringRepo, |
| 70 | + triggering_pr: prNumber.toString(), |
| 71 | + preview_url: '${{ needs.preview.outputs.preview-url }}', |
| 72 | + package_name: '${{ needs.preview.outputs.package-name }}', |
| 73 | + triggering_sha: context.sha, |
| 74 | + triggering_ref: context.ref |
| 75 | + } |
| 76 | + }); |
| 77 | + |
| 78 | + console.log('Successfully triggered supabase-js tests'); |
| 79 | + console.log('Response:', response.status); |
| 80 | + |
| 81 | + // Add a comment to the PR indicating tests were triggered |
| 82 | + if (context.issue.number) { |
| 83 | + await github.rest.issues.createComment({ |
| 84 | + owner: context.repo.owner, |
| 85 | + repo: context.repo.repo, |
| 86 | + issue_number: context.issue.number, |
| 87 | + body: `🚀 **Preview release created!**\n\nsupabase-js CI tests have been automatically triggered to verify compatibility.\n\n**Preview package:** \`${{ needs.preview.outputs.preview-url }}\`\n\nResults will be posted here once testing is complete.` |
| 88 | + }); |
| 89 | + } |
| 90 | + } catch (error) { |
| 91 | + console.error('Failed to trigger supabase-js tests:', error); |
| 92 | + if (context.issue.number) { |
| 93 | + await github.rest.issues.createComment({ |
| 94 | + owner: context.repo.owner, |
| 95 | + repo: context.repo.repo, |
| 96 | + issue_number: context.issue.number, |
| 97 | + body: `⚠️ **Preview release created, but failed to trigger supabase-js tests**\n\n**Preview package:** \`${{ needs.preview.outputs.preview-url }}\`\n\nPlease manually verify compatibility or contact the team.` |
| 98 | + }); |
| 99 | + } |
| 100 | + throw error; |
| 101 | + } |
0 commit comments