Repository navigation
ci(relay2): only deploy relay2 when relay2-relevant paths change - #6359
saddlepaddle wants to merge 1 commit into
Conversation
Every relay2 deploy restarts its Durable Objects and severs every live host tunnel. deploy-production runs on every push to main, so unrelated merges were bouncing the whole relay fleet several times an hour.
📝 WalkthroughWalkthroughThe production workflow now detects Relay2-related changes on push events. It runs Relay2 setup, dependency installation, caching, and deployment only when matching files change. Manual workflow dispatches continue to deploy unconditionally. ChangesRelay2 deployment gating
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🚀 Preview Deployment🔗 Preview Links
Preview updates automatically with new commits |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.github/workflows/deploy-production.yml:
- Around line 497-502: Add ".bun-version" to the relay2 path filters in the
deployment workflow so changes to the Bun version trigger the Relay2 deployment
steps. Preserve all existing relay2 paths and conditions.
- Around line 491-494: Declare least-privilege GITHUB_TOKEN permissions in the
workflow by setting contents: read at the workflow level, or specifically on the
deploy-relay2 job after verifying other jobs’ requirements; preserve all
existing job behavior.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 29d1e28b-62d6-41fc-8419-63017e10466c
📒 Files selected for processing (1)
.github/workflows/deploy-production.yml
| - name: Detect relay2-relevant changes | ||
| if: github.event_name == 'push' | ||
| id: changes | ||
| uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 |
There was a problem hiding this comment.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- workflow structure ---'
awk 'NR <= 80 || (NR >= 430 && NR <= 540) {printf "%5d %s\n", NR, $0}' .github/workflows/deploy-production.yml
printf '%s\n' '--- jobs, permissions, and relevant action references ---'
rg -n '^(name:|on:| [A-Za-z0-9_-]+:| permissions:| permissions:| permissions:|permissions:|.*dorny/paths-filter|.*actions/checkout|.*github\.token|.*GITHUB_TOKEN|.*paths-filter|.*outputs|.*environment:)' .github/workflows/deploy-production.yml
printf '%s\n' '--- repository workflow files and permission declarations ---'
git ls-files '.github/workflows/*'
rg -n '(^permissions:|^[[:space:]]+permissions:|dorny/paths-filter|actions/checkout)' .github/workflowsRepository: superset-sh/superset
Length of output: 16201
🌐 Web query:
dorny paths-filter v3 GitHub Actions required permissions push workflow_dispatch contents read
💡 Result:
For the dorny/paths-filter action (including v3 and newer versions), the required permissions depend on how the workflow is triggered [1][2]. 1. Pull Request Events: When a workflow is triggered by pull_request or pull_request_target events, the action requires the pull-requests: read permission to fetch the list of modified files via the GitHub REST API [3][4][2]. If you are also using actions/checkout in the same job, you typically need contents: read as well [3][4]. 2. Other Events (e.g., push, workflow_dispatch): In cases where the job does not rely on the pull request API (i.e., it executes local git commands instead), explicit pull-requests: read permissions are generally not required [1]. However, if you include a permissions: block in your workflow, it overrides any default permissions [5]. If you manually define permissions, ensure you include the necessary scopes for all steps in the job, such as contents: read for actions/checkout [3][4][5]. Important Considerations: - Permission Overrides: Defining a permissions block at the job level will override inherited permissions [5]. If your workflow requires both actions/checkout and paths-filter, ensure your configuration includes both required scopes [3][4]: permissions: contents: read pull-requests: read - workflow_dispatch: When using workflow_dispatch, the action does not automatically have a "before" commit to compare against [6]. If you experience issues with change detection in manual triggers, verify your base input configuration; often, removing the explicit base configuration allows the action to correctly default to the repository's main branch [6].
Citations:
- 1: What permissions does the GitHub Action need? dorny/paths-filter#123
- 2: https://github.com/dorny/paths-filter/tree/v3
- 3: https://github.com/dorny/paths-filter/blob/master/README.md
- 4: https://github.com/dorny/paths-filter
- 5: remote: Repository not found dorny/paths-filter#243
- 6: Changes not detected on a manual trigger (workflow_dispatch) dorny/paths-filter#235
🌐 Web query:
GitHub Actions workflow syntax permissions unspecified default GITHUB_TOKEN repository organization enterprise settings job-level permissions contents read actions checkout
💡 Result:
In GitHub Actions, the GITHUB_TOKEN is a temporary, repository-scoped access token used for authentication [1][2]. Understanding its permission model is essential for adhering to the principle of least privilege [1][3][2]. Default Permissions The default permissions of the GITHUB_TOKEN are determined by settings configured at the repository, organization, or enterprise level [4][5]. Administrators can choose between two primary settings: - Restricted: Generally grants read-only access to contents and packages [6][4]. This is the recommended secure default [3][2]. - Permissive: Grants read and write access to a wider range of scopes [4]. If you do not explicitly define a permissions key in your workflow, the GITHUB_TOKEN inherits these repository-level default settings [4][7]. Workflow Syntax and Permission Scoping To enforce the principle of least privilege, you should use the permissions key in your workflow file to explicitly define only the necessary access [1][5][8]. - Top-level permissions: When placed at the top level of a workflow file, these settings apply to all jobs within that workflow [9][10]. - Job-level permissions: When placed within a specific job (e.g., jobs.<job_id>.permissions), these settings override the repository defaults and any top-level workflow permissions entirely for that specific job [5][9][10]. Important Behaviors - Overriding: If you define permissions at the job level, you must specify all required permissions for that job, as they do not merge with workflow-level permissions; they replace them completely [5][10]. - Explicit Definition: If you specify a permission for even one scope (e.g., contents: read), all other unspecified scopes are set to none [5][9][11]. - Forked Repositories: If a workflow is triggered by a pull request from a forked repository, permissions are automatically restricted to read-only for security reasons, unless explicitly configured otherwise by organization settings (e.g., "Send write tokens to workflows from pull requests") [4][5]. For common tasks like actions/checkout, the contents: read permission is typically required [7]. You should audit your workflows to ensure they use the minimum necessary permissions rather than relying on broad, potentially overly permissive defaults [1][3][2].
Citations:
- 1: https://docs.github.com/en/actions/tutorials/authenticate-with-github_token
- 2: https://github.blog/security/new-tool-to-secure-your-github-actions/
- 3: https://github.com/github/docs/blob/main/content/actions/reference/security/secure-use.md
- 4: https://docs.github.com/en/[email protected]/actions/reference/authentication-in-a-workflow
- 5: https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax
- 6: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-github-actions-settings-for-a-repository
- 7: https://adhdecode.com/articles/github-actions/github-actions-workflow-permissions/
- 8: https://docs.github.com/actions/reference/authentication-in-a-workflow
- 9: https://docs.github.com/actions/using-workflows/workflow-syntax-for-github-actions
- 10: https://adaptive-enforcement-lab.com/secure/github-actions-security/token-permissions/job-scoping/
- 11: https://docs.github.com/en/enterprise-cloud@latest/actions/reference/workflows-and-actions/workflow-syntax
🏁 Script executed:
#!/bin/bash
set -eu
python3 - <<'PY'
from pathlib import Path
import re
path = Path(".github/workflows/deploy-production.yml")
lines = path.read_text().splitlines()
jobs = []
current = None
for number, line in enumerate(lines, 1):
m = re.match(r"^ ([A-Za-z0-9_-]+):\s*$", line)
if m:
current = {"name": m.group(1), "line": number, "permissions": []}
jobs.append(current)
elif current and re.match(r"^ permissions:\s*$", line):
current["permissions"].append(number)
print("workflow-level permissions:",
any(re.match(r"^permissions:\s*$", line) for line in lines))
for job in jobs:
print(f"job={job['name']} line={job['line']} permissions={job['permissions']}")
start = next(i for i, line in enumerate(lines, 1)
if "id: changes" in line)
end = next(i for i in range(start, len(lines) + 1)
if i > start and re.match(r"^ - name:", lines[i - 1]))
print(f"paths-filter step lines={start}-{end - 1}")
print("paths-filter filters:")
for i in range(start, end):
if re.match(r'^\s+- "', lines[i - 1]):
print(f"{i}: {lines[i - 1].strip()}")
PYRepository: superset-sh/superset
Length of output: 804
Declare least-privilege token permissions.
If repository defaults grant write access, this workflow gives the deployment jobs broader GITHUB_TOKEN permissions than required. Set contents: read at the workflow level, or at least on deploy-relay2 after checking the other jobs.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.github/workflows/deploy-production.yml around lines 491 - 494, Declare
least-privilege GITHUB_TOKEN permissions in the workflow by setting contents:
read at the workflow level, or specifically on the deploy-relay2 job after
verifying other jobs’ requirements; preserve all existing job behavior.
Source: Linters/SAST tools
| relay2: | ||
| - "apps/relay2/**" | ||
| - "packages/shared/**" | ||
| - "packages/trpc/**" | ||
| - "bun.lock" | ||
| - ".github/workflows/deploy-production.yml" |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- workflow structure ---'
wc -l .github/workflows/deploy-production.yml
printf '%s\n' '--- relevant lines ---'
sed -n '450,535p' .github/workflows/deploy-production.yml
printf '%s\n' '--- workflow references ---'
rg -n -C 3 'on:|workflow_dispatch|push:|branches:|paths-filter|relay2|\.bun-version|Setup Bun|environment:|permissions:|outputs:' .github/workflows/deploy-production.ymlRepository: superset-sh/superset
Length of output: 10340
🏁 Script executed:
#!/bin/bash
set -eu
python3 - <<'PY'
from pathlib import Path
import re
p = Path(".github/workflows/deploy-production.yml")
text = p.read_text()
lines = text.splitlines()
# Extract the relay2 rule block and the relay2 job/step context without executing
# repository code or a workflow.
for i, line in enumerate(lines):
if re.match(r"\s+relay2:\s*$", line):
start = i
while start > 0 and not re.match(r"\s{8}filters:\s*$", lines[start - 1]):
start -= 1
end = i + 1
while end < len(lines) and (lines[end].startswith(" - ") or not lines[end].strip()):
end += 1
print("relay2_filter_lines:")
for n in range(start + 1, end + 1):
print(f"{n}: {lines[n-1]}")
if "Setup Bun" in line:
print("setup_bun_context:")
for n in range(max(1, i - 5), min(len(lines), i + 8) + 1):
print(f"{n}: {lines[n-1]}")
print("top_level_trigger_and_permissions:")
for n, line in enumerate(lines[:80], 1):
if line.strip() in {"on:", "permissions:"} or re.match(r"\s+(push|workflow_dispatch|branches|paths):", line):
print(f"{n}: {line}")
PYRepository: superset-sh/superset
Length of output: 32126
🏁 Script executed:
#!/bin/bash
set -eu
python3 - <<'PY'
from pathlib import Path
import fnmatch
import re
workflow = Path(".github/workflows/deploy-production.yml").read_text().splitlines()
bun = Path(".bun-version")
print(f".bun-version_exists={bun.is_file()}")
print(f".bun-version_tracked={'.bun-version' in set(__import__('subprocess').check_output(['git', 'ls-files', '--', '.bun-version'], text=True).splitlines())}")
print(f".bun-version_value={bun.read_text().strip() if bun.is_file() else '<missing>'}")
start = next(i for i, line in enumerate(workflow)
if line.strip() == "deploy-relay2:")
filter_start = next(i for i in range(start, len(workflow))
if workflow[i].strip() == "relay2:")
patterns = []
for line in workflow[filter_start + 1:]:
m = re.match(r'\s+-\s+"([^"]+)"\s*$', line)
if not m:
break
patterns.append(m.group(1))
changed_paths = [".bun-version"]
matches = {
path: [pattern for pattern in patterns if fnmatch.fnmatchcase(path, pattern)]
for path in changed_paths
}
print(f"relay2_patterns={patterns}")
print(f"changed_paths={changed_paths}")
print(f"relay2_matches={matches}")
print(f"relay2_output_for_only_bun_version={'true' if any(matches.values()) else 'false'}")
print("relay2_deploy_condition_on_push=github.event_name == 'push' && steps.changes.outputs.relay2 == 'true'")
PYRepository: superset-sh/superset
Length of output: 577
Include .bun-version in the Relay2 filter. A push that changes only .bun-version matches none of the current relay2 rules. The conditional Relay2 steps skip, so the deployment does not use the new Bun version.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.github/workflows/deploy-production.yml around lines 497 - 502, Add
".bun-version" to the relay2 path filters in the deployment workflow so changes
to the Bun version trigger the Relay2 deployment steps. Preserve all existing
relay2 paths and conditions.
There was a problem hiding this comment.
No issues found across 1 file
You’re at about 91% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact [email protected].
Architecture diagram
sequenceDiagram
participant GH as GitHub Actions
participant WF as deploy-production.yml
participant PF as dorny/paths-filter
participant Bun as Bun Setup & Build
participant CF as Cloudflare Workers
participant DO as Relay2 Durable Objects
Note over GH,DO: CI/CD Deployment Pipeline - Current State
GH->>WF: Trigger workflow (push or workflow_dispatch)
WF->>WF: Job: deploy-relay2
alt workflow_dispatch (manual)
WF->>Bun: Skip path filter (always deploy)
Bun->>Bun: Setup Bun runtime
Bun->>Bun: Cache dependencies
Bun->>Bun: Install dependencies (bun install)
Bun->>CF: Deploy Worker (wranger deploy)
CF->>DO: NEW: Restart Durable Objects
DO-->>CF: Host tunnels reconnect (~2s)
else push to main
WF->>PF: Detect relay2-relevant changes
PF->>PF: Check paths: apps/relay2/**, packages/shared/**, packages/trpc/**, bun.lock, workflow file
alt relay2-relevant changes detected
PF-->>WF: relay2 = true
WF->>Bun: Setup Bun runtime
Bun->>Bun: Cache dependencies
Bun->>Bun: Install dependencies (bun install)
Bun->>CF: Deploy Worker (wranger deploy)
CF->>DO: Restart Durable Objects
DO-->>CF: Host tunnels reconnect (~2s)
else no relay2 changes
PF-->>WF: relay2 = false
WF->>WF: Skip deploy (no restart)
Note over WF,DO: Stateless workers (electric-proxy) deploy<br/>unaffected - harmless redeploy
end
end
Note over CF,DO: IMPORTANT: Every deployment causes<br/>Durable Object restart, severing<br/>live host tunnels (in-flight streams drop)
|
Closing per discussion: deploy-time tunnel bounces are recoverable (liveness sweep + ~2s partysocket reconnect + app-layer terminal resume) and not noticeably disruptive in practice, and out-of-band relay deploys won't be part of the workflow going forward — so the gate isn't worth the CI complexity. Revisit if deploy churn ever becomes user-visible. |
Summary
Every relay2 deploy restarts its Durable Objects, which severs every live host tunnel (hosts reconnect in ~2s, but in-flight streams drop).
deploy-production.ymlruns on every push tomainwith no path gating, so today's six unrelated merges bounced the entire relay2 fleet six times in one hour.This gates the
deploy-relay2job withdorny/paths-filter(pinned v3.0.2): it now deploys only whenapps/relay2/**, its workspace deps (packages/shared/**,packages/trpc/**),bun.lock, or the workflow itself changed.workflow_dispatchalways deploys, preserving the manual escape hatch.The stateless Cloudflare workers (electric-proxy) are left as-is — redeploying them on every push is harmless.
Test plan
bun run lintcleanSummary by CodeRabbit
Summary by cubic
Gate relay2 deployments so the job only runs when relay2-related files change, preventing unnecessary Durable Object restarts and dropped host tunnels. Uses
dorny/[email protected]to watchapps/relay2/**,packages/shared/**,packages/trpc/**,bun.lock, and the workflow;workflow_dispatchstill triggers a deploy.Written for commit 9510012. Summary will update on new commits.