@@ -3,75 +3,79 @@ stages:
33 - sync
44
55pages :
6- stage : deploy
7- # The Docker image that will be used to build your app
8- image : node:lts
6+ stage : deploy
7+ # The Docker image that will be used to build your app
8+ image : node:lts
99 # Functions that should be executed before the build script is run
10- before_script :
11- - npm install
12- script :
13- - npm run build
14- - mv public public-vue
15- - mv dist public
16- artifacts :
17- paths :
18- # The folder that contains the files to be exposed at the Page URL
19- # Must be public for GitLab pages
20- - public
21- rules :
22- # This ensures that only pushes to the default branch will trigger
23- # a pages deploy
24- - if : $CI_COMMIT_REF_NAME == "production"
25- tags :
26- - docker
10+ before_script :
11+ - npm install
12+ script :
13+ - npm run build
14+ - mv public public-vue
15+ - mv dist public
16+ artifacts :
17+ paths :
18+ # The folder that contains the files to be exposed at the Page URL
19+ # Must be public for GitLab pages
20+ - public
21+ rules :
22+ # This ensures that only pushes to the default branch will trigger a pages deployment
23+ - if : $CI_COMMIT_REF_NAME == "production"
24+ tags :
25+ - docker
2726
2827sync_to_github :
29- stage : sync
30- image : alpine:latest
31- rules :
32- - if : ' $CI_COMMIT_BRANCH == "github-sync"'
33- when : on_success
34- variables :
35- GITLAB_BRANCH : " github-sync"
36- GITHUB_BRANCH : " main"
37- before_script :
38- # Setup git
39- - apk add --no-cache git
40- - git config --global user.email "$GIT_USER_EMAIL"
41- - git config --global user.name "$GIT_USER_NAME"
28+ stage : sync
29+ image : alpine:latest
30+ rules :
31+ - if : ' $CI_COMMIT_TAG != null'
32+ - if : ' $CI_COMMIT_BRANCH == "github-sync"'
33+ when : on_success
34+ variables :
35+ GITLAB_BRANCH : " github-sync"
36+ GITHUB_BRANCH : " main"
4237
43- # Get the version from package.json
44- - apk add --no-cache nodejs npm
45- - export VERSION=$(node -p "require('./package.json').version")
46- - export GIT_MERGE_MSG="Release v${VERSION}"
47- script :
48- # 1. Add the upstream repository
49- - git remote add github "https://$GITHUB_TOKEN@$GITHUB_REPO "
38+ GIT_STRATEGY : fetch
39+ GIT_DEPTH : " 0 "
40+ before_script :
41+ # Setup git
42+ - apk add --no-cache git
43+ - git config --global user.email "$GIT_USER_EMAIL"
44+ - git config --global user.name "$GIT_USER_NAME "
5045
51- # 2. Fetch the latest changes from the upstream repository
52- - git fetch github $GITHUB_BRANCH
53- - git checkout -B $GITHUB_BRANCH github/$GITHUB_BRANCH
46+ # Get the version from package.json
47+ - apk add --no-cache nodejs npm
48+ - export VERSION=$(node -p "require('./package.json').version")
49+ - export GIT_MERGE_MSG="Release v${VERSION}"
5450
55- # 3. Check if there is a common ancestor between the public branch and the main branch
56- - |
57- if git merge-base --is-ancestor origin/$GITLAB_BRANCH $GITHUB_BRANCH; then
58- echo "✅ Common ancestor found - normal merge"
59- MERGE_FLAGS="--squash"
60- else
61- echo "⚠️ No common ancestor - merge with --allow-unrelated-histories"
62- MERGE_FLAGS="--squash --allow-unrelated-histories"
63- fi
51+ # Ensure both sides are available locally
52+ - git fetch origin "$GITLAB_BRANCH"
6453
65- # 4. Squash-merge the changes from the public branch into the local main branch
66- # Always use GitLab's changes in case of conflicts
67- - git merge $MERGE_FLAGS origin/$GITLAB_BRANCH -X theirs
54+ # Add GitHub remote and fetch the target branch
55+ - git remote add github "https://$GITHUB_TOKEN@$GITHUB_REPO"
56+ - git fetch github "$GITHUB_BRANCH"
57+ script :
58+ # Start from the GitHub branch tip
59+ - git checkout -B "$GITHUB_BRANCH" "github/$GITHUB_BRANCH"
6860
69- # 5. Commit the changes
70- - git commit -m "$GIT_MERGE_MSG"
61+ # Replace the entire working tree with the GitLab branch snapshot
62+ # (this reliably propagates deletions too)
63+ - git rm -r --ignore-unmatch .
64+ - git checkout "origin/$GITLAB_BRANCH" -- .
65+ - git add -A
7166
72- # 6. Push the changes to the upstream repository
73- - git push github $GITHUB_BRANCH --force-with-lease
67+ # Commit only if something actually changed
68+ - |
69+ if git diff --cached --quiet; then
70+ echo "No changes to sync."
71+ exit 0
72+ fi
7473
75- after_script :
76- # Clean up to prevent token exposure
77- - git remote remove github
74+ - git commit -m "$GIT_MERGE_MSG"
75+
76+ # Push the new snapshot commit
77+ - git push github "$GITHUB_BRANCH" --force-with-lease
78+
79+ after_script :
80+ # Clean up to prevent token exposure
81+ - git remote remove github
0 commit comments