Skip to content

Commit 836b04f

Browse files
committed
ci: add repo mirroring workflow
- [add] Create new GitHub Actions workflow file (.github/workflows/repo-mirror.yml) - [config] Set workflow name to "Repository Mirroring" (repo-mirror.yml:1) - [config] Configure triggers for push/delete on main and workflow_dispatch (repo-mirror.yml:4-8) - [add] Define 'mirror_to_gitlab' job running on ubuntu-latest (repo-mirror.yml:10-11) - [ci] Add checkout step with fetch-depth: 0 to mirror_to_gitlab job (repo-mirror.yml:13-15) - [config] Add "Configure Git" step to mirror_to_gitlab job (repo-mirror.yml:16-19) - [config] Set SSH_PRIVATE_KEY and TARGET_URL envs from secrets for mirror_to_gitlab job (repo-mirror.yml:20-23) - [ci] Add step to setup SSH and force push to target URL in mirror_to_gitlab job (repo-mirror.yml:24-30) - [add] Define 'mirror_to_gitea' job running on ubuntu-latest (repo-mirror.yml:32-33) - [ci] Add checkout step with fetch-depth: 0 to mirror_to_gitea job (repo-mirror.yml:35-37) - [config] Add "Configure Git" step to mirror_to_gitea job (repo-mirror.yml:38-41) - [config] Set SSH_PRIVATE_KEY and TARGET_URL envs from secrets for mirror_to_gitea job (repo-mirror.yml:42-45) - [ci] Add step to setup SSH and force push to target URL in mirror_to_gitea job (repo-mirror.yml:46-52)
1 parent 286fd12 commit 836b04f

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

.github/workflows/repo-mirror.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Repository Mirroring
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
delete:
7+
branches: [ "main" ]
8+
workflow_dispatch: # Allows manual triggering
9+
10+
jobs:
11+
mirror_to_gitlab:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
with:
16+
fetch-depth: 0
17+
- name: Configure Git
18+
run: |
19+
git config --global user.name "GitHub Actions"
20+
git config --global user.email "[email protected]"
21+
- name: Mirror to GitLab
22+
env:
23+
SSH_PRIVATE_KEY: ${{ secrets.GITLAB_SSH_PRIVATE_KEY }}
24+
TARGET_URL: ${{ secrets.GITLAB_REPO_URL }}
25+
run: |
26+
mkdir -p ~/.ssh
27+
echo "${SSH_PRIVATE_KEY}" > ~/.ssh/id_rsa
28+
chmod 600 ~/.ssh/id_rsa
29+
ssh-keyscan gitlab.com >> ~/.ssh/known_hosts
30+
# Push local branches and tags, excluding remote refs
31+
git push --force ${TARGET_URL} 'refs/heads/*:refs/heads/*' 'refs/tags/*:refs/tags/*'
32+
33+
mirror_to_gitea:
34+
runs-on: ubuntu-latest
35+
steps:
36+
- uses: actions/checkout@v3
37+
with:
38+
fetch-depth: 0
39+
- name: Configure Git
40+
run: |
41+
git config --global user.name "GitHub Actions"
42+
git config --global user.email "[email protected]"
43+
- name: Mirror to Gitea
44+
env:
45+
SSH_PRIVATE_KEY: ${{ secrets.GITEA_SSH_PRIVATE_KEY }}
46+
TARGET_URL: ${{ secrets.GITEA_REPO_URL }}
47+
run: |
48+
mkdir -p ~/.ssh
49+
echo "${SSH_PRIVATE_KEY}" > ~/.ssh/id_rsa
50+
chmod 600 ~/.ssh/id_rsa
51+
ssh-keyscan -t rsa $(echo ${TARGET_URL} | cut -d '@' -f 2 | cut -d ':' -f 1) >> ~/.ssh/known_hosts
52+
# Push local branches and tags, excluding remote refs
53+
git push --force ${TARGET_URL} 'refs/heads/*:refs/heads/*' 'refs/tags/*:refs/tags/*'

0 commit comments

Comments
 (0)