Skip to content

Commit 1d9e19a

Browse files
authored
Merge branch 'main' into main
2 parents 45bcc64 + 3ad4a60 commit 1d9e19a

File tree

12 files changed

+898
-216
lines changed

12 files changed

+898
-216
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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, is on the correct repository, and targets main branch
19+
if: |
20+
github.repository == 'supabase/functions-js' &&
21+
github.event.pull_request.base.ref == 'main' &&
22+
contains(github.event.pull_request.labels.*.name, 'trigger: preview')
23+
runs-on: ubuntu-latest
24+
timeout-minutes: 15
25+
outputs:
26+
preview-url: ${{ steps.preview.outputs.url }}
27+
pr-number: ${{ github.event.pull_request.number }}
28+
steps:
29+
# Checkout fork code - safe because no secrets are available
30+
- name: Checkout code
31+
uses: actions/checkout@v4
32+
33+
# Log PR author for auditing
34+
- name: Log PR author
35+
run: |
36+
echo "Preview build triggered by: ${{ github.event.pull_request.user.login }}"
37+
echo "PR #${{ github.event.pull_request.number }} from fork: ${{ github.event.pull_request.head.repo.full_name }}"
38+
39+
- name: Setup Node.js
40+
uses: actions/setup-node@v4
41+
with:
42+
node-version: '20'
43+
cache: 'npm'
44+
45+
- name: Install dependencies
46+
run: npm ci
47+
48+
- name: Build
49+
run: npm run build
50+
- name: Create preview release
51+
id: preview
52+
run: |
53+
echo "Creating preview release..."
54+
OUTPUT=$(npx pkg-pr-new@latest publish --compact 2>&1 || true)
55+
echo "Full output:"
56+
echo "$OUTPUT"
57+
58+
# Extract the preview URL
59+
PREVIEW_URL=$(echo "$OUTPUT" | grep -o 'https://pkg\.pr\.new/@supabase/[^[:space:]]*' | head -1)
60+
61+
if [ -z "$PREVIEW_URL" ]; then
62+
echo "Error: Failed to extract preview URL from pkg-pr-new output"
63+
echo "Output was: $OUTPUT"
64+
exit 1
65+
fi
66+
67+
echo "Preview Release URL: $PREVIEW_URL"
68+
echo "url=$PREVIEW_URL" >> $GITHUB_OUTPUT
69+
70+
# Save preview info for the next workflows
71+
- name: Save preview info
72+
run: |
73+
mkdir -p preview-info
74+
echo "${{ steps.preview.outputs.url }}" > preview-info/preview-url.txt
75+
echo "${{ github.event.pull_request.number }}" > preview-info/pr-number.txt
76+
echo "${{ github.event.pull_request.head.sha }}" > preview-info/commit-sha.txt
77+
echo "functions-js" > preview-info/package-name.txt
78+
79+
- name: Upload preview info
80+
uses: actions/upload-artifact@v4
81+
with:
82+
name: preview-info
83+
path: preview-info/
84+
retention-days: 7
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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/functions-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: '<!-- functions-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+
<!-- functions-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
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
name: Trigger Supabase JS Tests
2+
3+
permissions:
4+
contents: read
5+
actions: read
6+
7+
on:
8+
workflow_run:
9+
workflows: ["Preview Build"]
10+
types: [completed]
11+
12+
workflow_dispatch:
13+
inputs:
14+
preview_url:
15+
description: 'Preview package URL to test'
16+
required: true
17+
type: string
18+
target_branch:
19+
description: 'Target branch for supabase-js tests'
20+
type: string
21+
default: 'master'
22+
23+
jobs:
24+
trigger-tests:
25+
# Only run if the preview build succeeded and on the correct repository
26+
if: |
27+
github.repository == 'supabase/functions-js' &&
28+
(github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success')
29+
runs-on: ubuntu-latest
30+
timeout-minutes: 10
31+
steps:
32+
# For workflow_run trigger, download the preview info
33+
- name: Download preview info
34+
if: github.event_name != 'workflow_dispatch'
35+
uses: actions/download-artifact@v4
36+
with:
37+
name: preview-info
38+
path: preview-info/
39+
run-id: ${{ github.event.workflow_run.id }}
40+
41+
- name: Read preview info
42+
id: info
43+
run: |
44+
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
45+
# Use inputs from workflow_dispatch
46+
echo "url=${{ github.event.inputs.preview_url }}" >> $GITHUB_OUTPUT
47+
echo "pr=manual" >> $GITHUB_OUTPUT
48+
echo "sha=manual" >> $GITHUB_OUTPUT
49+
echo "package=functions-js" >> $GITHUB_OUTPUT
50+
else
51+
# Read from downloaded artifacts
52+
echo "url=$(cat preview-info/preview-url.txt)" >> $GITHUB_OUTPUT
53+
echo "pr=$(cat preview-info/pr-number.txt)" >> $GITHUB_OUTPUT
54+
echo "sha=$(cat preview-info/commit-sha.txt)" >> $GITHUB_OUTPUT
55+
echo "package=$(cat preview-info/package-name.txt)" >> $GITHUB_OUTPUT
56+
fi
57+
58+
- name: Show preview info
59+
run: |
60+
echo "Preview URL: ${{ steps.info.outputs.url }}"
61+
echo "PR Number: ${{ steps.info.outputs.pr }}"
62+
echo "Commit SHA: ${{ steps.info.outputs.sha }}"
63+
echo "Package: ${{ steps.info.outputs.package }}"
64+
65+
# Generate GitHub App token for cross-repo access
66+
- name: Generate GitHub App token
67+
id: generate-token
68+
uses: actions/create-github-app-token@v1
69+
with:
70+
app-id: ${{ vars.CROSS_REPO_APP_ID }}
71+
private-key: ${{ secrets.CROSS_REPO_APP_PRIVATE_KEY }}
72+
owner: supabase
73+
repositories: functions-js,supabase-js
74+
75+
- name: Trigger supabase-js CI tests
76+
uses: actions/github-script@v7
77+
with:
78+
github-token: ${{ steps.generate-token.outputs.token }}
79+
script: |
80+
const targetBranch = context.eventName === 'workflow_dispatch' && context.payload.inputs?.target_branch
81+
? context.payload.inputs.target_branch
82+
: 'master';
83+
84+
console.log('Triggering supabase-js tests...');
85+
console.log('Target branch:', targetBranch);
86+
console.log('Preview URL:', '${{ steps.info.outputs.url }}');
87+
88+
try {
89+
const response = await github.rest.actions.createWorkflowDispatch({
90+
owner: 'supabase',
91+
repo: 'supabase-js',
92+
workflow_id: 'external-test.yml',
93+
ref: targetBranch,
94+
inputs: {
95+
triggering_repo: '${{ steps.info.outputs.package }}',
96+
triggering_pr: '${{ steps.info.outputs.pr }}',
97+
preview_url: '${{ steps.info.outputs.url }}',
98+
package_name: '${{ steps.info.outputs.package }}',
99+
triggering_sha: '${{ steps.info.outputs.sha }}'
100+
}
101+
});
102+
103+
console.log('✅ Successfully triggered supabase-js tests');
104+
console.log('Response status:', response.status);
105+
} catch (error) {
106+
console.error('❌ Failed to trigger supabase-js tests:', error);
107+
throw error;
108+
}

packages/core/functions-js/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# `functions-js`
22

3-
[![Coverage Status](https://coveralls.io/repos/github/supabase/functions-js/badge.svg?branch=main)](https://coveralls.io/github/supabase/functions-js?branch=main)
3+
[![Coverage Status](https://coveralls.io/repos/github/supabase/functions-js/badge.svg?branch=main)](https://coveralls.io/github/supabase/functions-js?branch=main) [![pkg.pr.new](https://pkg.pr.new/badge/supabase/functions-js)](https://pkg.pr.new/~/supabase/functions-js)
4+
45

56
JS Client library to interact with Supabase Functions.
67

packages/core/functions-js/jest.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const config: Config.InitialOptions = {
1313
'src/**/*.{ts,tsx}',
1414
'!src/version.ts',
1515
'!src/index.ts',
16+
'!**/*.d.ts',
1617
],
1718
coverageProvider: 'v8',
1819
coverageThreshold: {

0 commit comments

Comments
 (0)