Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
196 changes: 196 additions & 0 deletions .github/workflows/sync-upstream.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
name: Sync upstream

on:
schedule:
# Every Monday at 09:00 UTC
- cron: "0 9 * * 1"
workflow_dispatch:
inputs:
upstream_ref:
description: "Upstream ref to sync from (default: main)"
required: false
default: "main"
cohere_branch:
description: "Cohere branch to merge into"
required: false
default: "cohere"

permissions:
contents: write

Check failure

Code scanning / zizmor

overly broad permissions Error

overly broad permissions

Check notice

Code scanning / zizmor

permissions without explanatory comments Note

permissions without explanatory comments
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
pull-requests: write

Check failure

Code scanning / zizmor

overly broad permissions Error

overly broad permissions
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed

env:
UPSTREAM_REPO: https://github.com/confidential-containers/cloud-api-adaptor.git
UPSTREAM_REF: ${{ inputs.upstream_ref || 'main' }}
COHERE_BRANCH: ${{ inputs.cohere_branch || 'cohere' }}

jobs:
# ── Step 1: fast-forward origin/main to match upstream/main ──────────────
sync-main:

Check notice

Code scanning / zizmor

workflow or action definition without a name Note

workflow or action definition without a name
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
runs-on: ubuntu-latest
outputs:
new_commits: ${{ steps.ff.outputs.new_commits }}
upstream_sha: ${{ steps.ff.outputs.upstream_sha }}
steps:
- name: Checkout main
uses: actions/checkout@v4

Check failure

Code scanning / zizmor

unpinned action reference Error

unpinned action reference
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
with:
ref: main
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

Check warning

Code scanning / zizmor

credential persistence through GitHub Actions artifacts Warning

credential persistence through GitHub Actions artifacts
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed

- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

- name: Fast-forward main to upstream
id: ff
run: |

Check failure on line 49 in .github/workflows/sync-upstream.yaml

View workflow job for this annotation

GitHub Actions / run-actionlint

shellcheck reported issue in this script: SC2086:info:5:47: Double quote to prevent globbing and word splitting

Check failure on line 49 in .github/workflows/sync-upstream.yaml

View workflow job for this annotation

GitHub Actions / run-actionlint

shellcheck reported issue in this script: SC2086:info:4:46: Double quote to prevent globbing and word splitting

Check failure on line 49 in .github/workflows/sync-upstream.yaml

View workflow job for this annotation

GitHub Actions / run-actionlint

shellcheck reported issue in this script: SC2086:info:22:30: Double quote to prevent globbing and word splitting

Check failure on line 49 in .github/workflows/sync-upstream.yaml

View workflow job for this annotation

GitHub Actions / run-actionlint

shellcheck reported issue in this script: SC2086:info:15:39: Double quote to prevent globbing and word splitting
git remote add upstream "$UPSTREAM_REPO" || true
git fetch upstream "$UPSTREAM_REF"

BEHIND=$(git rev-list --count HEAD..upstream/$UPSTREAM_REF)
UPSTREAM_SHA=$(git rev-parse --short upstream/$UPSTREAM_REF)
echo "upstream_sha=$UPSTREAM_SHA" >> "$GITHUB_OUTPUT"

if [ "$BEHIND" -eq 0 ]; then
echo "main is already up to date with upstream."
echo "new_commits=0" >> "$GITHUB_OUTPUT"
exit 0
fi

# Verify this is a clean fast-forward (main should have no extra commits).
AHEAD=$(git rev-list --count upstream/$UPSTREAM_REF..HEAD)
if [ "$AHEAD" -ne 0 ]; then
echo "::error::origin/main is $AHEAD commits AHEAD of upstream — cannot fast-forward."
echo "::error::Remove the extra commits first (rebase or reset) before syncing."
exit 1
fi

git merge --ff-only upstream/$UPSTREAM_REF
git push origin main
echo "new_commits=$BEHIND" >> "$GITHUB_OUTPUT"
echo "Fast-forwarded main by $BEHIND commits to $UPSTREAM_SHA"

# ── Step 2: merge updated main into the cohere branch via PR ─────────────
sync-cohere:

Check notice

Code scanning / zizmor

workflow or action definition without a name Note

workflow or action definition without a name
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
needs: sync-main
runs-on: ubuntu-latest
steps:
- name: Checkout cohere branch
uses: actions/checkout@v4

Check failure

Code scanning / zizmor

unpinned action reference Error

unpinned action reference
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
with:
ref: ${{ env.COHERE_BRANCH }}
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

Check warning

Code scanning / zizmor

credential persistence through GitHub Actions artifacts Warning

credential persistence through GitHub Actions artifacts
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed

- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

