Skip to content

Commit fc2c085

Browse files
committed
ci: add DDMAL workflow for syncing with RISM changes
- This workflow runs every Monday at 3am montreal time. refs: Neon/issues/1347
1 parent b741a12 commit fc2c085

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
name: Sync with RISM Upstream
2+
3+
on:
4+
# Run automatically every Monday at 07:00 UTC (3am in Montreal)
5+
schedule:
6+
- cron: "0 7 * * 1"
7+
8+
# Allow manual triggering
9+
workflow_dispatch:
10+
inputs:
11+
force_rebase:
12+
description: "Force rebase even if no new commits detected"
13+
required: false
14+
default: false
15+
type: boolean
16+
17+
jobs:
18+
sync-upstream:
19+
runs-on: ubuntu-latest
20+
# Only run this workflow on the DDMAL/verovio repository
21+
if: github.repository == 'DDMAL/verovio'
22+
23+
steps:
24+
- name: Checkout repository
25+
uses: actions/checkout@v4
26+
with:
27+
# Fetch full history for proper rebasing
28+
fetch-depth: 0
29+
# Use a personal access token with repo permissions
30+
token: ${{ secrets.GITHUB_TOKEN }}
31+
ref: develop
32+
33+
- name: Configure Git
34+
run: |
35+
git config user.name "github-actions[bot]"
36+
git config user.email "github-actions[bot]@users.noreply.github.com"
37+
38+
- name: Add upstream remote
39+
run: |
40+
# Check if upstream remote already exists
41+
if git remote get-url upstream 2>/dev/null; then
42+
echo "Upstream remote already exists"
43+
git remote set-url upstream https://github.com/rism-digital/verovio.git
44+
else
45+
echo "Adding upstream remote"
46+
git remote add upstream https://github.com/rism-digital/verovio.git
47+
fi
48+
49+
- name: Fetch upstream changes
50+
run: |
51+
echo "Fetching upstream changes..."
52+
git fetch upstream develop
53+
54+
- name: Check for new commits
55+
id: check_commits
56+
run: |
57+
# Get the latest commit hash from upstream
58+
UPSTREAM_COMMIT=$(git rev-parse upstream/develop)
59+
60+
# Get the latest commit hash from our develop branch
61+
LOCAL_COMMIT=$(git rev-parse develop)
62+
63+
echo "Upstream commit: $UPSTREAM_COMMIT"
64+
echo "Local commit: $LOCAL_COMMIT"
65+
66+
# Check if there are new commits to sync
67+
if [ "$UPSTREAM_COMMIT" != "$LOCAL_COMMIT" ]; then
68+
echo "new_commits=true" >> $GITHUB_OUTPUT
69+
echo "New commits detected in upstream"
70+
71+
# Count the number of commits behind
72+
COMMITS_BEHIND=$(git rev-list --count develop..upstream/develop)
73+
echo "commits_behind=$COMMITS_BEHIND" >> $GITHUB_OUTPUT
74+
echo "Local branch is $COMMITS_BEHIND commits behind upstream"
75+
else
76+
echo "new_commits=false" >> $GITHUB_OUTPUT
77+
echo "No new commits in upstream"
78+
echo "commits_behind=0" >> $GITHUB_OUTPUT
79+
fi
80+
81+
- name: Check for local uncommitted changes
82+
# It's a good practice to check if the runner is in a dirty state before running a rebase
83+
if: steps.check_commits.outputs.new_commits == 'true' || github.event.inputs.force_rebase == 'true'
84+
run: |
85+
if [ -n "$(git status --porcelain)" ]; then
86+
echo "Error: Working directory has uncommitted changes"
87+
git status
88+
exit 1
89+
fi
90+
91+
- name: Rebase onto upstream
92+
if: steps.check_commits.outputs.new_commits == 'true' || github.event.inputs.force_rebase == 'true'
93+
run: |
94+
echo "Starting rebase onto upstream/develop..."
95+
96+
# Attempt to rebase
97+
if git rebase upstream/develop; then
98+
echo "✅ Rebase successful!"
99+
else
100+
echo "❌ Rebase failed due to conflicts"
101+
echo "Aborting rebase..."
102+
git rebase --abort
103+
104+
# Set failure type
105+
echo "SYNC_FAILED=rebase" >> $GITHUB_ENV
106+
exit 1
107+
fi
108+
109+
- name: Push rebased changes
110+
if: (steps.check_commits.outputs.new_commits == 'true' || github.event.inputs.force_rebase == 'true') && env.SYNC_FAILED == ''
111+
# force-with-lease is used to avoid overwriting changes that have been pushed and not yet merged to upstream
112+
run: |
113+
echo "Pushing rebased changes to origin/develop..."
114+
if ! git push --force-with-lease origin develop; then
115+
echo "❌ Push failed"
116+
echo "SYNC_FAILED=push" >> $GITHUB_ENV
117+
exit 1
118+
fi
119+
120+
- name: Summary
121+
if: always()
122+
run: |
123+
if [ "${{ steps.check_commits.outputs.new_commits }}" = "true" ] || [ "${{ github.event.inputs.force_rebase }}" = "true" ]; then
124+
if [ "$SYNC_FAILED" = "rebase" ]; then
125+
echo "❌ Sync failed due to rebase conflicts"
126+
elif [ "$SYNC_FAILED" = "push" ]; then
127+
echo "❌ Sync failed due to push error"
128+
else
129+
echo "✅ Successfully synced ${{ steps.check_commits.outputs.commits_behind }} commits from upstream"
130+
echo "🚀 Changes pushed to develop branch"
131+
fi
132+
else
133+
echo "ℹ️ No new commits to sync"
134+
fi

0 commit comments

Comments
 (0)