|
| 1 | +name: Update PR Comment |
| 2 | + |
| 3 | +permissions: |
| 4 | + pull-requests: write |
| 5 | + actions: read |
| 6 | + |
| 7 | +on: |
| 8 | + workflow_run: |
| 9 | + workflows: ["Preview Build", "Trigger Supabase JS Tests"] |
| 10 | + types: [completed] |
| 11 | + |
| 12 | +jobs: |
| 13 | + update-comment: |
| 14 | + # Only run on the correct repository |
| 15 | + if: github.repository == 'supabase/auth-js' |
| 16 | + runs-on: ubuntu-latest |
| 17 | + timeout-minutes: 5 |
| 18 | + steps: |
| 19 | + # Get PR number from the workflow run |
| 20 | + - name: Get PR info |
| 21 | + id: pr-info |
| 22 | + uses: actions/github-script@v7 |
| 23 | + with: |
| 24 | + script: | |
| 25 | + // Get the workflow run details |
| 26 | + const workflowRun = context.payload.workflow_run; |
| 27 | + |
| 28 | + // Find associated PR |
| 29 | + const prs = await github.rest.pulls.list({ |
| 30 | + owner: context.repo.owner, |
| 31 | + repo: context.repo.repo, |
| 32 | + state: 'open', |
| 33 | + head: `${workflowRun.head_repository.owner.login}:${workflowRun.head_branch}` |
| 34 | + }); |
| 35 | + |
| 36 | + if (prs.data.length > 0) { |
| 37 | + const pr = prs.data[0]; |
| 38 | + core.setOutput('pr-number', pr.number); |
| 39 | + core.setOutput('found', 'true'); |
| 40 | + console.log(`Found PR #${pr.number}`); |
| 41 | + } else { |
| 42 | + core.setOutput('found', 'false'); |
| 43 | + console.log('No associated PR found'); |
| 44 | + } |
| 45 | + |
| 46 | + # Only continue if we found a PR |
| 47 | + - name: Download preview info |
| 48 | + if: steps.pr-info.outputs.found == 'true' && github.event.workflow_run.name == 'Preview Build' && github.event.workflow_run.conclusion == 'success' |
| 49 | + uses: actions/download-artifact@v4 |
| 50 | + with: |
| 51 | + name: preview-info |
| 52 | + path: preview-info/ |
| 53 | + run-id: ${{ github.event.workflow_run.id }} |
| 54 | + continue-on-error: true |
| 55 | + |
| 56 | + - name: Read preview URL |
| 57 | + if: steps.pr-info.outputs.found == 'true' && github.event.workflow_run.name == 'Preview Build' && github.event.workflow_run.conclusion == 'success' |
| 58 | + id: preview-url |
| 59 | + run: | |
| 60 | + if [ -f "preview-info/preview-url.txt" ]; then |
| 61 | + echo "url=$(cat preview-info/preview-url.txt)" >> $GITHUB_OUTPUT |
| 62 | + echo "found=true" >> $GITHUB_OUTPUT |
| 63 | + else |
| 64 | + echo "found=false" >> $GITHUB_OUTPUT |
| 65 | + fi |
| 66 | + continue-on-error: true |
| 67 | + |
| 68 | + # Find existing comment |
| 69 | + - name: Find existing comment |
| 70 | + if: steps.pr-info.outputs.found == 'true' |
| 71 | + uses: peter-evans/find-comment@v3 |
| 72 | + id: find-comment |
| 73 | + with: |
| 74 | + issue-number: ${{ steps.pr-info.outputs.pr-number }} |
| 75 | + comment-author: 'github-actions[bot]' |
| 76 | + body-includes: '<!-- auth-js-preview-status -->' |
| 77 | + |
| 78 | + # Create or update comment based on workflow status |
| 79 | + - name: Create or update preview comment |
| 80 | + if: steps.pr-info.outputs.found == 'true' |
| 81 | + uses: peter-evans/create-or-update-comment@v4 |
| 82 | + with: |
| 83 | + comment-id: ${{ steps.find-comment.outputs.comment-id }} |
| 84 | + issue-number: ${{ steps.pr-info.outputs.pr-number }} |
| 85 | + body: | |
| 86 | + <!-- auth-js-preview-status --> |
| 87 | + ## 🚀 Preview Release Status |
| 88 | + |
| 89 | + ${{ github.event.workflow_run.name == 'Preview Build' && github.event.workflow_run.conclusion == 'success' && steps.preview-url.outputs.found == 'true' && format('✅ **Preview package created successfully!** |
| 90 | + |
| 91 | + 📦 **Preview URL:** `{0}` |
| 92 | + |
| 93 | + You can install this preview package in your project by running: |
| 94 | + ```bash |
| 95 | + npm install {0} |
| 96 | + ``` |
| 97 | + |
| 98 | + 🔄 Supabase-js CI tests have been automatically triggered to verify compatibility. |
| 99 | + ', steps.preview-url.outputs.url) || '' }} |
| 100 | + |
| 101 | + ${{ github.event.workflow_run.name == 'Preview Build' && github.event.workflow_run.conclusion == 'failure' && '❌ **Preview build failed** |
| 102 | + |
| 103 | + Please check the [workflow logs](' }}${{ github.event.workflow_run.name == 'Preview Build' && github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.html_url || '' }}${{ github.event.workflow_run.name == 'Preview Build' && github.event.workflow_run.conclusion == 'failure' && ') for more details.' || '' }} |
| 104 | + |
| 105 | + ${{ github.event.workflow_run.name == 'Trigger Supabase JS Tests' && github.event.workflow_run.conclusion == 'success' && '✅ **Supabase-js tests triggered successfully!** |
| 106 | + |
| 107 | + The integration tests are now running. Results will be posted here when complete.' || '' }} |
| 108 | + |
| 109 | + ${{ github.event.workflow_run.name == 'Trigger Supabase JS Tests' && github.event.workflow_run.conclusion == 'failure' && '⚠️ **Failed to trigger supabase-js tests** |
| 110 | + |
| 111 | + The preview package was created but the integration tests could not be triggered. You may need to trigger them manually.' || '' }} |
| 112 | + |
| 113 | + --- |
| 114 | + <sub>Last updated: ${{ github.event.workflow_run.updated_at }}</sub> |
| 115 | + edit-mode: replace |
0 commit comments