-
-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (91 loc) · 3.58 KB
/
Copy pathsync-docs.yml
File metadata and controls
100 lines (91 loc) · 3.58 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
92
93
94
95
96
97
98
99
100
name: Synchronize Documentation
on:
push:
branches:
- main
paths:
- '**/docs/**'
workflow_dispatch:
jobs:
sync-to-portal:
name: Sync docs to Central Portal
runs-on: ubuntu-latest
steps:
- name: Create GitHub App Token
uses: actions/create-github-app-token@v3
id: app-token
with:
client-id: ${{ secrets.BOT_CLIENT_ID }}
private-key: ${{ secrets.BOT_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: ${{ github.repository }},gp-docs
- name: Checkout gp-engine repository
uses: actions/checkout@v6
with:
path: gp-engine
submodules: recursive
fetch-depth: 0
- name: Checkout gp-docs
uses: actions/checkout@v6
with:
repository: GraphicalPlayground/gp-docs
token: ${{ steps.app-token.outputs.token }}
path: gp-docs
- name: Sync Documentation
run: |
# remove old docs
rm -rf gp-docs/docs/gp-engine
mkdir -p gp-docs/docs/gp-engine
cd gp-engine
mkdir -p 'docs/Programming With C++/GP Build Tool'
if [ -d "cmake/gp-build-tool/docs" ]; then
cp -r cmake/gp-build-tool/docs/* 'docs/Programming With C++/GP Build Tool/'
fi
find . -type f -path "*/docs/*" -not -path "./thirdparty/*" -not -path "./cmake/*" -print0 | while IFS= read -r -d '' file; do
rel_path="${file#./}"
dest_path=$(echo "$rel_path" | sed -e 's|^docs/||' -e 's|/docs/|/|g')
target_file="../gp-docs/docs/gp-engine/$dest_path"
mkdir -p "$(dirname "$target_file")"
cp "$file" "$target_file"
done
- name: Collect doc authors from this push
id: collect-authors
run: |
cd gp-engine
CO_AUTHORS=""
BEFORE="${{ github.event.before }}"
AFTER="${{ github.sha }}"
ZERO_SHA="0000000000000000000000000000000000000000"
if [ "${{ github.event_name }}" = "push" ] && [ "$BEFORE" != "$ZERO_SHA" ]; then
CO_AUTHORS=$(git log --pretty=format:"%an <%ae>" "${BEFORE}..${AFTER}" -- '**/docs/**' \
| sort -u \
| sed 's/^/Co-authored-by: /')
fi
DELIMITER=$(openssl rand -hex 16)
echo "co_authors<<${DELIMITER}" >> "$GITHUB_OUTPUT"
echo "${CO_AUTHORS}" >> "$GITHUB_OUTPUT"
echo "${DELIMITER}" >> "$GITHUB_OUTPUT"
- name: Get GitHub App User ID
id: get-user-id
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
- name: Commit and Push Changes to gp-docs
env:
CO_AUTHORS: ${{ steps.collect-authors.outputs.co_authors }}
run: |
cd gp-docs
git config user.name "${{ steps.app-token.outputs.app-slug }}[bot]"
git config user.email "${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com"
git add .
if ! git diff-index --quiet HEAD; then
if [ -n "$CO_AUTHORS" ]; then
git commit -m "sync(gp-engine): synchronize documentation from gp-engine" -m "$CO_AUTHORS"
else
git commit -m "sync(gp-engine): synchronize documentation from gp-engine"
fi
git push -u origin main
echo "Successfully pushed new docs to gp-docs!"
else
echo "No changes to commit"
fi