-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
65 lines (54 loc) · 1.92 KB
/
Copy path.gitlab-ci.yml
File metadata and controls
65 lines (54 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
stages:
- deploy
variables:
# Branches to mirror to GitHub. Edit this list as needed.
MIRROR_BRANCHES: "master newscope audioprocessing accessibility"
mirror-to-github:
stage: deploy
variables:
GIT_DEPTH: "0"
rules:
- if: $CI_COMMIT_BRANCH
image:
name: alpine/git:latest
entrypoint: [""]
script:
- |
# Check if current branch is in the mirror list
SHOULD_MIRROR=false
for BRANCH in $MIRROR_BRANCHES; do
if [ "$CI_COMMIT_BRANCH" = "$BRANCH" ]; then
SHOULD_MIRROR=true
break
fi
done
if [ "$SHOULD_MIRROR" = "false" ]; then
echo "Branch '$CI_COMMIT_BRANCH' is not in mirror list, skipping."
exit 0
fi
echo "Mirroring branch '$CI_COMMIT_BRANCH' to GitHub..."
GITHUB_URL="https://x-access-token:${GITHUB_PAT}@github.com/eliggett/wfview.git"
# Set up git identity (required for some git operations)
git config user.email "ci@mirror"
git config user.name "GitLab Mirror"
# Check if the original commit has a tag before we rewrite history
ORIGINAL_TAG=$(git tag --points-at "$CI_COMMIT_SHA" | head -1)
if [ -n "$ORIGINAL_TAG" ]; then
echo "Found tag '$ORIGINAL_TAG' on commit $CI_COMMIT_SHA"
else
echo "No tag on this commit."
fi
# Create orphan branch with the current tree
git checkout --orphan mirror_branch
git add -A
git commit -m "Mirror of $CI_COMMIT_SHORT_SHA"
# If the original commit had a tag, recreate it on the new commit
PUSH_REFS="HEAD:refs/heads/$CI_COMMIT_BRANCH"
if [ -n "$ORIGINAL_TAG" ]; then
git tag -f "$ORIGINAL_TAG" HEAD
PUSH_REFS="$PUSH_REFS refs/tags/$ORIGINAL_TAG"
echo "Tag '$ORIGINAL_TAG' applied to mirrored commit."
fi
# Push branch (and tag if present) to GitHub in one operation
git push --force --no-thin "$GITHUB_URL" $PUSH_REFS
echo "Done."