Skip to content

Commit bf5c60b

Browse files
committed
ci: github workflow
Signed-off-by: QuentinN42 <quentin@lieumont.fr>
1 parent a414bf7 commit bf5c60b

3 files changed

Lines changed: 66 additions & 3 deletions

File tree

.github/workflows/commit-sync.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Commit Sync
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
schedule:
8+
- cron: '0 0 * * *' # Run daily at midnight UTC
9+
10+
jobs:
11+
sync-commits:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
with:
18+
token: ${{ secrets.GITHUB_TOKEN }}
19+
fetch-depth: 0
20+
- name: Run commit sync
21+
env:
22+
GITLAB_USERNAME: ${{ secrets.GITLAB_USERNAME }}
23+
REPOSITORY: ${{ secrets.REPOSITORY }}
24+
GITHUB_USERNAME: ${{ secrets.GITHUB_USERNAME }}
25+
GITHUB_EMAIL: ${{ secrets.GITHUB_EMAIL }}
26+
run: ./script.sh

README.md

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,38 @@
1-
# Commit sync
1+
# Commit Sync
22

3-
Sync your gitlab commits history with gihub.
3+
Fork this repo to sync your GitLab commit history with GitHub.
44

5-
## Usage
5+
This tool automatically creates commits on GitHub with dates matching your GitLab activity calendar, helping maintain a consistent contribution history across platforms.
6+
7+
## How it works
8+
9+
The GitHub Action will:
10+
11+
- Run automatically on every commit to main/master branch
12+
- Run daily at midnight UTC via scheduled cron job
13+
- Fetch your GitLab activity calendar
14+
- Create commits with matching dates for any missing activity
15+
- Push the changes back to your repository
16+
17+
## Setup
18+
19+
1. Fork this repository
20+
2. Go to your fork's Settings → Secrets and variables → Actions
21+
3. Add the following secrets:
22+
- `GITLAB_USERNAME`: Your GitLab username
23+
- `REPOSITORY`: The Git repository URL to sync to (e.g., `https://github.com/username/repo.git`)
24+
- `GITHUB_USERNAME`: Your GitHub username
25+
- `GITHUB_EMAIL`: Your GitHub email address
26+
27+
## Manual Usage
28+
29+
You can also run the script manually:
630

731
```bash
32+
export GITLAB_USERNAME="your-gitlab-username"
33+
export REPOSITORY="https://github.com/username/repo.git"
34+
export GITHUB_USERNAME="your-github-username"
35+
export GITHUB_EMAIL="your-github-email@example.com"
36+
837
./script.sh
938
```

script.sh

100644100755
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ todo="$(curl -s "https://gitlab.com/users/${GITLAB_USERNAME}/calendar.json" | jq
3636
already_done="$(git log --pretty='format:%s' | grep -E "^${PRE_COMMIT_MSG}" | sed "s/^${PRE_COMMIT_MSG}//")"
3737

3838
export IFS=$'\n'
39+
commits=0
3940
for x in $todo;
4041
do
4142
echo "Processing ${x}"
@@ -44,5 +45,12 @@ do
4445
git add changes
4546
commit_date="$(date -d "$(echo "${x}" | cut -d- -f-3)" '+%Y-%m-%d %H:%M:%S')"
4647
GIT_COMMITTER_DATE="${commit_date}" git commit -s -m "${PRE_COMMIT_MSG}${x}" --date "${commit_date}"
48+
commits=$((commits + 1))
4749
fi
4850
done
51+
52+
git push origin HEAD
53+
54+
echo
55+
echo "Done ! Added ${commits} commits"
56+
echo

0 commit comments

Comments
 (0)