Skip to content

Commit 699a3b7

Browse files
committed
Add GitHub Actions workflow for syncing changes from personal repository
1 parent 29b5ec4 commit 699a3b7

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

.github/workflows/sync.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Sync from Personal Repo
2+
3+
on:
4+
schedule:
5+
- cron: '0 2 * * *' # Every day at 2:00 AM UTC
6+
workflow_dispatch: # Allow manual trigger
7+
8+
jobs:
9+
sync:
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 10 # Prevent long-running jobs
12+
13+
steps:
14+
- name: Checkout organization repo
15+
uses: actions/checkout@v3
16+
with:
17+
ref: main
18+
persist-credentials: false # We'll use a PAT for pushing
19+
20+
- name: Set up Git user
21+
run: |
22+
git config user.name "github-actions[bot]"
23+
git config user.email "github-actions[bot]@users.noreply.github.com"
24+
25+
- name: Add personal repo as remote
26+
run: |
27+
git remote add personal https://github.com/chojuninengu/cameroon-developer-network.git
28+
git fetch personal
29+
continue-on-error: true # Continue even if fetch fails
30+
31+
- name: Check for changes
32+
id: check_changes
33+
run: |
34+
if git diff --quiet personal/main main; then
35+
echo "No changes to sync"
36+
echo "has_changes=false" >> $GITHUB_OUTPUT
37+
else
38+
echo "Changes detected"
39+
echo "has_changes=true" >> $GITHUB_OUTPUT
40+
fi
41+
42+
- name: Merge changes from personal repo
43+
if: steps.check_changes.outputs.has_changes == 'true'
44+
run: |
45+
git merge personal/main --allow-unrelated-histories --no-edit || {
46+
echo "Merge conflict detected"
47+
git merge --abort
48+
exit 1
49+
}
50+
51+
- name: Push to organization repo
52+
if: steps.check_changes.outputs.has_changes == 'true'
53+
env:
54+
TOKEN: ${{ secrets.PERSONAL_REPO_TOKEN }}
55+
run: |
56+
git remote set-url origin https://x-access-token:${TOKEN}@github.com/Cameroon-Developer-Network/welcome-to-cdn.git
57+
git push origin main || {
58+
echo "Failed to push changes"
59+
exit 1
60+
}
61+
62+
- name: Cleanup
63+
if: always()
64+
run: |
65+
git remote remove personal || true
66+
git clean -fd || true
67+
68+
- name: Notify on failure
69+
if: failure()
70+
run: |
71+
echo "Sync workflow failed. Please check the logs for details."
72+
exit 1

0 commit comments

Comments
 (0)