Repository navigation
91 lines (76 loc) · 3.42 KB
/
Copy pathmain.yml
File metadata and controls
91 lines (76 loc) · 3.42 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
89
90
91
name: SyncToReferenceSite
# Copies this repo's published content into reference.groupdocs.com at
# content/sites/groupdocs/conversion/ on `main` — the site's single deploy branch.
#
# The SOURCE is checked out with this job's own GITHUB_TOKEN, so REPO_TOKEN is only ever used
# against the DESTINATION. That is what lets REPO_TOKEN be a fine-grained PAT scoped to the
# single repo groupdocs/reference.groupdocs.com (Contents: RW) — a token that also clones the
# private source would need access in two different orgs, which fine-grained PATs cannot express.
#
# The commit message carries [deploy-qa], so the site deploys it to STAGING only
# (reference2.groupdocs.com). To publish it live, run the PromoteToProduction workflow.
on:
push:
branches: [ main ]
workflow_dispatch:
concurrency:
group: sync-to-reference-site
cancel-in-progress: false
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Check out this repo (source)
uses: actions/checkout@v4
with:
path: src
fetch-depth: 1
- name: Check out the site repo (destination)
uses: actions/checkout@v4
with:
repository: groupdocs/reference.groupdocs.com
ref: main
path: dest
token: ${{ secrets.REPO_TOKEN }}
fetch-depth: 1
- name: Mirror this tree into the site and push
working-directory: dest
env:
DST_DIR: content/sites/groupdocs/conversion
run: |
set -euo pipefail
# Drop this repo's own plumbing so only published content (english/, static/) is
# mirrored. Deleting it from the SOURCE rather than using `rsync --exclude` is
# deliberate: an --exclude hides a path on both sides, so --delete would *protect*
# any copy already sitting in the site instead of removing it.
cd "$GITHUB_WORKSPACE/src"
rm -rf .git .github LICENSE README.md
cd "$GITHUB_WORKSPACE/dest"
git config user.name "groupdocs-sync-bot"
git config user.email "groupdocs-sync-bot@groupdocs.com"
# The site's `main` absorbs 15 product syncs plus the versions bot, so losing a race
# is routine. The mirror is idempotent, so rebuild it on a fresh tree and retry rather
# than failing — or, worse, reporting success on a push that was rejected.
for attempt in 1 2 3 4 5; do
git fetch --depth 1 origin main
git reset --hard origin/main
# --delete makes this a mirror: anything added to $DST_DIR in the site repo alone is
# destroyed here, which is why canonical content must live in THIS repo.
mkdir -p "$DST_DIR"
rsync -a --delete "$GITHUB_WORKSPACE/src/" "$DST_DIR/"
if [ -z "$(git status --porcelain)" ]; then
echo "no changes to sync"
exit 0
fi
echo "changed paths: $(git status --porcelain | wc -l)"
git add -A
git commit -m "Update file(s) from ${{ github.repository }} [deploy-qa]"
if git push origin HEAD:main; then
echo "synced to groupdocs/reference.groupdocs.com@main"
exit 0
fi
echo "push rejected by a concurrent write — rebuilding (attempt $attempt)"
sleep $(( attempt * 5 ))
done
echo "::error::could not push to reference.groupdocs.com after 5 attempts"
exit 1