-
Notifications
You must be signed in to change notification settings - Fork 0
167 lines (144 loc) · 5.87 KB
/
Copy pathsync-shared-docs.yml
File metadata and controls
167 lines (144 loc) · 5.87 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# Cross-Repository Documentation Sync Workflow
#
# This workflow syncs the docs/shared/ folder across all PurposePath repositories.
# When documentation is updated in any repo, it propagates to all other repos.
#
# The docs/shared/ folder contains:
# - Specifications (backend/frontend API specs)
# - Shared documentation across all repos
#
# Setup Requirements:
# 1. Create a PAT with 'repo' scope that has access to all PurposePath repos
# 2. Add the PAT as a secret named 'DOCS_SYNC_PAT' to all repositories
# 3. Copy this workflow file to all repositories
#
# Synced Repositories:
# - PurposePath_Api (Backend API)
# - PurposePath_Web (User Frontend)
# - PurposePath_AI (Coaching Service)
# - PurposePath_Admin (Admin Frontend)
# - PurposePath_Kpi (KPI Integration)
name: Sync Shared Documentation
on:
push:
branches:
- dev
- main
paths:
- 'docs/shared/**'
# Allow manual trigger for initial sync or troubleshooting
workflow_dispatch:
inputs:
target_branch:
description: 'Branch to sync to (dev or main)'
required: true
default: 'dev'
type: choice
options:
- dev
- main
# Prevent concurrent syncs to avoid race conditions
concurrency:
group: docs-sync-${{ github.ref }}
cancel-in-progress: false
jobs:
sync-docs:
# Skip if this push was from a sync operation (prevents infinite loops)
if: "!contains(github.event.head_commit.message, '[docs-sync]')"
runs-on: ubuntu-latest
env:
# List of repositories to sync to (excluding the source repo)
ALL_REPOS: |
PurposePath_Api
PurposePath_Web
PurposePath_AI
PurposePath_Admin
PurposePath_Kpi
steps:
- name: Checkout source repository
uses: actions/checkout@v4
with:
fetch-depth: 0
path: source
- name: Get current repo name
id: current-repo
run: echo "name=${GITHUB_REPOSITORY#*/}" >> $GITHUB_OUTPUT
- name: Get commit info
id: commit-info
run: |
cd source
echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "message=$(git log -1 --pretty=%s | head -c 50)" >> $GITHUB_OUTPUT
echo "author=$(git log -1 --pretty=%an)" >> $GITHUB_OUTPUT
- name: Sync to other repositories
env:
GH_TOKEN: ${{ secrets.DOCS_SYNC_PAT }}
CURRENT_REPO: ${{ steps.current-repo.outputs.name }}
SOURCE_SHA: ${{ steps.commit-info.outputs.sha }}
SOURCE_MESSAGE: ${{ steps.commit-info.outputs.message }}
SOURCE_AUTHOR: ${{ steps.commit-info.outputs.author }}
SOURCE_BRANCH: ${{ github.event.inputs.target_branch || github.ref_name }}
run: |
# Configure git
git config --global user.name "GitHub Actions (Docs Sync)"
git config --global user.email "actions@github.com"
# Process each repository
echo "$ALL_REPOS" | while read -r repo; do
# Skip empty lines and current repo
[ -z "$repo" ] && continue
[ "$repo" = "$CURRENT_REPO" ] && continue
echo "=========================================="
echo "Syncing to: $repo"
echo "=========================================="
# Clone target repo
TARGET_DIR="target-$repo"
if ! git clone --depth=1 --branch="$SOURCE_BRANCH" \
"https://x-access-token:${GH_TOKEN}@github.com/${{ github.repository_owner }}/${repo}.git" \
"$TARGET_DIR" 2>/dev/null; then
echo "WARNING: Branch $SOURCE_BRANCH does not exist in $repo, skipping"
continue
fi
# Create docs/shared if it doesn't exist
mkdir -p "$TARGET_DIR/docs/shared"
# Sync docs/shared/ if it exists in source
if [ -d "source/docs/shared" ]; then
rsync -av --delete \
--exclude='.git' \
"source/docs/shared/" "$TARGET_DIR/docs/shared/"
fi
# Check for changes
cd "$TARGET_DIR"
if git diff --quiet && git diff --cached --quiet; then
echo "No changes needed for $repo"
cd ..
continue
fi
# Stage and commit changes
git add docs/shared/
git commit -m "docs: sync shared documentation from $CURRENT_REPO [docs-sync]" \
-m "Synced from: $CURRENT_REPO@$SOURCE_SHA" \
-m "Original commit: $SOURCE_MESSAGE" \
-m "Original author: $SOURCE_AUTHOR" \
-m "Branch: $SOURCE_BRANCH" \
-m "[skip ci]"
# Push changes
if git push; then
echo "Successfully synced to $repo"
else
echo "Failed to push to $repo"
fi
cd ..
done
echo "=========================================="
echo "Sync complete!"
echo "=========================================="
- name: Summary
run: |
echo "## Documentation Sync Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Source Repository:** ${{ github.repository }}" >> $GITHUB_STEP_SUMMARY
echo "- **Branch:** ${{ github.event.inputs.target_branch || github.ref_name }}" >> $GITHUB_STEP_SUMMARY
echo "- **Commit:** ${{ steps.commit-info.outputs.sha }}" >> $GITHUB_STEP_SUMMARY
echo "- **Message:** $(echo '${{ steps.commit-info.outputs.message }}' | head -c 50)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Documentation in docs/shared/ has been synced to all PurposePath repositories." >> $GITHUB_STEP_SUMMARY