Repository navigation
88 lines (85 loc) · 3 KB
/
Copy pathdocs.yaml
File metadata and controls
88 lines (85 loc) · 3 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# .github/workflows/docs.yaml
name: Sync Docs to Repo VSAGIO
on:
push:
branches: [main]
paths: ['docs/**']
workflow_dispatch:
permissions:
contents: read
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo VSAG
uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
path: repo-vsag
persist-credentials: false
- name: Checkout Repo VSAGIO
uses: actions/checkout@v4
with:
repository: vsag-io/vsag-io.github.io
token: ${{ secrets.GH_PAT }}
ref: main
path: repo-vsagio
- name: Prepare shared sync branch
working-directory: repo-vsagio
shell: bash
run: |
set -euo pipefail
git fetch --no-tags origin main
expected_remote_oid="$(git ls-remote origin refs/heads/sync | awk 'NR == 1 { print $1 }')"
if [[ -n "$expected_remote_oid" ]]; then
[[ "$expected_remote_oid" =~ ^[0-9a-f]{40}$ ]]
git fetch --no-tags origin \
"refs/heads/sync:refs/remotes/origin/sync"
else
expected_remote_oid=0000000000000000000000000000000000000000
fi
git checkout -B sync origin/main
echo "EXPECTED_REMOTE_OID=$expected_remote_oid" >> "$GITHUB_ENV"
- name: Sync docs books (zh, en)
run: |
set -euo pipefail
mkdir -p repo-vsagio/docs
rsync -av --delete repo-vsag/docs/docs/zh/ repo-vsagio/docs/zh/
rsync -av --delete repo-vsag/docs/docs/en/ repo-vsagio/docs/en/
- name: Sync blogs books (zh, en)
run: |
set -euo pipefail
mkdir -p repo-vsagio/blogs
rsync -av --delete repo-vsag/docs/blog/zh/ repo-vsagio/blogs/zh/
rsync -av --delete repo-vsag/docs/blog/en/ repo-vsagio/blogs/en/
- name: Sync landing page (site root)
run: |
set -euo pipefail
mkdir -p repo-vsagio/landing
rsync -av --delete repo-vsag/docs/landing/ repo-vsagio/landing/
- name: Commit and publish shared snapshot
working-directory: repo-vsagio
shell: bash
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A docs blogs landing
if [[ -n "$(git status --porcelain)" ]]; then
git commit -m "docs: sync from vsag@${GITHUB_SHA}"
fi
set +e
push_output="$(git push \
--force-with-lease="refs/heads/sync:${EXPECTED_REMOTE_OID}" \
origin sync 2>&1)"
push_status=$?
set -e
if [[ "$push_status" -eq 0 ]]; then
exit 0
fi
printf '%s\n' "$push_output" >&2
if grep -Fq 'stale info' <<< "$push_output"; then
echo "Warning: shared sync branch changed during this run; keeping the other snapshot." >&2
exit 0
fi
exit "$push_status"