Update Canary PR Comment #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: Update Canary PR Comment | |
permissions: | |
pull-requests: write | |
actions: read | |
on: | |
workflow_run: | |
workflows: ['Canary Deploy'] | |
types: [completed] | |
jobs: | |
update-comment: | |
# Only run on the correct repository | |
if: github.repository == 'supabase/postgres-meta' | |
runs-on: ubuntu-latest | |
timeout-minutes: 5 | |
steps: | |
# Get PR number from the workflow run | |
- name: Get PR info | |
id: pr-info | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
// Get the workflow run details | |
const workflowRun = context.payload.workflow_run; | |
// Find associated PR | |
const prs = await github.rest.pulls.list({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
state: 'open', | |
head: `${workflowRun.head_repository.owner.login}:${workflowRun.head_branch}` | |
}); | |
if (prs.data.length > 0) { | |
const pr = prs.data[0]; | |
core.setOutput('pr_number', pr.number); | |
core.setOutput('found', 'true'); | |
console.log(`Found PR #${pr.number}`); | |
} else { | |
core.setOutput('found', 'false'); | |
console.log('No associated PR found'); | |
} | |
# Only continue if we found a PR and the workflow succeeded | |
- name: Download canary info | |
if: ${{ steps.pr-info.outputs.found == 'true' && github.event.workflow_run.conclusion == 'success' }} | |
uses: actions/download-artifact@v4 | |
with: | |
name: canary-info | |
path: canary-info/ | |
run-id: ${{ github.event.workflow_run.id }} | |
continue-on-error: true | |
- name: Read canary info | |
if: ${{ steps.pr-info.outputs.found == 'true' && github.event.workflow_run.conclusion == 'success' }} | |
id: canary-info | |
run: | | |
if [ -f "canary-info/canary-tags.txt" ]; then | |
# Read the first tag (DockerHub) from the tags | |
FIRST_TAG=$(head -n1 canary-info/canary-tags.txt) | |
echo "tag=$FIRST_TAG" >> $GITHUB_OUTPUT | |
echo "found=true" >> $GITHUB_OUTPUT | |
echo "commit-sha=$(cat canary-info/commit-sha.txt)" >> $GITHUB_OUTPUT | |
else | |
echo "found=false" >> $GITHUB_OUTPUT | |
fi | |
continue-on-error: true | |
# Find existing comment | |
- name: Find existing comment | |
if: ${{ steps.pr-info.outputs.found == 'true' }} | |
uses: peter-evans/find-comment@v3 | |
id: find-comment | |
with: | |
issue-number: ${{ steps.pr-info.outputs.pr_number }} | |
comment-author: 'github-actions[bot]' | |
body-includes: '<!-- postgres-meta-canary-status -->' | |
# Create or update comment based on workflow status | |
- name: Create or update canary comment | |
if: ${{ steps.pr-info.outputs.found == 'true' }} | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
comment-id: ${{ steps.find-comment.outputs.comment-id }} | |
issue-number: ${{ steps.pr-info.outputs.pr_number }} | |
body: | | |
<!-- postgres-meta-canary-status --> | |
## 🚀 Canary Deployment Status | |
${{ github.event.workflow_run.conclusion == 'success' && steps.canary-info.outputs.found == 'true' && format('✅ **Canary image deployed successfully!** | |
🐳 **Docker Image:** `{0}` | |
📝 **Commit:** `{1}` | |
You can test this canary deployment by pulling the image: | |
```bash | |
docker pull {0} | |
``` | |
You can also set the version in a supabase local project by running: | |
```bash | |
echo "{0}" > supabase/.temp/pgmeta-version | |
``` | |
Or use it in your docker-compose.yml: | |
```yaml | |
services: | |
postgres-meta: | |
image: {0} | |
# ... other configuration | |
``` | |
The canary image is available on: | |
- 🐳 [Docker Hub](https://hub.docker.com/r/supabase/postgres-meta) | |
- 📦 [GitHub Container Registry](https://ghcr.io/supabase/postgres-meta) | |
- ☁️ [AWS ECR Public](https://gallery.ecr.aws/supabase/postgres-meta) | |
', steps.canary-info.outputs.tag, steps.canary-info.outputs.commit-sha) || '' }} | |
${{ github.event.workflow_run.conclusion == 'failure' && '❌ **Canary deployment failed** | |
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. | |
Make sure your PR has the `deploy-canary` label and targets the `master` branch.' || '' }} | |
--- | |
<sub>Last updated: ${{ github.event.workflow_run.updated_at }}</sub> | |
edit-mode: replace |