forked from Universal-Commerce-Protocol/ucp
-
Notifications
You must be signed in to change notification settings - Fork 0
238 lines (200 loc) · 7.54 KB
/
docs.yml
File metadata and controls
238 lines (200 loc) · 7.54 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
---
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Docs Build and Deploy
on:
workflow_dispatch:
push:
branches:
- main
- "release/**"
pull_request:
branches:
- main
- "release/**"
paths:
- ".github/workflows/docs.yml"
- "requirements-docs.txt"
- "mkdocs.yml"
- "main.py"
- "hooks.py"
- "docs/**"
- "source/**"
jobs:
lint:
runs-on: ubuntu-latest
# Don't run this workflow if this is a release branch creation event
# (event.before SHA is all zeros)
if: >-
!(github.event_name == 'push' &&
startsWith(github.ref, 'refs/heads/release/') &&
github.event.before == '0000000000000000000000000000000000000000')
steps:
- name: Checkout Code
uses: actions/checkout@v5
with:
fetch-depth: 0
- uses: ./.github/actions/setup-build-env
- name: Lint YAML files
run: uv run yamllint -c .github/linters/.yamllint.yml .
- name: Check for changed files in source
id: source_files_changed
uses: tj-actions/changed-files@v46
with:
files: source/**
- name: Lint source schemas
if: steps.source_files_changed.outputs.any_changed == 'true' || github.event_name == 'workflow_dispatch'
run: ucp-schema lint source/
build_and_verify_main:
needs: lint
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || github.event.pull_request.base.ref == 'main'
permissions:
contents: read
pages: read
steps:
- name: Checkout Code
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Configure Git Credentials
run: |
git config --global user.name github-actions[bot]
git config --global user.email 41898282+github-actions[bot]@users.noreply.github.com
- uses: ./.github/actions/setup-build-env
- uses: ./.github/actions/configure-site-url
- name: Build and Verify Documentation Site (Main/PR)
run: |
bash scripts/build_local.sh --main-only
uv run python scripts/check_links.py local_preview
build_and_verify_release:
needs: lint
runs-on: ubuntu-latest
if: >-
startsWith(github.ref, 'refs/heads/release/') ||
startsWith(github.event.pull_request.base.ref, 'release/')
permissions:
contents: read
pages: read
steps:
- name: Checkout Code
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Configure Git Credentials
run: |
git config --global user.name github-actions[bot]
git config --global user.email 41898282+github-actions[bot]@users.noreply.github.com
- uses: ./.github/actions/setup-build-env
- uses: ./.github/actions/configure-site-url
- name: Build and Verify Specification Docs (Release Branches)
run: |
export DOCS_MODE=spec
uv run mkdocs build --strict
uv run python scripts/check_links.py site
deploy_main:
needs: build_and_verify_main
runs-on: ubuntu-latest
if: contains(fromJson('["push", "workflow_dispatch"]'), github.event_name) && github.ref == 'refs/heads/main'
permissions:
contents: write
pages: read
steps:
- name: Checkout Code
uses: actions/checkout@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Configure Git Credentials
run: |
git config --global user.name github-actions[bot]
git config --global user.email 41898282+github-actions[bot]@users.noreply.github.com
- uses: ./.github/actions/setup-build-env
- uses: ./.github/actions/configure-site-url
- name: Deploy development version from main branch
run: |
export DOCS_MODE=spec
uv run mike deploy --push draft
export DOCS_MODE=root
uv run mkdocs build --strict
# Checkout gh-pages into a separate directory to avoid overwriting the workspace
# and causing GitHub Actions post-run hooks to fail (as they need .github/actions)
git clone --branch gh-pages "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" gh-pages-branch
cd gh-pages-branch
# Remove existing root files except versions and git metadata
git ls-files | grep -vE "^(\.nojekyll|draft|latest|[0-9]{4}-[0-9]{2}-[0-9]{2}|versions\.json|\.git)" | xargs -r rm -f
find . -maxdepth 1 -type d -empty -not -path "./.git*" -delete
# Copy build artifacts to root
cp -r ../site/* .
rm -rf ../site
# Add redirects for all specification files
rm -rf specification
ln -s latest/specification specification
# Commit and push
git add .
git commit -m "Deploy root site from main" --allow-empty
git push origin gh-pages
deploy_release:
needs: build_and_verify_release
runs-on: ubuntu-latest
if: contains(fromJson('["push", "workflow_dispatch"]'), github.event_name) && startsWith(github.ref, 'refs/heads/release/')
permissions:
contents: write
pages: read
steps:
- name: Checkout Code
uses: actions/checkout@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Configure Git Credentials
run: |
git config --global user.name github-actions[bot]
git config --global user.email 41898282+github-actions[bot]@users.noreply.github.com
- uses: ./.github/actions/setup-build-env
- uses: ./.github/actions/configure-site-url
- name: Deploy release version
run: |
export DOCS_MODE=spec
VERSION_NAME=${GITHUB_REF#refs/heads/release/}
git fetch origin "+refs/heads/release/*:refs/remotes/origin/release/*"
LATEST_VERSION=$(git branch -r --list "origin/release/*" | sed 's|origin/release/||' | sort -V | tail -n 1 | tr -d ' ')
if [ "$VERSION_NAME" = "$LATEST_VERSION" ]; then
uv run mike deploy --push --update-aliases "$VERSION_NAME" latest
else
uv run mike deploy --push "$VERSION_NAME"
fi
create_release:
needs: deploy_release
runs-on: ubuntu-latest
if: contains(fromJson('["push", "workflow_dispatch"]'), github.event_name) && startsWith(github.ref, 'refs/heads/release/')
permissions:
contents: write
steps:
- name: Checkout Code
uses: actions/checkout@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Create GitHub Release and Tag
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION_DATE=${GITHUB_REF#refs/heads/release/}
TAG_NAME="v$VERSION_DATE"
gh release create "$TAG_NAME" \
--title "Release $TAG_NAME" \
--generate-notes \
--target "$GITHUB_REF_NAME" \
|| echo "Release $TAG_NAME already exists, skipping creation."