Skip to content

Commit 02aee9c

Browse files
authored
chore: add workflow to mirror external repo (#16)
1 parent 8c03fbf commit 02aee9c

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

.github/workflows/sync.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Sync from External Repository
2+
3+
on:
4+
schedule:
5+
- cron: '0 */3 * * *'
6+
workflow_dispatch:
7+
8+
jobs:
9+
sync:
10+
runs-on: ["self-hosted"]
11+
if: ${{ !contains(github.server_url, 'github.com') }}
12+
steps:
13+
- name: Configure Git
14+
run: |
15+
git config --global user.name "GitHub Actions Bot"
16+
git config --global user.email "actions@github.com"
17+
18+
- name: Mirror main branch
19+
env:
20+
EXTERNAL_REPO: https://github.com/SAP/cloud-sdk-python.git
21+
INTERNAL_REPO: ${{ format('https://{0}/{1}.git', github.server_url, github.repository) }}
22+
INTERNAL_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
run: |
24+
echo "Cloning external repository main branch..."
25+
git clone --single-branch --branch main "$EXTERNAL_REPO" repo-clone
26+
cd repo-clone
27+
28+
echo "Adding internal remote..."
29+
INTERNAL_REPO="https://oauth2:${INTERNAL_TOKEN}@${INTERNAL_REPO#https://}"
30+
git remote add internal "$INTERNAL_REPO"
31+
32+
echo "Pushing main branch to internal repository..."
33+
git push internal main:main --force-with-lease
34+
35+
echo "Mirror completed successfully"
36+
37+
- name: Summary
38+
if: success()
39+
run: |
40+
echo "### Sync Successful" >> $GITHUB_STEP_SUMMARY
41+
42+
echo "" >> $GITHUB_STEP_SUMMARY
43+
echo "External repository **main** branch has been successfully mirrored to internal." >> $GITHUB_STEP_SUMMARY
44+
echo "- **External**: https://github.com/SAP/cloud-sdk-python" >> $GITHUB_STEP_SUMMARY
45+
echo "- **Branch**: main" >> $GITHUB_STEP_SUMMARY
46+
echo "- **Time**: $(date -u)" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)