Skip to content

Commit 8759da6

Browse files
authored
Merge pull request #11 from ShipSecAI/chore/upstream-sync-workflow
ci: add daily upstream sync workflow
2 parents 42e0831 + 643acfa commit 8759da6

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Sync upstream main
2+
3+
on:
4+
schedule:
5+
- cron: "0 9 * * *" # Once daily at 9am UTC
6+
workflow_dispatch: # Manual trigger
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
sync:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Add upstream remote
22+
run: |
23+
git remote add upstream https://github.com/ShipSecAI/studio.git || true
24+
git fetch upstream main
25+
26+
- name: Check for divergence
27+
id: check
28+
run: |
29+
UPSTREAM_SHA=$(git rev-parse upstream/main)
30+
# Check if upstream-sync branch exists on origin
31+
if git ls-remote --exit-code origin upstream-sync &>/dev/null; then
32+
CURRENT_SHA=$(git rev-parse origin/upstream-sync)
33+
else
34+
CURRENT_SHA=""
35+
fi
36+
37+
if [ "$UPSTREAM_SHA" = "$CURRENT_SHA" ]; then
38+
echo "skip=true" >> "$GITHUB_OUTPUT"
39+
echo "No new upstream commits"
40+
else
41+
echo "skip=false" >> "$GITHUB_OUTPUT"
42+
AHEAD=$(git rev-list --count origin/main..upstream/main)
43+
echo "ahead=$AHEAD" >> "$GITHUB_OUTPUT"
44+
echo "Upstream is $AHEAD commits ahead"
45+
fi
46+
47+
- name: Push upstream-sync branch
48+
if: steps.check.outputs.skip == 'false'
49+
run: |
50+
git checkout -B upstream-sync upstream/main
51+
git push origin upstream-sync --force
52+
53+
- name: Create or update PR
54+
if: steps.check.outputs.skip == 'false'
55+
env:
56+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57+
run: |
58+
EXISTING_PR=$(gh pr list --head upstream-sync --base main --state open --json number --jq '.[0].number' 2>/dev/null || echo "")
59+
60+
if [ -n "$EXISTING_PR" ]; then
61+
echo "PR #$EXISTING_PR already exists, updated sync branch"
62+
gh pr comment "$EXISTING_PR" --body "Sync branch updated. Upstream is now ${{ steps.check.outputs.ahead }} commits ahead of main."
63+
else
64+
gh pr create \
65+
--head upstream-sync \
66+
--base main \
67+
--title "sync: merge upstream main" \
68+
--body "$(cat <<'EOF'
69+
Automated sync from [ShipSecAI/studio](https://github.com/ShipSecAI/studio) main.
70+
71+
**${{ steps.check.outputs.ahead }} new upstream commits.**
72+
73+
Review the changes and merge when ready. If there are conflicts, resolve them locally:
74+
```bash
75+
git fetch origin upstream-sync main
76+
git checkout main
77+
git merge origin/upstream-sync
78+
# resolve conflicts
79+
git push origin main
80+
```
81+
EOF
82+
)"
83+
fi

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ node_modules/
1111

1212
# Generated files
1313
*.generated.ts
14+
15+
# GitHub Actions (uses ${{ }} template syntax)
16+
.github/workflows/

0 commit comments

Comments
 (0)