-
-
Notifications
You must be signed in to change notification settings - Fork 30
68 lines (57 loc) · 2.25 KB
/
sync-docs.yml
File metadata and controls
68 lines (57 loc) · 2.25 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
66
67
68
name: Sync Docs to GitLab
on:
push:
branches: [main]
paths:
- 'docs/**'
- '.github/workflows/sync-docs.yml'
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup SSH for GitLab
run: |
mkdir -p ~/.ssh
echo "${{ secrets.GITLAB_SSH_KEY }}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -t ed25519 gitlab.com >> ~/.ssh/known_hosts
- name: Sync docs/ to GitLab
run: |
WORK=$(mktemp -d)
git clone git@gitlab.com:quant-flow/pilot-docs.git "$WORK"
# Preserve GitLab-only infrastructure files (Dockerfile may have
# GitLab-specific changes like apk add nodejs)
BACKUP=$(mktemp -d)
[ -d "$WORK/docker" ] && cp -a "$WORK/docker" "$BACKUP/docker"
# Remove old content (except .git), copy fresh docs
find "$WORK" -mindepth 1 -maxdepth 1 ! -name '.git' -exec rm -rf {} +
cp -a docs/. "$WORK"/
# Remove dirs that should never be synced to GitLab
rm -rf "$WORK/.next" "$WORK/node_modules" "$WORK/.idea" "$WORK/~"
# Restore GitLab-only infrastructure files
[ -d "$BACKUP/docker" ] && rm -rf "$WORK/docker" && cp -a "$BACKUP/docker" "$WORK/docker"
cd "$WORK"
git config user.name "Pilot CI"
git config user.email "ci@quantflow.studio"
git add -A
# Push content if there are changes
if git diff --cached --quiet; then
echo "No changes to sync"
else
git commit -m "sync: docs from pilot@${GITHUB_SHA::7}"
git push origin main
fi
# Always trigger GitLab deploy via unique prod tag
# GitLab ignores re-pushed tags, so each deploy needs a unique tag name
VERSION=$(git -C "$GITHUB_WORKSPACE" describe --tags --abbrev=0 2>/dev/null | sed 's/^v//')
if [ -n "$VERSION" ]; then
BUILD_NUM=$(date +%Y%m%d%H%M%S)
DEPLOY_TAG="prod-${VERSION}-${BUILD_NUM}"
git tag "$DEPLOY_TAG"
git push origin "$DEPLOY_TAG"
echo "Tagged ${DEPLOY_TAG} to trigger deploy"
fi