-
Notifications
You must be signed in to change notification settings - Fork 18
219 lines (193 loc) · 7.37 KB
/
Copy pathpublish-spec.yml
File metadata and controls
219 lines (193 loc) · 7.37 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
name: Publish Specification
on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
- closed
paths:
- .github/workflows/publish-spec.yml
- pyproject.toml
- uv.lock
- specification/ai-catalog.md
- specification/respec-config.json
- tools/build_spec.py
- tools/build_spec_preview.py
- tools/update_gh_pages.py
push:
branches:
- main
paths:
- .github/workflows/publish-spec.yml
- pyproject.toml
- uv.lock
- specification/ai-catalog.md
- specification/respec-config.json
- tools/build_spec.py
- tools/build_spec_preview.py
- tools/update_gh_pages.py
workflow_dispatch:
permissions:
contents: read
concurrency:
group: spec-pages-${{ github.event_name }}-${{ github.event.pull_request.number || github.ref_name }}
cancel-in-progress: true
jobs:
build:
if: github.event_name != 'pull_request' || github.event.action != 'closed'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Check out repository
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Set up uv
uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6
with:
enable-cache: true
cache-dependency-glob: uv.lock
- name: Build specification site
run: |
uv run --python 3.12 --locked python tools/build_spec.py specification/ai-catalog.md dist/index.html --config specification/respec-config.json
publish-root:
if: |
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
(github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main')
needs: build
runs-on: ubuntu-latest
concurrency:
group: gh-pages-write
cancel-in-progress: false
permissions:
contents: write
steps:
- name: Check out repository
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Set up uv
uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6
with:
enable-cache: true
cache-dependency-glob: uv.lock
- name: Build canonical specification site
run: |
uv run --python 3.12 --locked python tools/build_spec.py specification/ai-catalog.md .site/root/index.html --config specification/respec-config.json
- name: Publish canonical site to gh-pages
run: |
python3 tools/update_gh_pages.py root \
--source-dir .site/root \
--cname ai-catalog.io \
--remote-url "https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}.git" \
--commit-message "Publish specification site from main"
publish-pr-preview:
if: |
github.event_name == 'pull_request' &&
github.event.action != 'closed' &&
github.event.pull_request.head.repo.full_name == github.repository
needs: build
runs-on: ubuntu-latest
concurrency:
group: gh-pages-write
cancel-in-progress: false
permissions:
contents: write
issues: write
pull-requests: write
steps:
- name: Check out pull request merge ref
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Set up uv
uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6
with:
enable-cache: true
cache-dependency-glob: uv.lock
- name: Fetch base and head history
env:
BASE_REF: ${{ github.event.pull_request.base.ref }}
HEAD_REF: ${{ github.event.pull_request.head.ref }}
run: |
git fetch --no-tags origin "$BASE_REF" "$HEAD_REF"
- name: Resolve preview revisions
id: preview-revisions
env:
BASE_REF: ${{ github.event.pull_request.base.ref }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
base_sha=$(git rev-parse "origin/${BASE_REF}")
if ! git cat-file -e "${HEAD_SHA}^{commit}"; then
git fetch --no-tags origin "${HEAD_SHA}"
fi
echo "base_sha=${base_sha}" >> "$GITHUB_OUTPUT"
echo "head_sha=${HEAD_SHA}" >> "$GITHUB_OUTPUT"
- name: Build rendered PR preview site
run: |
uv run --python 3.12 --locked python tools/build_spec_preview.py \
--base-sha "${{ steps.preview-revisions.outputs.base_sha }}" \
--head-sha "${{ steps.preview-revisions.outputs.head_sha }}" \
--base-branch "${{ github.event.pull_request.base.ref }}" \
--head-branch "${{ github.event.pull_request.head.ref }}" \
--pr-number "${{ github.event.pull_request.number }}" \
--output-dir ".site/pr/${{ github.event.pull_request.number }}"
- name: Publish PR preview to gh-pages
run: |
python3 tools/update_gh_pages.py preview \
--source-dir ".site/pr/${{ github.event.pull_request.number }}" \
--pr-number "${{ github.event.pull_request.number }}" \
--remote-url "https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}.git" \
--commit-message "Publish specification preview for PR #${{ github.event.pull_request.number }}"
- name: Comment preview URL on pull request
env:
GH_TOKEN: ${{ github.token }}
PREVIEW_URL: https://ai-catalog.io/pr/${{ github.event.pull_request.number }}/
run: |
marker='<!-- ai-catalog-preview-url -->'
body=$(cat <<EOF
${marker}
Preview: ${PREVIEW_URL}
This comment is updated automatically while the pull request preview is available.
EOF
)
gh pr comment "${{ github.event.pull_request.number }}" \
--repo "${{ github.repository }}" \
--edit-last \
--create-if-none \
--body "$body"
cleanup-pr-preview:
if: |
github.event_name == 'pull_request' &&
github.event.action == 'closed' &&
github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
concurrency:
group: gh-pages-write
cancel-in-progress: false
permissions:
contents: write
issues: write
pull-requests: write
steps:
- name: Check out repository
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Remove PR preview from gh-pages
run: |
python3 tools/update_gh_pages.py cleanup \
--pr-number "${{ github.event.pull_request.number }}" \
--remote-url "https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}.git" \
--commit-message "Remove specification preview for PR #${{ github.event.pull_request.number }}"
- name: Update preview comment on pull request close
env:
GH_TOKEN: ${{ github.token }}
run: |
marker='<!-- ai-catalog-preview-url -->'
body=$(cat <<EOF
${marker}
Preview unavailable.
The pull request preview was removed because this pull request is closed.
EOF
)
gh pr comment "${{ github.event.pull_request.number }}" \
--repo "${{ github.repository }}" \
--edit-last \
--create-if-none \
--body "$body"