Skip to content

AI-native design editor. Open-source Figma alternative.

Split preview deploy into pull_request_target workflow

Danila Poyarkov86d201b29e59
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index c21f4d083..27dd9f36d 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -44,55 +44,3 @@ jobs:
- name: Copy-paste detection
run: bun run test:dupes
-
- preview:
- runs-on: ubuntu-latest
- permissions:
- contents: read
- deployments: write
- pull-requests: write
- environment:
- name: preview
- url: ${{ steps.deploy.outputs.deployment-url }}
- steps:
- - uses: actions/checkout@v4
-
- - uses: oven-sh/setup-bun@v2
-
- - uses: actions/cache@v4
- with:
- path: ~/.bun/install/cache
- key: bun-${{ runner.os }}-${{ hashFiles('bun.lock') }}
- restore-keys: bun-${{ runner.os }}-
-
- - run: bun install --frozen-lockfile
-
- - run: bun run build
-
- - uses: cloudflare/wrangler-action@v3
- id: deploy
- with:
- apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
- accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
- command: pages deploy dist --project-name=openpencil-app --branch=${{ github.head_ref }}
-
- - name: Comment preview URL
- uses: actions/github-script@v7
- with:
- script: |
- const url = '${{ steps.deploy.outputs.deployment-url }}';
- const marker = '<!-- preview-deploy -->';
- const body = `${marker}\n🔗 Preview: ${url}`;
- const { data: comments } = await github.rest.issues.listComments({
- ...context.repo, issue_number: context.issue.number
- });
- const existing = comments.find(c => c.body.includes(marker));
- if (existing) {
- await github.rest.issues.updateComment({
- ...context.repo, comment_id: existing.id, body
- });
- } else {
- await github.rest.issues.createComment({
- ...context.repo, issue_number: context.issue.number, body
- });
- }
diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml
new file mode 100644
index 000000000..d09fb5894
--- /dev/null
+++ b/.github/workflows/preview.yml
@@ -0,0 +1,68 @@
+name: Preview
+
+on:
+ pull_request_target:
+ branches: [master]
+ paths-ignore:
+ - 'packages/docs/**'
+ - 'openspec/**'
+ - '*.md'
+
+concurrency:
+ group: preview-${{ github.event.pull_request.number }}
+ cancel-in-progress: true
+
+jobs:
+ preview:
+ runs-on: ubuntu-latest
+ permissions:
+ contents: read
+ deployments: write
+ pull-requests: write
+ environment:
+ name: preview
+ url: ${{ steps.deploy.outputs.deployment-url }}
+ steps:
+ - uses: actions/checkout@v4
+ with:
+ ref: ${{ github.event.pull_request.head.sha }}
+
+ - uses: oven-sh/setup-bun@v2
+
+ - uses: actions/cache@v4
+ with:
+ path: ~/.bun/install/cache
+ key: bun-${{ runner.os }}-${{ hashFiles('bun.lock') }}
+ restore-keys: bun-${{ runner.os }}-
+
+ - run: bun install --frozen-lockfile
+
+ - run: bun run build
+
+ - uses: cloudflare/wrangler-action@v3
+ id: deploy
+ with:
+ apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
+ accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
+ command: pages deploy dist --project-name=openpencil-app --branch=${{ github.event.pull_request.head.ref }}
+
+ - name: Comment preview URL
+ uses: actions/github-script@v7
+ with:
+ script: |
+ const url = '${{ steps.deploy.outputs.deployment-url }}';
+ const marker = '<!-- preview-deploy -->';
+ const body = `${marker}\n🔗 Preview: ${url}`;
+ const { data: comments } = await github.rest.issues.listComments({
+ ...context.repo, issue_number: context.issue.number
+ });
+ const existing = comments.find(c => c.body.includes(marker));
+ if (existing) {
+ await github.rest.issues.updateComment({
+ ...context.repo, comment_id: existing.id, body
+ });
+ } else {
+ await github.rest.issues.createComment({
+ ...context.repo, issue_number: context.issue.number, body
+ });
+ }