A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
ci: run web, help & desktop previews on fork PRs (#10596)
Abdullah Atta7a183013af83
diff --git a/.github/actions/verify-pr-meta/action.yml b/.github/actions/verify-pr-meta/action.ymlnew file mode 100644index 000000000..1dc97ae22--- /dev/null+++ b/.github/actions/verify-pr-meta/action.yml@@ -0,0 +1,38 @@+name: "Verify PR metadata"+description: "Loads the PR number from a preview build artifact and verifies it against the triggering workflow_run"++# The artifact is written by fork-controlled workflow code, so only a numeric+# PR number is taken from it, and the API must confirm that PR is the one whose+# branch triggered this run. The commit comes from the trusted event payload.++inputs:+ meta-file:+ description: "Path to the pr-meta.env file from the build artifact"+ required: true++outputs:+ pr-number:+ description: "Verified PR number"+ value: ${{ steps.meta.outputs.PR_NUMBER }}+ head-sha:+ description: "Head commit of the triggering run"+ value: ${{ steps.meta.outputs.HEAD_SHA }}++runs:+ using: "composite"+ steps:+ - name: Load & verify PR metadata+ id: meta+ shell: bash+ env:+ GH_TOKEN: ${{ github.token }}+ META_FILE: ${{ inputs.meta-file }}+ RUN_HEAD: ${{ github.event.workflow_run.head_repository.full_name }}:${{ github.event.workflow_run.head_branch }}+ RUN_HEAD_SHA: ${{ github.event.workflow_run.head_sha }}+ run: |+ set -euo pipefail+ PR_NUMBER="$(grep -m1 -E '^PR_NUMBER=[0-9]{1,10}$' "$META_FILE" | cut -d= -f2)"+ PR_HEAD="$(gh api "repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER" --jq '.head.repo.full_name + ":" + .head.ref')"+ [ "$PR_HEAD" = "$RUN_HEAD" ] || { echo "::error::PR #$PR_NUMBER does not belong to $RUN_HEAD"; exit 1; }+ echo "PR_NUMBER=$PR_NUMBER" >> "$GITHUB_OUTPUT"+ echo "HEAD_SHA=$RUN_HEAD_SHA" >> "$GITHUB_OUTPUT"diff --git a/.github/workflows/android.preview.publish.yml b/.github/workflows/android.preview.publish.ymlindex 6bd3d920b..9f155a59e 100644--- a/.github/workflows/android.preview.publish.yml+++ b/.github/workflows/android.preview.publish.yml@@ -12,11 +12,17 @@ on:jobs:publish:- if: github.event.workflow_run.conclusion == 'success'+ if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request'runs-on: ubuntu-latesttimeout-minutes: 20steps:+ - name: Checkout base repo (trusted)+ uses: actions/checkout@v5+ # No `ref` -> default branch. Only the shared actions are needed.+ with:+ sparse-checkout: .github/actions+- name: Download build artifactuses: actions/download-artifact@v4with:@@ -25,8 +31,11 @@ jobs:run-id: ${{ github.event.workflow_run.id }}github-token: ${{ secrets.GITHUB_TOKEN }}- - name: Load PR metadata- run: cat "$RUNNER_TEMP/artifact/pr-meta.env" >> "$GITHUB_ENV"+ - name: Load & verify PR metadata+ id: meta+ uses: ./.github/actions/verify-pr-meta+ with:+ meta-file: ${{ runner.temp }}/artifact/pr-meta.env- name: Publish to Firebaseid: firebase-output@@ -36,12 +45,14 @@ jobs:serviceCredentialsFileContent: ${{ secrets.QA_SERVICE_ACCOUNT }}groups: testersfile: ${{ runner.temp }}/artifact/app-preview.apk- releaseNotes: Preview for https://github.com/${{ github.repository }}/pull/${{ env.PR_NUMBER }}+ releaseNotes: Preview for https://github.com/${{ github.repository }}/pull/${{ steps.meta.outputs.pr-number }}- name: Post or update PR commentuses: actions/github-script@v7env:preview_url: ${{ steps.firebase-output.outputs.TESTING_URI }}+ PR_NUMBER: ${{ steps.meta.outputs.pr-number }}+ HEAD_SHA: ${{ steps.meta.outputs.head-sha }}with:script: |const marker = '<!-- android-preview-comment -->';diff --git a/.github/workflows/desktop.preview.yml b/.github/workflows/desktop.preview.build.ymlsimilarity index 75%rename from .github/workflows/desktop.preview.ymlrename to .github/workflows/desktop.preview.build.ymlindex ec193e137..f24f20914 100644--- a/.github/workflows/desktop.preview.yml+++ b/.github/workflows/desktop.preview.build.yml@@ -1,4 +1,10 @@-name: Preview @notesnook/desktop+name: Notesnook Desktop Preview Build++# UNTRUSTED stage for fork PRs. Runs on `pull_request`, so fork code gets a+# read-only GITHUB_TOKEN and NO repository secrets. The signed + notarized+# macOS build only runs for same-repo PRs; fork PRs get an ad-hoc signed dmg+# instead so fork code is never signed with our Developer ID. The PR comment is+# posted by desktop.preview.publish.yml in the trusted `workflow_run` context.on:pull_request:@@ -9,11 +15,15 @@ on:- "apps/web/**"- "packages/**"# re-run workflow if workflow file changes- - ".github/workflows/desktop.preview.yml"+ - ".github/workflows/desktop.preview.build.yml"+ - ".github/workflows/desktop.preview.publish.yml"++concurrency:+ group: desktop-preview-${{ github.event.pull_request.number }}+ cancel-in-progress: truejobs:build:- if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}name: Buildruns-on: ubuntu-22.04steps:@@ -48,8 +58,21 @@ jobs:name: buildpath: apps/web/build/**/*+ - name: Stage PR metadata+ run: |+ mkdir -p "$RUNNER_TEMP/pr-meta"+ echo "PR_NUMBER=${{ github.event.pull_request.number }}" > "$RUNNER_TEMP/pr-meta/pr-meta.env"++ - name: Upload PR metadata+ uses: actions/upload-artifact@v4+ with:+ name: desktop-preview-meta+ path: ${{ runner.temp }}/pr-meta+ retention-days: 1+build-macos:name: Build for macOS+ if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}needs: buildruns-on: macos-14outputs:@@ -119,6 +142,52 @@ jobs:name: macos-buildpath: apps/desktop/output/*.dmg+ # Fork PRs get no signing secrets: ad-hoc sign (required to launch on Apple+ # silicon) without hardened runtime, which ad-hoc signatures can't satisfy.+ build-macos-unsigned:+ name: Build for macOS (unsigned)+ if: ${{ github.event.pull_request.head.repo.full_name != github.repository }}+ needs: build+ runs-on: macos-14+ steps:+ - name: Check out Git repository+ uses: actions/checkout@v5++ - name: Setup Node+ uses: ./.github/actions/setup-node-with-cache++ - name: Install setuptools+ run: brew install python-setuptools++ - name: Download build+ uses: actions/download-artifact@v4+ with:+ name: build+ path: ./apps/web/build++ - name: Install packages+ run: |+ npm ci --ignore-scripts --prefer-offline --no-audit+ npm run bootstrap -- --scope=desktop++ - name: Install sqlite-better-trigram for all arch+ run: |+ npm i --cpu arm64 sqlite-better-trigram+ npm i --cpu x64 sqlite-better-trigram+ working-directory: ./apps/desktop++ - name: Build dmg+ run: |+ npm run tx @notesnook/desktop:release+ cd apps/desktop+ yarn electron-builder --config=electron-builder.config.js --mac dmg --arm64 -p never -c.mac.identity=- -c.mac.hardenedRuntime=false -c.mac.notarize=false++ - name: Upload dmg artifact+ uses: actions/upload-artifact@v4+ with:+ name: macos-build+ path: apps/desktop/output/*.dmg+build-linux-x64:name: Build for Linux x64needs: build@@ -255,49 +324,3 @@ jobs:with:name: windows-buildpath: apps/desktop/output/*.exe-- post-pr-comment:- name: Post PR comment with preview URLs- needs:- [build, build-macos, build-linux-x64, build-linux-arm64, build-windows]- runs-on: ubuntu-latest- steps:- - name: Post or update PR comment- uses: actions/github-script@v6- env:- macos_artifact_url: ${{ needs.build-macos.outputs.macos-artifact-url }}- linux_x64_artifact_url: ${{ needs.build-linux-x64.outputs.linux-x64-artifact-url }}- linux_arm64_artifact_url: ${{ needs.build-linux-arm64.outputs.linux-arm64-artifact-url }}- windows_artifact_url: ${{ needs.build-windows.outputs.windows-artifact-url }}- with:- script: |- const marker = '<!-- desktop-preview-comment -->';- const prNumber = context.issue.number;- const previewUrl = [- { platform: 'macOS', url: process.env.macos_artifact_url },- { platform: 'Linux x64', url: process.env.linux_x64_artifact_url },- { platform: 'Linux arm64', url: process.env.linux_arm64_artifact_url },- { platform: 'Windows x64', url: process.env.windows_artifact_url },- ].filter(u => u.url).map(u => `- [${u.platform}](${u.url})`).join('\n');- const body = `${marker}\n**Desktop Previews**\n\n${previewUrl || 'Preview URL unavailable — check workflow logs.'}\n\nCommit: ${process.env.GITHUB_SHA}\n`;- const { data: comments } = await github.rest.issues.listComments({- owner: context.repo.owner,- repo: context.repo.repo,- issue_number: prNumber,- });- const existing = comments.find(c => c.body && c.body.includes(marker));- if (existing) {- await github.rest.issues.updateComment({- owner: context.repo.owner,- repo: context.repo.repo,- comment_id: existing.id,- body,- });- } else {- await github.rest.issues.createComment({- owner: context.repo.owner,- repo: context.repo.repo,- issue_number: prNumber,- body,- });- }diff --git a/.github/workflows/desktop.preview.publish.yml b/.github/workflows/desktop.preview.publish.ymlnew file mode 100644index 000000000..7fef31791--- /dev/null+++ b/.github/workflows/desktop.preview.publish.yml@@ -0,0 +1,88 @@+name: Notesnook Desktop Preview Publish++# TRUSTED stage. Runs via `workflow_run` after the build workflow finishes, so+# it has a write-scoped token. It only looks up the build's artifacts through+# the API and posts the PR comment. It never checks out or executes fork code.++on:+ workflow_run:+ workflows: ["Notesnook Desktop Preview Build"]+ types: [completed]++jobs:+ post-pr-comment:+ name: Post PR comment with preview URLs+ if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request'+ runs-on: ubuntu-latest+ timeout-minutes: 10++ steps:+ - name: Checkout base repo (trusted)+ uses: actions/checkout@v5+ # No `ref` -> default branch. Only the shared actions are needed.+ with:+ sparse-checkout: .github/actions++ - name: Download PR metadata+ uses: actions/download-artifact@v4+ with:+ name: desktop-preview-meta+ path: ${{ runner.temp }}/artifact+ run-id: ${{ github.event.workflow_run.id }}+ github-token: ${{ secrets.GITHUB_TOKEN }}++ - name: Load & verify PR metadata+ id: meta+ uses: ./.github/actions/verify-pr-meta+ with:+ meta-file: ${{ runner.temp }}/artifact/pr-meta.env++ - name: Post or update PR comment+ uses: actions/github-script@v7+ env:+ PR_NUMBER: ${{ steps.meta.outputs.pr-number }}+ HEAD_SHA: ${{ steps.meta.outputs.head-sha }}+ RUN_ID: ${{ github.event.workflow_run.id }}+ with:+ script: |+ const marker = '<!-- desktop-preview-comment -->';+ const prNumber = Number(process.env.PR_NUMBER);+ if (!prNumber) return;+ const runId = Number(process.env.RUN_ID);+ const artifacts = await github.paginate(github.rest.actions.listWorkflowRunArtifacts, {+ owner: context.repo.owner,+ repo: context.repo.repo,+ run_id: runId,+ });+ const urlFor = (name) => {+ const artifact = artifacts.find(a => a.name === name);+ return artifact && `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}/artifacts/${artifact.id}`;+ };+ const previewUrl = [+ { platform: 'macOS', url: urlFor('macos-build') },+ { platform: 'Linux x64', url: urlFor('linux-x64-build') },+ { platform: 'Linux arm64', url: urlFor('linux-arm64-build') },+ { platform: 'Windows x64', url: urlFor('windows-build') },+ ].filter(u => u.url).map(u => `- [${u.platform}](${u.url})`).join('\n');+ const body = `${marker}\n**Desktop Previews**\n\n${previewUrl || 'Preview URL unavailable — check workflow logs.'}\n\nCommit: ${process.env.HEAD_SHA}\n`;+ const { data: comments } = await github.rest.issues.listComments({+ owner: context.repo.owner,+ repo: context.repo.repo,+ issue_number: prNumber,+ });+ const existing = comments.find(c => c.body && c.body.includes(marker));+ if (existing) {+ await github.rest.issues.updateComment({+ owner: context.repo.owner,+ repo: context.repo.repo,+ comment_id: existing.id,+ body,+ });+ } else {+ await github.rest.issues.createComment({+ owner: context.repo.owner,+ repo: context.repo.repo,+ issue_number: prNumber,+ body,+ });+ }diff --git a/.github/workflows/help.preview.build.yml b/.github/workflows/help.preview.build.ymlnew file mode 100644index 000000000..4d0f65157--- /dev/null+++ b/.github/workflows/help.preview.build.yml@@ -0,0 +1,57 @@+name: Notesnook Help Preview Build++# UNTRUSTED stage. Runs on `pull_request`, so fork code is checked out and+# compiled with a read-only GITHUB_TOKEN and NO repository secrets. Uploading to+# Cloudflare and the PR comment happen in help.preview.publish.yml, which runs+# in the trusted `workflow_run` context and never executes fork code. Because+# no secrets are exposed here, the build runs automatically for every PR+# (including forks) with no authorization gate.++on:+ pull_request:+ types: [opened, reopened, synchronize]+ branches: [master, beta]+ paths:+ - "docs/help/**"+ - ".github/workflows/help.preview.build.yml"+ - ".github/workflows/help.preview.publish.yml"++concurrency:+ group: help-preview-${{ github.event.pull_request.number }}+ cancel-in-progress: true++jobs:+ build:+ runs-on: ubuntu-latest+ steps:+ - name: Checkout+ uses: actions/checkout@v5+ with:+ fetch-depth: 0++ - name: Setup Node+ uses: ./.github/actions/setup-node-with-cache++ - name: Install dependencies+ run: |+ npm ci --ignore-scripts --prefer-offline --no-audit+ npm run bootstrap -- --scope=help++ - name: Build help+ run: npm run build:help++ - name: Stage build artifact+ run: |+ set -euo pipefail+ mkdir -p "$RUNNER_TEMP/artifact"+ cp -R docs/help/.vitepress/dist "$RUNNER_TEMP/artifact/dist"+ echo "PR_NUMBER=${{ github.event.pull_request.number }}" > "$RUNNER_TEMP/artifact/pr-meta.env"++ - name: Upload build artifact+ uses: actions/upload-artifact@v4+ with:+ name: help-preview-build+ path: ${{ runner.temp }}/artifact+ include-hidden-files: true+ if-no-files-found: error+ retention-days: 1diff --git a/.github/workflows/help.preview.yml b/.github/workflows/help.preview.publish.ymlsimilarity index 51%rename from .github/workflows/help.preview.ymlrename to .github/workflows/help.preview.publish.ymlindex c32d7591e..f1b5e326b 100644--- a/.github/workflows/help.preview.yml+++ b/.github/workflows/help.preview.publish.yml@@ -1,44 +1,56 @@-name: Notesnook Help PR Preview+name: Notesnook Help Preview Publish++# TRUSTED stage. Runs via `workflow_run` after the build workflow finishes, so+# it has the base repo's secrets and a write-scoped token. It downloads the+# static site the PR produced and uploads it as a preview version using the+# BASE repo's wrangler config, then posts the PR comment. It never executes+# fork code.on:- pull_request:- types: [opened, reopened, synchronize]- branches: [master, beta]- paths:- - "docs/help/**"- # re-run workflow if workflow file changes- - ".github/workflows/help.preview.yml"+ workflow_run:+ workflows: ["Notesnook Help Preview Build"]+ types: [completed]jobs:- build-and-deploy:- if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}+ deploy:+ if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request'runs-on: ubuntu-latest+ timeout-minutes: 20env:CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}+steps:- - name: Checkout+ - name: Checkout base repo (trusted)uses: actions/checkout@v5+ # No `ref` -> default branch. Only the wrangler config is needed.with:- fetch-depth: 0-- - name: Setup Node- uses: ./.github/actions/setup-node-with-cache+ sparse-checkout: |+ .github/actions+ docs/help- - name: Install dependencies- run: |- npm ci --ignore-scripts --prefer-offline --no-audit- npm run bootstrap -- --scope=help+ - name: Download build artifact+ uses: actions/download-artifact@v4+ with:+ name: help-preview-build+ path: ${{ runner.temp }}/artifact+ run-id: ${{ github.event.workflow_run.id }}+ github-token: ${{ secrets.GITHUB_TOKEN }}- - name: Build help- run: npm run build:help+ - name: Load & verify PR metadata+ id: meta+ uses: ./.github/actions/verify-pr-meta+ with:+ meta-file: ${{ runner.temp }}/artifact/pr-meta.env- name: Deploy to Cloudflare- id: deployworking-directory: ./docs/helprun: |set -euo pipefail- DEPLOY_OUT=$(npx --yes wrangler versions upload 2>&1) || { echo "$DEPLOY_OUT"; exit 1; }+ rm -rf ./.vitepress/dist+ mkdir -p ./.vitepress+ mv "$RUNNER_TEMP/artifact/dist" ./.vitepress/dist+ DEPLOY_OUT=$(npx --yes wrangler@4 versions upload 2>&1) || { echo "$DEPLOY_OUT"; exit 1; }echo "$DEPLOY_OUT"PREVIEW_URL=$(printf "%s" "$DEPLOY_OUT" | grep -Eo 'https?://[^ ]+' | head -1 || true)if [ -z "$PREVIEW_URL" ]; then@@ -47,15 +59,18 @@ jobs:echo "preview_url=$PREVIEW_URL" >> $GITHUB_ENV- name: Post or update PR comment- uses: actions/github-script@v6+ uses: actions/github-script@v7env:preview_url: ${{ env.preview_url }}+ PR_NUMBER: ${{ steps.meta.outputs.pr-number }}+ HEAD_SHA: ${{ steps.meta.outputs.head-sha }}with:script: |const marker = '<!-- docs-pages-preview-comment -->';- const prNumber = context.issue.number;+ const prNumber = Number(process.env.PR_NUMBER);+ if (!prNumber) return;const previewUrl = process.env.preview_url || '';- const body = `${marker}\n**Cloudflare Pages Docs Preview**\n\n${previewUrl || 'Preview URL unavailable — check workflow logs.'}\n\nCommit: ${process.env.GITHUB_SHA}\n`;+ const body = `${marker}\n**Cloudflare Pages Docs Preview**\n\n${previewUrl || 'Preview URL unavailable — check workflow logs.'}\n\nCommit: ${process.env.HEAD_SHA}\n`;const { data: comments } = await github.rest.issues.listComments({owner: context.repo.owner,repo: context.repo.repo,diff --git a/.github/workflows/ios.preview.publish.yml b/.github/workflows/ios.preview.publish.ymlindex a193e4909..4d32229b5 100644--- a/.github/workflows/ios.preview.publish.yml+++ b/.github/workflows/ios.preview.publish.yml@@ -18,12 +18,12 @@ on:jobs:export:# Only publish previews for builds that actually succeeded.- if: github.event.workflow_run.conclusion == 'success'+ if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request'runs-on: macos-26timeout-minutes: 30outputs:- pr_number: ${{ steps.meta.outputs.PR_NUMBER }}- head_sha: ${{ steps.meta.outputs.HEAD_SHA }}+ pr_number: ${{ steps.meta.outputs.pr-number }}+ head_sha: ${{ steps.meta.outputs.head-sha }}steps:- name: Checkout base repo (trusted)@@ -43,12 +43,14 @@ jobs:run-id: ${{ github.event.workflow_run.id }}github-token: ${{ secrets.GITHUB_TOKEN }}- - name: Load PR metadata & extract archive+ - name: Load & verify PR metadataid: meta- run: |- set -euo pipefail- cat "$RUNNER_TEMP/artifact/pr-meta.env" >> "$GITHUB_OUTPUT"- tar -xzf "$RUNNER_TEMP/artifact/Notesnook.xcarchive.tar.gz" -C "$RUNNER_TEMP"+ uses: ./.github/actions/verify-pr-meta+ with:+ meta-file: ${{ runner.temp }}/artifact/pr-meta.env++ - name: Extract archive+ run: tar -xzf "$RUNNER_TEMP/artifact/Notesnook.xcarchive.tar.gz" -C "$RUNNER_TEMP"- name: Import signing certificateuses: apple-actions/import-codesign-certs@v3diff --git a/.github/workflows/web.preview.build.yml b/.github/workflows/web.preview.build.ymlnew file mode 100644index 000000000..e4c8d075b--- /dev/null+++ b/.github/workflows/web.preview.build.yml@@ -0,0 +1,58 @@+name: Notesnook Web Preview Build++# UNTRUSTED stage. Runs on `pull_request`, so fork code is checked out and+# compiled with a read-only GITHUB_TOKEN and NO repository secrets. Deploying to+# Cloudflare Pages and the PR comment happen in web.preview.publish.yml, which+# runs in the trusted `workflow_run` context and never executes fork code.+# Because no secrets are exposed here, the build runs automatically for every+# PR (including forks) with no authorization gate.++on:+ pull_request:+ types: [opened, reopened, synchronize]+ branches: [master, beta]+ paths:+ - "apps/web/**"+ - "packages/**"+ - ".github/workflows/web.preview.build.yml"+ - ".github/workflows/web.preview.publish.yml"++concurrency:+ group: web-preview-${{ github.event.pull_request.number }}+ cancel-in-progress: true++jobs:+ build:+ runs-on: ubuntu-latest+ steps:+ - name: Checkout+ uses: actions/checkout@v5+ with:+ fetch-depth: 0++ - name: Setup Node+ uses: ./.github/actions/setup-node-with-cache++ - name: Install dependencies+ run: |+ npm ci --ignore-scripts --prefer-offline --no-audit+ npm run bootstrap -- --scope=web++ - name: Build web+ run: npm run build:web++ - name: Stage build artifact+ run: |+ set -euo pipefail+ mkdir -p "$RUNNER_TEMP/artifact"+ cp -R apps/web/build "$RUNNER_TEMP/artifact/build"+ echo "PR_NUMBER=${{ github.event.pull_request.number }}" > "$RUNNER_TEMP/artifact/pr-meta.env"++ - name: Upload build artifact+ uses: actions/upload-artifact@v4+ with:+ name: web-preview-build+ path: ${{ runner.temp }}/artifact+ include-hidden-files: true+ if-no-files-found: error+ retention-days: 1diff --git a/.github/workflows/web.preview.yml b/.github/workflows/web.preview.publish.ymlsimilarity index 50%rename from .github/workflows/web.preview.ymlrename to .github/workflows/web.preview.publish.ymlindex bc8c2a470..b3c6901c0 100644--- a/.github/workflows/web.preview.yml+++ b/.github/workflows/web.preview.publish.yml@@ -1,45 +1,60 @@-name: Notesnook Web PR Preview+name: Notesnook Web Preview Publish++# TRUSTED stage. Runs via `workflow_run` after the build workflow finishes, so+# it has the base repo's secrets and a write-scoped token. It downloads the+# static build the PR produced and deploys it to Cloudflare Pages alongside the+# BASE repo's Pages Functions, then posts the PR comment. It never executes+# fork code.on:- pull_request:- types: [opened, reopened, synchronize]- branches: [master, beta]- paths:- - "apps/web/**"- - "packages/**"- # re-run workflow if workflow file changes- - ".github/workflows/web.preview.yml"+ workflow_run:+ workflows: ["Notesnook Web Preview Build"]+ types: [completed]jobs:- build-and-deploy:- if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}+ deploy:+ if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request'runs-on: ubuntu-latest+ timeout-minutes: 20env:CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}+steps:- - name: Checkout+ - name: Checkout base repo (trusted)uses: actions/checkout@v5+ # No `ref` -> default branch. Only the Pages Functions are needed.with:- fetch-depth: 0+ sparse-checkout: |+ .github/actions+ apps/web/functions- - name: Setup Node- uses: ./.github/actions/setup-node-with-cache-- - name: Install dependencies- run: |- npm ci --ignore-scripts --prefer-offline --no-audit- npm run bootstrap -- --scope=web+ - name: Download build artifact+ uses: actions/download-artifact@v4+ with:+ name: web-preview-build+ path: ${{ runner.temp }}/artifact+ run-id: ${{ github.event.workflow_run.id }}+ github-token: ${{ secrets.GITHUB_TOKEN }}- - name: Build web- run: npm run build:web+ - name: Load & verify PR metadata+ id: meta+ uses: ./.github/actions/verify-pr-meta+ with:+ meta-file: ${{ runner.temp }}/artifact/pr-meta.env- name: Deploy to Cloudflare Pages- id: deployworking-directory: ./apps/web+ env:+ PR_NUMBER: ${{ steps.meta.outputs.pr-number }}+ HEAD_SHA: ${{ steps.meta.outputs.head-sha }}run: |set -euo pipefail- BRANCH=pr-${{ github.event.number }}-$(echo "${{ github.sha }}" | cut -c1-7)+ mv "$RUNNER_TEMP/artifact/build" ./build+ # An advanced-mode worker in the output would replace the trusted+ # functions/ with fork code running on our Cloudflare account.+ rm -rf ./build/_worker.js+ BRANCH="pr-$PR_NUMBER-$(echo "$HEAD_SHA" | cut -c1-7)"echo "Deploying branch: $BRANCH"DEPLOY_OUT=$(npx --yes wrangler pages deploy --project-name=notesnook-app --branch="$BRANCH" ./build 2>&1) || { echo "$DEPLOY_OUT"; exit 1; }echo "$DEPLOY_OUT"@@ -50,15 +65,18 @@ jobs:echo "preview_url=$PREVIEW_URL" >> $GITHUB_ENV- name: Post or update PR comment- uses: actions/github-script@v6+ uses: actions/github-script@v7env:preview_url: ${{ env.preview_url }}+ PR_NUMBER: ${{ steps.meta.outputs.pr-number }}+ HEAD_SHA: ${{ steps.meta.outputs.head-sha }}with:script: |const marker = '<!-- pages-preview-comment -->';- const prNumber = context.issue.number;+ const prNumber = Number(process.env.PR_NUMBER);+ if (!prNumber) return;const previewUrl = process.env.preview_url || '';- const body = `${marker}\n**Cloudflare Pages Preview**\n\n${previewUrl || 'Preview URL unavailable — check workflow logs.'}\n\nCommit: ${process.env.GITHUB_SHA}\n`;+ const body = `${marker}\n**Cloudflare Pages Preview**\n\n${previewUrl || 'Preview URL unavailable — check workflow logs.'}\n\nCommit: ${process.env.HEAD_SHA}\n`;const { data: comments } = await github.rest.issues.listComments({owner: context.repo.owner,repo: context.repo.repo,