- name: Check if cohere is behind main
id: check
run: |
git fetch origin main
BEHIND=$(git rev-list --count HEAD..origin/main)
echo "behind=$BEHIND" >> "$GITHUB_OUTPUT"
echo "Cohere branch is $BEHIND commits behind origin/main"

DATE=$(date +%Y-%m-%d)
SHORT_SHA=$(git rev-parse --short origin/main)
echo "sync_branch=sync/upstream-${DATE}-${SHORT_SHA}" >> "$GITHUB_OUTPUT"

- name: Skip if up to date
if: steps.check.outputs.behind == '0'
run: echo "Cohere branch is already up to date with main. Nothing to do."

- name: Create sync branch and attempt merge
if: steps.check.outputs.behind != '0'
id: merge
run: |
git checkout -b "${{ steps.check.outputs.sync_branch }}"

Check notice

Code scanning / zizmor

code injection via template expansion Note

code injection via template expansion
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed

if git merge origin/main --no-edit \
-m "Merge main (${{ needs.sync-main.outputs.upstream_sha }}) into $COHERE_BRANCH"; then

Check notice

Code scanning / zizmor

code injection via template expansion Note

code injection via template expansion
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
echo "conflict=false" >> "$GITHUB_OUTPUT"
else
echo "conflict=true" >> "$GITHUB_OUTPUT"
echo ""
echo "=== CONFLICT: listing conflicted files ==="
git diff --name-only --diff-filter=U
# Abort so the branch stays at the cohere HEAD — the reviewer
# will run the merge locally and get native Git conflict tooling.
git merge --abort
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated
fi

- name: Push sync branch
if: steps.check.outputs.behind != '0'
run: git push origin "${{ steps.check.outputs.sync_branch }}"

Check notice

Code scanning / zizmor

code injection via template expansion Note

code injection via template expansion
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed

- name: Create pull request (clean merge)
if: steps.check.outputs.behind != '0' && steps.merge.outputs.conflict == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
BEHIND=${{ steps.check.outputs.behind }}

Check notice

Code scanning / zizmor

code injection via template expansion Note

code injection via template expansion
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
UPSTREAM_SHA=${{ needs.sync-main.outputs.upstream_sha }}

Check notice

Code scanning / zizmor

code injection via template expansion Note

code injection via template expansion
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed

gh pr create \
--base "$COHERE_BRANCH" \
--head "${{ steps.check.outputs.sync_branch }}" \

Check notice

Code scanning / zizmor

code injection via template expansion Note

code injection via template expansion
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
--title "Sync upstream ($UPSTREAM_SHA) — $BEHIND new commits" \
--body "$(cat <<EOF
## Upstream sync

Merges **${BEHIND}** new commits from \`main\` (synced from upstream) into \`$COHERE_BRANCH\`.

**Upstream HEAD**: \`${UPSTREAM_SHA}\`
**Conflicts**: None — clean merge.

### Review checklist
- [ ] Scan the diff for changes that touch files we've customized
- [ ] Verify CI passes
- [ ] Check if any upstream changes obsolete our patches
EOF
)"

- name: Create pull request (conflicts)
if: steps.check.outputs.behind != '0' && steps.merge.outputs.conflict == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
UPSTREAM_SHA=${{ needs.sync-main.outputs.upstream_sha }}

Check notice

Code scanning / zizmor

code injection via template expansion Note

code injection via template expansion
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed

gh pr create \
--base "$COHERE_BRANCH" \
--head "${{ steps.check.outputs.sync_branch }}" \

Check notice

Code scanning / zizmor

code injection via template expansion Note

code injection via template expansion
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
--title "Sync upstream ($UPSTREAM_SHA) — needs conflict resolution" \
--body "$(cat <<EOF
## Upstream sync — manual merge needed

Upstream has new commits to merge into \`$COHERE_BRANCH\`, but there are conflicts.

**Upstream HEAD**: \`${UPSTREAM_SHA}\`

### How to resolve

\`\`\`bash
git fetch origin
git checkout ${{ steps.check.outputs.sync_branch }}

Check notice

Code scanning / zizmor

code injection via template expansion Note

code injection via template expansion
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
git merge origin/main
# Git will show conflicts — resolve them in your IDE, then:
git add -A && git commit
git push origin ${{ steps.check.outputs.sync_branch }}

Check notice

Code scanning / zizmor

code injection via template expansion Note

code injection via template expansion
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
\`\`\`

Your IDE will show the native merge conflict UI with accept-theirs /
accept-ours / accept-both options for each conflict.

### Review checklist
- [ ] Resolve all conflicts
- [ ] Verify CI passes
- [ ] Check if any upstream changes obsolete our patches
EOF
)"
Loading