-
Notifications
You must be signed in to change notification settings - Fork 0
210 lines (174 loc) · 7.1 KB
/
sync-docs.yml
File metadata and controls
210 lines (174 loc) · 7.1 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
name: Sync Documentation
on:
repository_dispatch:
types:
- sync-api-docs
- sync-dataset-docs
- sync-governance-docs
workflow_dispatch:
inputs:
source:
description: "Source repository to sync from"
required: true
type: choice
options:
- all
- api
- dataset
- governance
- ui
ref:
description: "Git ref (branch/tag/commit) to sync from"
required: false
default: "main"
type: string
permissions:
contents: write
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- id: set-matrix
run: |
# Initialize variables
INPUT_SOURCE=""
INPUT_REF=""
SHA_VAL=""
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
INPUT_SOURCE="${{ inputs.source }}"
INPUT_REF="${{ inputs.ref }}"
else
# For repository_dispatch, source comes from payload
INPUT_SOURCE="${{ github.event.client_payload.source }}"
INPUT_REF="${{ github.event.client_payload.ref }}"
SHA_VAL="${{ github.event.client_payload.sha }}"
fi
if [ "$INPUT_SOURCE" == "all" ]; then
# Create matrix for all repositories
# Using minified JSON for matrix output
echo "matrix={\"include\":[{\"source\":\"api\",\"ref\":\"$INPUT_REF\",\"sha\":\"\"},{\"source\":\"dataset\",\"ref\":\"$INPUT_REF\",\"sha\":\"\"},{\"source\":\"governance\",\"ref\":\"$INPUT_REF\",\"sha\":\"\"},{\"source\":\"ui\",\"ref\":\"$INPUT_REF\",\"sha\":\"\"}]}" >> $GITHUB_OUTPUT
else
# Single repository
echo "matrix={\"include\":[{\"source\":\"$INPUT_SOURCE\",\"ref\":\"$INPUT_REF\",\"sha\":\"$SHA_VAL\"}]}" >> $GITHUB_OUTPUT
fi
sync-docs:
needs: prepare
name: Sync ${{ matrix.source }}
runs-on: ubuntu-latest
strategy:
max-parallel: 1
matrix: ${{ fromJson(needs.prepare.outputs.matrix) }}
fail-fast: false
permissions:
contents: write
actions: write
steps:
- name: Set Source Variables
id: source
run: |
SOURCE="${{ matrix.source }}"
REF="${{ matrix.ref }}"
SHA="${{ matrix.sha }}"
echo "source=$SOURCE" >> $GITHUB_OUTPUT
if [ -n "$SHA" ]; then
echo "sha=$SHA" >> $GITHUB_OUTPUT
else
# Calculate SHA from Ref if not provided
REPO_SUFFIX="open-ev-data-$SOURCE"
if [ "$SOURCE" == "governance" ]; then REPO_SUFFIX=".github"; fi
REPO_URL="https://github.com/open-ev-data/$REPO_SUFFIX"
echo "Resolving SHA for $REPO_URL at $REF..."
CALCULATED_SHA=$(git ls-remote $REPO_URL $REF | cut -f1)
if [ -z "$CALCULATED_SHA" ]; then
echo "Error: Could not resolve SHA for $REF"
exit 1
fi
echo "sha=$CALCULATED_SHA" >> $GITHUB_OUTPUT
fi
- name: Generate GitHub App token
id: generate_token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.PRIVATE_KEY }}
- name: Checkout Website Repository
uses: actions/checkout@v4
with:
token: ${{ steps.generate_token.outputs.token }}
fetch-depth: 0
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Checkout Source Repository
uses: actions/checkout@v4
with:
repository: ${{ steps.source.outputs.source == 'governance' && 'open-ev-data/.github' || format('open-ev-data/open-ev-data-{0}', steps.source.outputs.source) }}
ref: ${{ steps.source.outputs.sha }}
path: source-repo
token: ${{ steps.generate_token.outputs.token }}
- name: Sync API Documentation
if: steps.source.outputs.source == 'api'
run: |
mkdir -p docs/api
cp source-repo/README.md docs/api/index.md
cp source-repo/docs/GET_STARTED.md docs/api/
cp source-repo/docs/ARCHITECTURE.md docs/api/
cp source-repo/docs/TESTING.md docs/api/
cp source-repo/docs/RUST_GUIDELINES.md docs/api/
cp source-repo/docs/RELEASE_STRATEGY.md docs/api/
cp source-repo/docs/API_ERRORS.md docs/api/
cp source-repo/docs/PROBLEM_DETAILS_RFC_7807.md docs/api/
cp source-repo/docs/CRATE_EV_CORE.md docs/api/
cp source-repo/docs/CRATE_EV_ETL.md docs/api/
cp source-repo/docs/CRATE_EV_SERVER.md docs/api/
cp source-repo/CHANGELOG.md docs/changelog-api.md
- name: Sync Dataset Documentation
if: steps.source.outputs.source == 'dataset'
run: |
mkdir -p docs/dataset
cp source-repo/README.md docs/dataset/index.md
cp source-repo/docs/HOW_TO_CONSUME.md docs/dataset/
cp source-repo/docs/ARCHITECTURE.md docs/dataset/
cp source-repo/docs/SCHEMA.md docs/dataset/
cp source-repo/docs/RELEASE_PROCESS.md docs/dataset/
cp source-repo/docs/CONTRIBUTING_VEHICLES.md docs/dataset/
cp source-repo/CHANGELOG.md docs/changelog-dataset.md
- name: Sync Governance Documentation
if: steps.source.outputs.source == 'governance'
run: |
mkdir -p docs/governance
cp source-repo/README.md docs/governance/index.md
cp source-repo/GET_STARTED.md docs/governance/GET_STARTED.md
cp source-repo/CONTRIBUTING.md docs/governance/CONTRIBUTING.md
cp source-repo/CODE_OF_CONDUCT.md docs/governance/CODE_OF_CONDUCT.md
- name: Sync UI Documentation
if: steps.source.outputs.source == 'ui'
run: |
mkdir -p docs/ui
# Use GET_STARTED as index for UI section
cp source-repo/docs/GET_STARTED.md docs/ui/index.md
cp source-repo/docs/ARCHITECTURE.md docs/ui/
cp source-repo/docs/DESIGN_SYSTEM.md docs/ui/
cp source-repo/docs/PAGE_LAYOUTS.md docs/ui/
cp source-repo/docs/RESPONSIVE_STRATEGY.md docs/ui/
cp source-repo/docs/SEO_STRATEGY.md docs/ui/
cp source-repo/docs/UI_COMPONENTS.md docs/ui/
cp source-repo/CHANGELOG.md docs/changelog-ui.md
- name: Commit and Push Changes
run: |
git add docs/
if git diff --staged --quiet; then
echo "No documentation changes detected"
exit 0
fi
SOURCE="${{ steps.source.outputs.source }}"
SHA="${{ steps.source.outputs.sha }}"
# Commit changes locally first
git commit -m "docs($SOURCE): sync documentation from $SOURCE@$SHA"
# Pull and rebase on top of latest main (handles matrix race conditions)
git pull --rebase origin main
git push origin main
echo "✅ Documentation synchronized from $SOURCE"