|
| 1 | +name: Update Canary PR Comment |
| 2 | + |
| 3 | +permissions: |
| 4 | + pull-requests: write |
| 5 | + actions: read |
| 6 | + |
| 7 | +on: |
| 8 | + workflow_run: |
| 9 | + workflows: ['Canary Deploy'] |
| 10 | + types: [completed] |
| 11 | + |
| 12 | +jobs: |
| 13 | + update-comment: |
| 14 | + # Only run on the correct repository |
| 15 | + if: github.repository == 'supabase/postgres-meta' |
| 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 and the workflow succeeded |
| 47 | + - name: Download canary info |
| 48 | + if: ${{ steps.pr-info.outputs.found == 'true' && github.event.workflow_run.conclusion == 'success' }} |
| 49 | + uses: actions/download-artifact@v4 |
| 50 | + with: |
| 51 | + name: canary-info |
| 52 | + path: canary-info/ |
| 53 | + run-id: ${{ github.event.workflow_run.id }} |
| 54 | + continue-on-error: true |
| 55 | + |
| 56 | + - name: Read canary info |
| 57 | + if: ${{ steps.pr-info.outputs.found == 'true' && github.event.workflow_run.conclusion == 'success' }} |
| 58 | + id: canary-info |
| 59 | + run: | |
| 60 | + if [ -f "canary-info/canary-tags.txt" ]; then |
| 61 | + # Read the first tag (DockerHub) from the tags |
| 62 | + FIRST_TAG=$(head -n1 canary-info/canary-tags.txt) |
| 63 | + echo "tag=$FIRST_TAG" >> $GITHUB_OUTPUT |
| 64 | + echo "found=true" >> $GITHUB_OUTPUT |
| 65 | + echo "commit-sha=$(cat canary-info/commit-sha.txt)" >> $GITHUB_OUTPUT |
| 66 | + else |
| 67 | + echo "found=false" >> $GITHUB_OUTPUT |
| 68 | + fi |
| 69 | + continue-on-error: true |
| 70 | + |
| 71 | + # Find existing comment |
| 72 | + - name: Find existing comment |
| 73 | + if: ${{ steps.pr-info.outputs.found == 'true' }} |
| 74 | + uses: peter-evans/find-comment@v3 |
| 75 | + id: find-comment |
| 76 | + with: |
| 77 | + issue-number: ${{ steps.pr-info.outputs.pr_number }} |
| 78 | + comment-author: 'github-actions[bot]' |
| 79 | + body-includes: '<!-- postgres-meta-canary-status -->' |
| 80 | + |
| 81 | + # Create or update comment based on workflow status |
| 82 | + - name: Create or update canary comment |
| 83 | + if: ${{ steps.pr-info.outputs.found == 'true' }} |
| 84 | + uses: peter-evans/create-or-update-comment@v4 |
| 85 | + with: |
| 86 | + comment-id: ${{ steps.find-comment.outputs.comment-id }} |
| 87 | + issue-number: ${{ steps.pr-info.outputs.pr_number }} |
| 88 | + body: | |
| 89 | + <!-- postgres-meta-canary-status --> |
| 90 | + ## 🚀 Canary Deployment Status |
| 91 | +
|
| 92 | + ${{ github.event.workflow_run.conclusion == 'success' && steps.canary-info.outputs.found == 'true' && format('✅ **Canary image deployed successfully!** |
| 93 | +
|
| 94 | + 🐳 **Docker Image:** `{0}` |
| 95 | + 📝 **Commit:** `{1}` |
| 96 | +
|
| 97 | + You can test this canary deployment by pulling the image: |
| 98 | + ```bash |
| 99 | + docker pull {0} |
| 100 | + ``` |
| 101 | +
|
| 102 | + You can also set the version in a supabase local project by running: |
| 103 | + ```bash |
| 104 | + echo "{0}" > supabase/.temp/pgmeta-version |
| 105 | + ``` |
| 106 | +
|
| 107 | + Or use it in your docker-compose.yml: |
| 108 | + ```yaml |
| 109 | + services: |
| 110 | + postgres-meta: |
| 111 | + image: {0} |
| 112 | + # ... other configuration |
| 113 | + ``` |
| 114 | +
|
| 115 | + The canary image is available on: |
| 116 | + - 🐳 [Docker Hub](https://hub.docker.com/r/supabase/postgres-meta) |
| 117 | + - 📦 [GitHub Container Registry](https://ghcr.io/supabase/postgres-meta) |
| 118 | + - ☁️ [AWS ECR Public](https://gallery.ecr.aws/supabase/postgres-meta) |
| 119 | + ', steps.canary-info.outputs.tag, steps.canary-info.outputs.commit-sha) || '' }} |
| 120 | +
|
| 121 | + ${{ github.event.workflow_run.conclusion == 'failure' && '❌ **Canary deployment failed** |
| 122 | +
|
| 123 | + Please check the [workflow logs](' }}${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.html_url || '' }}${{ github.event.workflow_run.conclusion == 'failure' && ') for more details. |
| 124 | +
|
| 125 | + Make sure your PR has the `deploy-canary` label and targets the `master` branch.' || '' }} |
| 126 | +
|
| 127 | + --- |
| 128 | + <sub>Last updated: ${{ github.event.workflow_run.updated_at }}</sub> |
| 129 | + edit-mode: replace |
0 commit comments