Skip to content

Commit 71448c1

Browse files
committed
TUN-9800: Add pipeline to sync between gitlab and github repos
1 parent 80b1634 commit 71448c1

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

.ci/github.gitlab-ci.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
include:
2+
- local: .ci/commons.gitlab-ci.yml
3+
4+
######################################
5+
### Sync master branch with Github ###
6+
######################################
7+
push-github:
8+
stage: sync
9+
rules:
10+
- !reference [.default-rules, run-on-master]
11+
script:
12+
- ./.ci/scripts/github-push.sh
13+
secrets:
14+
CLOUDFLARED_DEPLOY_SSH_KEY:
15+
vault: gitlab/cloudflare/tun/cloudflared/_branch/master/cloudflared_github_ssh/data@kv
16+
file: false
17+
cache: {}

.ci/scripts/github-push.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
set -e -o pipefail
3+
4+
BRANCH="master"
5+
TMP_PATH="$PWD/tmp"
6+
PRIVATE_KEY_PATH="$TMP_PATH/github-deploy-key"
7+
PUBLIC_KEY_GITHUB_PATH="$TMP_PATH/github.pub"
8+
9+
mkdir -p $TMP_PATH
10+
11+
# Setup Private Key
12+
echo "$CLOUDFLARED_DEPLOY_SSH_KEY" > $PRIVATE_KEY_PATH
13+
chmod 400 $PRIVATE_KEY_PATH
14+
15+
# Download GitHub Public Key for KnownHostsFile
16+
ssh-keyscan -t ed25519 github.com > $PUBLIC_KEY_GITHUB_PATH
17+
18+
# Setup git ssh command with the right configurations
19+
export GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=$PUBLIC_KEY_GITHUB_PATH -o IdentitiesOnly=yes -i $PRIVATE_KEY_PATH"
20+
21+
# Add GitHub as a new remote
22+
git remote add github [email protected]:cloudflare/cloudflared.git || true
23+
24+
# GitLab doesn't pull branch references, instead it creates a new one on each pipeline.
25+
# Therefore, we need to manually fetch the reference to then push it to GitHub.
26+
git fetch origin $BRANCH:$BRANCH
27+
git push -u github $BRANCH
28+
29+
if TAG="$(git describe --tags --exact-match 2>/dev/null)"; then
30+
git push -u github "$TAG"
31+
fi

.gitlab-ci.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@ default:
77
VAULT_ID_TOKEN:
88
aud: https://vault.cfdata.org
99

10-
stages: [pre-build, build, validate, test, package, release]
10+
stages: [sync, pre-build, build, validate, test, package, release]
1111

1212
include:
1313
#####################################################
1414
########## Import Commons Configurations ############
1515
#####################################################
1616
- local: .ci/commons.gitlab-ci.yml
1717

18+
#####################################################
19+
########### Sync Repository with Github #############
20+
#####################################################
21+
- local: .ci/github.gitlab-ci.yml
22+
1823
#####################################################
1924
############# Build or Fetch CI Image ###############
2025
#####################################################

0 commit comments

Comments
 (0)