Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.

Commit 209f8eb

Browse files
committed
chore: secure-proof workflows
1 parent a918130 commit 209f8eb

File tree

4 files changed

+303
-167
lines changed

4 files changed

+303
-167
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Preview Build
2+
3+
permissions:
4+
contents: read
5+
pull-requests: read
6+
7+
on:
8+
pull_request:
9+
types: [opened, synchronize, labeled]
10+
paths:
11+
- 'src/**'
12+
- 'package.json'
13+
- 'package-lock.json'
14+
- 'tsconfig.json'
15+
16+
jobs:
17+
build-preview:
18+
# Only run if PR has the 'trigger: preview' label
19+
if: |
20+
contains(github.event.pull_request.labels.*.name, 'trigger: preview')
21+
runs-on: ubuntu-latest
22+
outputs:
23+
preview-url: ${{ steps.preview.outputs.url }}
24+
pr-number: ${{ github.event.pull_request.number }}
25+
steps:
26+
# Checkout fork code - safe because no secrets are available
27+
- name: Checkout code
28+
uses: actions/checkout@v4
29+
30+
# Log PR author for auditing
31+
- name: Log PR author
32+
run: |
33+
echo "Preview build triggered by: ${{ github.event.pull_request.user.login }}"
34+
echo "PR #${{ github.event.pull_request.number }} from fork: ${{ github.event.pull_request.head.repo.full_name }}"
35+
36+
- name: Setup Node.js
37+
uses: actions/setup-node@v4
38+
with:
39+
node-version: '20'
40+
cache: 'npm'
41+
42+
- name: Install dependencies
43+
run: npm ci
44+
45+
- name: Build
46+
run: npm run build
47+
48+
- name: Run tests
49+
run: npm test
50+
continue-on-error: true # Don't fail preview on test failures
51+
52+
- name: Create preview release
53+
id: preview
54+
run: |
55+
set -e
56+
echo "Creating preview release..."
57+
OUTPUT=$(npx pkg-pr-new@latest publish --compact 2>&1)
58+
echo "Full output:"
59+
echo "$OUTPUT"
60+
61+
# Extract the preview URL
62+
PREVIEW_URL=$(echo "$OUTPUT" | grep -o 'https://pkg\.pr\.new/@supabase/[^[:space:]]*' | head -1)
63+
64+
if [ -z "$PREVIEW_URL" ]; then
65+
echo "Error: Failed to extract preview URL from pkg-pr-new output"
66+
exit 1
67+
fi
68+
69+
echo "Preview Release URL: $PREVIEW_URL"
70+
echo "url=$PREVIEW_URL" >> $GITHUB_OUTPUT
71+
72+
# Save preview info for the next workflows
73+
- name: Save preview info
74+
run: |
75+
mkdir -p preview-info
76+
echo "${{ steps.preview.outputs.url }}" > preview-info/preview-url.txt
77+
echo "${{ github.event.pull_request.number }}" > preview-info/pr-number.txt
78+
echo "${{ github.event.pull_request.head.sha }}" > preview-info/commit-sha.txt
79+
echo "realtime-js" > preview-info/package-name.txt
80+
81+
- name: Upload preview info
82+
uses: actions/upload-artifact@v4
83+
with:
84+
name: preview-info
85+
path: preview-info/
86+
retention-days: 7
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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+
runs-on: ubuntu-latest
15+
steps:
16+
# Get PR number from the workflow run
17+
- name: Get PR info
18+
id: pr-info
19+
uses: actions/github-script@v7
20+
with:
21+
script: |
22+
// Get the workflow run details
23+
const workflowRun = context.payload.workflow_run;
24+
25+
// Find associated PR
26+
const prs = await github.rest.pulls.list({
27+
owner: context.repo.owner,
28+
repo: context.repo.repo,
29+
state: 'open',
30+
head: `${workflowRun.head_repository.owner.login}:${workflowRun.head_branch}`
31+
});
32+
33+
if (prs.data.length > 0) {
34+
const pr = prs.data[0];
35+
core.setOutput('pr-number', pr.number);
36+
core.setOutput('found', 'true');
37+
console.log(`Found PR #${pr.number}`);
38+
} else {
39+
core.setOutput('found', 'false');
40+
console.log('No associated PR found');
41+
}
42+
43+
# Only continue if we found a PR
44+
- name: Download preview info
45+
if: steps.pr-info.outputs.found == 'true' && github.event.workflow_run.name == 'Preview Build' && github.event.workflow_run.conclusion == 'success'
46+
uses: actions/download-artifact@v4
47+
with:
48+
name: preview-info
49+
path: preview-info/
50+
run-id: ${{ github.event.workflow_run.id }}
51+
continue-on-error: true
52+
53+
- name: Read preview URL
54+
if: steps.pr-info.outputs.found == 'true' && github.event.workflow_run.name == 'Preview Build' && github.event.workflow_run.conclusion == 'success'
55+
id: preview-url
56+
run: |
57+
if [ -f "preview-info/preview-url.txt" ]; then
58+
echo "url=$(cat preview-info/preview-url.txt)" >> $GITHUB_OUTPUT
59+
echo "found=true" >> $GITHUB_OUTPUT
60+
else
61+
echo "found=false" >> $GITHUB_OUTPUT
62+
fi
63+
continue-on-error: true
64+
65+
# Find existing comment
66+
- name: Find existing comment
67+
if: steps.pr-info.outputs.found == 'true'
68+
uses: peter-evans/find-comment@v3
69+
id: find-comment
70+
with:
71+
issue-number: ${{ steps.pr-info.outputs.pr-number }}
72+
comment-author: 'github-actions[bot]'
73+
body-includes: '<!-- functions-js-preview-status -->'
74+
75+
# Create or update comment based on workflow status
76+
- name: Create or update preview comment
77+
if: steps.pr-info.outputs.found == 'true'
78+
uses: peter-evans/create-or-update-comment@v4
79+
with:
80+
comment-id: ${{ steps.find-comment.outputs.comment-id }}
81+
issue-number: ${{ steps.pr-info.outputs.pr-number }}
82+
body: |
83+
<!-- functions-js-preview-status -->
84+
## 🚀 Preview Release Status
85+
86+
${{ github.event.workflow_run.name == 'Preview Build' && github.event.workflow_run.conclusion == 'success' && steps.preview-url.outputs.found == 'true' && format('✅ **Preview package created successfully!**
87+
88+
📦 **Preview URL:** `{0}`
89+
90+
You can install this preview package in your project by running:
91+
```bash
92+
npm install {0}
93+
```
94+
95+
🔄 Supabase-js CI tests have been automatically triggered to verify compatibility.
96+
', steps.preview-url.outputs.url) || '' }}
97+
98+
${{ github.event.workflow_run.name == 'Preview Build' && github.event.workflow_run.conclusion == 'failure' && '❌ **Preview build failed**
99+
100+
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.' || '' }}
101+
102+
${{ github.event.workflow_run.name == 'Trigger Supabase JS Tests' && github.event.workflow_run.conclusion == 'success' && '✅ **Supabase-js tests triggered successfully!**
103+
104+
The integration tests are now running. Results will be posted in the supabase-js repository when complete.' || '' }}
105+
106+
${{ github.event.workflow_run.name == 'Trigger Supabase JS Tests' && github.event.workflow_run.conclusion == 'failure' && '⚠️ **Failed to trigger supabase-js tests**
107+
108+
The preview package was created but the integration tests could not be triggered. You may need to trigger them manually.' || '' }}
109+
110+
---
111+
<sub>Last updated: ${{ github.event.workflow_run.updated_at }}</sub>
112+
edit-mode: replace

.github/workflows/preview-release.yml

Lines changed: 0 additions & 167 deletions
This file was deleted.

0 commit comments

Comments
 (0)