Repository navigation
ci: add scheduled upstream-sync workflow with policy-based conflict resolution - #14
sjoerd2025 wants to merge 1 commit into
Conversation
…esolution Daily scheduled (and manually dispatchable) sync of this fork with its upstream: clean merges push straight to the default branch; conflicts are resolved by KEEP_OURS/KEEP_THEIRS glob policy; anything unresolved lands as a PR with conflict markers. Generated-By: PostHog Desktop Task-Id: c432a00f-64b2-454e-8222-a8a49ea4efdc
|
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
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. |
Reviewer's GuideAdds a daily or manually triggered upstream-sync workflow that discovers the parent repository, merges its default branch, applies configurable path-based conflict policies, and either pushes the result directly or opens a PR for protected-branch or unresolved-conflict cases. Sequence diagram for scheduled upstream synchronizationsequenceDiagram
actor Trigger as Scheduler_or_User
participant Workflow
participant GitHubAPI
participant Upstream
participant Origin
Trigger->>Workflow: Start scheduled or manual workflow
Workflow->>GitHubAPI: gh api repository parent and default_branch
GitHubAPI-->>Workflow: Parent repository and upstream branch
Workflow->>Upstream: git fetch upstream branch
Workflow->>Workflow: git merge upstream branch
alt Already up to date
Workflow-->>Trigger: Exit without changes
else Clean merge
Workflow->>Origin: git push default branch
alt Direct push rejected
Workflow->>Origin: git push sync-upstream/pr branch
Workflow->>GitHubAPI: gh pr create
end
else Merge has conflicts
loop Each conflicted path
Workflow->>Workflow: Match KEEP_OURS or KEEP_THEIRS policy
alt Policy matches
Workflow->>Workflow: git checkout ours or theirs and git add
else No policy match
Workflow->>Workflow: git add with conflict markers
end
end
Workflow->>Workflow: git commit
alt Unresolved conflicts remain
Workflow->>Origin: git push sync-upstream/conflict branch
Workflow->>GitHubAPI: gh pr create with conflict details
else Policy resolved all conflicts
Workflow->>Origin: git push default branch
end
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
4 issues found across 1 file
Confidence score: 2/5
- In
.github/workflows/sync-upstream.yml, interpolating ref values into shell source can let a crafted ref execute commands on the runner. Pass the values through stepenvvariables and use quoted shell expansions. - A manual run on a non-default ref can push to that ref or target its PR there instead of using the default branch. Resolve and check out the fork’s default branch, or reject runs from other refs.
- The unquoted loop expansion makes the default
.github/**policy miss nested workflow files. Parse the policy strings into arrays before matching. - Unresolved conflicts can create a new timestamped branch and PR every day. Check for an existing open PR before creating another.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name=".github/workflows/sync-upstream.yml">
<violation number="1" location=".github/workflows/sync-upstream.yml:77">
P1: `ubranch` and `github.ref_name` are interpolated into shell source before Bash parses it, so a valid ref containing `$(...)` can execute on the runner. Pass ref values through step `env` variables and use quoted shell variables.</violation>
<violation number="2" location=".github/workflows/sync-upstream.yml:78">
P2: A manual dispatch on a non-default ref makes `BRANCH` that ref, so the sync pushes there or opens its PR against it instead of the default branch. Resolve and check out the fork's default branch, or reject runs on other refs.</violation>
<violation number="3" location=".github/workflows/sync-upstream.yml:128">
P2: The unquoted loop expansion turns matching policy globs into workspace paths before `[[ ... ]]` sees them, so the default `.github/**` policy misses nested workflow files. Parse both policy strings into arrays (or disable pathname expansion) before iterating.</violation>
<violation number="4" location=".github/workflows/sync-upstream.yml:147">
P2: Each daily run creates a new timestamped `sync-upstream/conflict-*` branch and a new PR for the same unresolved files, so unresolved conflicts produce a PR every day. Before creating the branch, check for an open PR from a stable branch name with `gh pr list --head` and reuse it, or use one stable branch name.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
| run: | | ||
| set -euo pipefail | ||
| PARENT="${{ steps.upstream.outputs.parent }}" | ||
| UBRANCH="${{ steps.upstream.outputs.ubranch }}" |
There was a problem hiding this comment.
P1: ubranch and github.ref_name are interpolated into shell source before Bash parses it, so a valid ref containing $(...) can execute on the runner. Pass ref values through step env variables and use quoted shell variables.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At .github/workflows/sync-upstream.yml, line 77:
<comment>`ubranch` and `github.ref_name` are interpolated into shell source before Bash parses it, so a valid ref containing `$(...)` can execute on the runner. Pass ref values through step `env` variables and use quoted shell variables.</comment>
<file context>
@@ -0,0 +1,162 @@
+ run: |
+ set -euo pipefail
+ PARENT="${{ steps.upstream.outputs.parent }}"
+ UBRANCH="${{ steps.upstream.outputs.ubranch }}"
+ BRANCH="${{ github.ref_name }}"
+ MSG="chore: sync with upstream $PARENT ($UBRANCH)"
</file context>
|
|
||
| if [ "${#unresolved[@]}" -gt 0 ]; then | ||
| printf 'Unresolvable conflicts (opened a PR): %s\n' "${unresolved[*]}" >> "$GITHUB_STEP_SUMMARY" | ||
| cb="sync-upstream/conflict-$(date +%Y%m%d-%H%M%S)" |
There was a problem hiding this comment.
P2: Each daily run creates a new timestamped sync-upstream/conflict-* branch and a new PR for the same unresolved files, so unresolved conflicts produce a PR every day. Before creating the branch, check for an open PR from a stable branch name with gh pr list --head and reuse it, or use one stable branch name.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At .github/workflows/sync-upstream.yml, line 147:
<comment>Each daily run creates a new timestamped `sync-upstream/conflict-*` branch and a new PR for the same unresolved files, so unresolved conflicts produce a PR every day. Before creating the branch, check for an open PR from a stable branch name with `gh pr list --head` and reuse it, or use one stable branch name.</comment>
<file context>
@@ -0,0 +1,162 @@
+
+ if [ "${#unresolved[@]}" -gt 0 ]; then
+ printf 'Unresolvable conflicts (opened a PR): %s\n' "${unresolved[*]}" >> "$GITHUB_STEP_SUMMARY"
+ cb="sync-upstream/conflict-$(date +%Y%m%d-%H%M%S)"
+ git push origin "HEAD:refs/heads/$cb"
+ {
</file context>
| set -euo pipefail | ||
| PARENT="${{ steps.upstream.outputs.parent }}" | ||
| UBRANCH="${{ steps.upstream.outputs.ubranch }}" | ||
| BRANCH="${{ github.ref_name }}" |
There was a problem hiding this comment.
P2: A manual dispatch on a non-default ref makes BRANCH that ref, so the sync pushes there or opens its PR against it instead of the default branch. Resolve and check out the fork's default branch, or reject runs on other refs.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At .github/workflows/sync-upstream.yml, line 78:
<comment>A manual dispatch on a non-default ref makes `BRANCH` that ref, so the sync pushes there or opens its PR against it instead of the default branch. Resolve and check out the fork's default branch, or reject runs on other refs.</comment>
<file context>
@@ -0,0 +1,162 @@
+ set -euo pipefail
+ PARENT="${{ steps.upstream.outputs.parent }}"
+ UBRANCH="${{ steps.upstream.outputs.ubranch }}"
+ BRANCH="${{ github.ref_name }}"
+ MSG="chore: sync with upstream $PARENT ($UBRANCH)"
+
</file context>
| [[ "$f" == $pat ]] && resolved="ours" && break | ||
| done | ||
| if [ -z "$resolved" ]; then | ||
| for pat in $KEEP_THEIRS; do |
There was a problem hiding this comment.
P2: The unquoted loop expansion turns matching policy globs into workspace paths before [[ ... ]] sees them, so the default .github/** policy misses nested workflow files. Parse both policy strings into arrays (or disable pathname expansion) before iterating.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At .github/workflows/sync-upstream.yml, line 128:
<comment>The unquoted loop expansion turns matching policy globs into workspace paths before `[[ ... ]]` sees them, so the default `.github/**` policy misses nested workflow files. Parse both policy strings into arrays (or disable pathname expansion) before iterating.</comment>
<file context>
@@ -0,0 +1,162 @@
+ [[ "$f" == $pat ]] && resolved="ours" && break
+ done
+ if [ -z "$resolved" ]; then
+ for pat in $KEEP_THEIRS; do
+ # shellcheck disable=SC2053
+ [[ "$f" == $pat ]] && resolved="theirs" && break
</file context>
Why: keep this fork automatically in sync with its upstream, without a manual setup step — clean upstream merges land directly on the default branch, conflicts are auto-resolved by policy (docs/CI take upstream, fork customizations are preserved via
KEEP_OURS), and anything the policy can't resolve is opened as a PR containing the conflict markers.Schedule and policy are editable at the top of the file. Trigger manually anytime via Run workflow.
Created with PostHog Desktop
Summary by cubic
Adds a scheduled workflow that keeps this fork in sync with its upstream automatically.
Clean upstream merges push directly to the default branch. Conflicts are resolved by policy: docs and CI boilerplate take the upstream version, while fork customizations can be preserved via a
KEEP_OURSlist. Any conflict the policy can't resolve is pushed to async-upstream/conflict-*branch and opened as a PR containing the conflict markers.The sync runs daily and can be triggered manually anytime via Run workflow. The schedule and conflict policy are configurable via environment variables at the top of
.github/workflows/sync-upstream.yml.Written for commit e0dcd0b. Summary will update on new commits.
Summary by Sourcery
Automate daily upstream synchronization with configurable conflict handling and PR-based escalation for unresolved changes.
New Features:
Enhancements:
CI: