-
Notifications
You must be signed in to change notification settings - Fork 6
62 lines (52 loc) · 2.07 KB
/
Copy pathsync-to-gitlab.yml
File metadata and controls
62 lines (52 loc) · 2.07 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
name: Sync protected branches to GitLab
on:
push:
branches:
- develop
- main
workflow_dispatch:
jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Prepare GitLab repository settings
id: gitlab-repo
uses: ./.github/actions/prepare-gitlab-repo
with:
gitlab-repo: ${{ secrets.GITLAB_REPO }}
- name: Push protected branches and tags to GitLab
env:
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
GITLAB_REPO_HOST_PATH: ${{ steps.gitlab-repo.outputs.host-path }}
GITLAB_COM_TOKEN: ${{ secrets.GITLAB_COM_TOKEN }}
GITLAB_COM_REPO_HOST_PATH: gitlab.com/yoshifuminakamura/benchkit.git
run: |
set -euo pipefail
if [ -z "${GITLAB_TOKEN}" ] || [ -z "${GITLAB_REPO_HOST_PATH}" ]; then
echo "GITLAB_TOKEN and GITLAB_REPO secrets are required."
exit 1
fi
git config user.name "github-bot"
git config user.email "bot@example.com"
git fetch origin +refs/heads/develop:refs/remotes/origin/develop +refs/heads/main:refs/remotes/origin/main
sync_gitlab_remote() {
local remote_name="$1"
local token="$2"
local host_path="$3"
git remote remove "${remote_name}" 2>/dev/null || true
git remote add "${remote_name}" "https://oauth2:${token}@${host_path}"
git push -o ci.skip "${remote_name}" \
refs/remotes/origin/develop:refs/heads/develop \
refs/remotes/origin/main:refs/heads/main \
--force
git push -o ci.skip "${remote_name}" --tags --force
}
sync_gitlab_remote gitlab "${GITLAB_TOKEN}" "${GITLAB_REPO_HOST_PATH}"
if [ -n "${GITLAB_COM_TOKEN}" ]; then
sync_gitlab_remote gitlab-com "${GITLAB_COM_TOKEN}" "${GITLAB_COM_REPO_HOST_PATH}"
else
echo "GITLAB_COM_TOKEN is not set; skipping GitLab.com mirror ${GITLAB_COM_REPO_HOST_PATH}."
fi