forked from matrix-org/matrix-spec-proposals
-
Notifications
You must be signed in to change notification settings - Fork 4
191 lines (181 loc) Β· 6.29 KB
/
main.yml
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
name: "Spec"
on:
push:
branches:
- main
tags:
- v*
# don't bother with this workflow if only proposals are changed
paths-ignore:
- proposals
pull_request:
paths-ignore:
- proposals
workflow_dispatch:
jobs:
validate-openapi:
name: "π Validate OpenAPI specifications"
runs-on: ubuntu-latest
steps:
- name: "π₯ Source checkout"
uses: actions/checkout@v2
- name: "β Setup Node"
uses: actions/setup-node@v2
with:
node-version: '14'
- name: "βοΈ npm"
working-directory: "./scripts"
run: |
npm install
- name: "π Run validator"
working-directory: "./scripts"
run: |
node validator.js -s "../data/api/application-service"
node validator.js -s "../data/api/client-server"
node validator.js -s "../data/api/push-gateway"
check-examples:
name: "π Check Event schema examples"
runs-on: ubuntu-latest
container: uhoreg/matrix-doc-build
steps:
- name: "π₯ Source checkout"
uses: actions/checkout@v2
- name: "π Run validator"
run: |
/env/bin/python scripts/check-event-schema-examples.py
calculate-baseurl:
name: "βοΈ Calculate baseURL for later jobs"
runs-on: ubuntu-latest
outputs:
baseURL: "${{ steps.set-baseurl.outputs.baseURL }}"
steps:
# For PRs, set the baseURL to `/`.
# For releases, set the baseURL to `/$tag` (eg: `/v1.2`).
# Otherwise, set it to `/unstable`.
- name: "βοΈ Calculate baseURL"
id: set-baseurl
# Double brackets on the elif to avoid auto-escaping refs/tags/* because we need
# the asterisk matching behaviour, not the literal string.
run: |
if [ "${GITHUB_EVENT_NAME}" == "pull_request" ]; then
echo ::set-output name=baseURL::/
elif [[ "${GITHUB_REF}" == refs/tags/* ]]; then
echo ::set-output name=baseURL::"/${GITHUB_REF/refs\/tags\//}"
else
echo ::set-output name=baseURL::/unstable
fi
build-openapi:
name: "π Build OpenAPI definitions"
runs-on: ubuntu-latest
container: "python:3.9"
needs: [calculate-baseurl]
steps:
- name: "π₯ Source checkout"
uses: actions/checkout@v2
- name: "π¦ Asset creation"
run: |
python3 -m venv env && . env/bin/activate
pip install -r scripts/requirements.txt
# The output path matches the final deployment path at spec.matrix.org
scripts/dump-swagger.py \
--base-url "https://spec.matrix.org${{ needs.calculate-baseurl.outputs.baseURL }}" \
--api application-service \
-o spec/application-service-api/api.json
scripts/dump-swagger.py \
--base-url "https://spec.matrix.org${{ needs.calculate-baseurl.outputs.baseURL }}" \
--api client-server \
-o spec/client-server-api/api.json
scripts/dump-swagger.py \
--base-url "https://spec.matrix.org${{ needs.calculate-baseurl.outputs.baseURL }}" \
--api push-gateway \
-o spec/push-gateway-api/api.json
tar -czf openapi.tar.gz spec
- name: "π€ Artifact upload"
uses: actions/upload-artifact@v2
with:
name: openapi-artifact
path: openapi.tar.gz
build-spec:
name: "π Build the spec"
runs-on: ubuntu-latest
needs: [calculate-baseurl, build-openapi]
steps:
- name: "β Setup Node"
uses: actions/setup-node@v2
with:
node-version: '14'
- name: "β Setup Hugo"
uses: peaceiris/actions-hugo@c03b5dbed22245418539b65eb9a3b1d5fdd9a0a6
with:
hugo-version: '0.85.0'
extended: true
- name: "π₯ Source checkout"
uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: "βοΈ npm"
run: |
npm i
npm run get-proposals
- name: "βοΈ hugo"
run: hugo --baseURL "${{ needs.calculate-baseurl.outputs.baseURL }}" -d "spec"
# We manually unpack the spec OpenAPI definition JSON to the website tree
# to make it available to the world in a canonical place:
# https://spec.matrix.org/latest/client-server-api/api.json
# Works for /unstable/ and /v1.1/ as well.
- name: "π₯ Spec definition download"
uses: actions/download-artifact@v2
with:
name: openapi-artifact
- name: "π Unpack the OpenAPI definitions in the right location"
run: |
tar -xzf openapi.tar.gz
- name: "π¦ Tarball creation"
run: tar -czf spec.tar.gz spec
- name: "π€ Artifact upload"
uses: actions/upload-artifact@v2
with:
name: spec-artifact
path: spec.tar.gz
build-historical-spec:
name: "π Build the historical backup spec"
runs-on: ubuntu-latest
needs: [build-openapi]
if: ${{ startsWith(github.ref, 'refs/tags/') }}
steps:
- name: "β Setup Node"
uses: actions/setup-node@v2
with:
node-version: '14'
- name: "β Setup Hugo"
uses: peaceiris/actions-hugo@c03b5dbed22245418539b65eb9a3b1d5fdd9a0a6
with:
hugo-version: '0.85.0'
extended: true
- name: "π₯ Source checkout"
uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: "βοΈ npm"
run: |
npm i
npm run get-proposals
- name: "βοΈ hugo"
# Create a baseURL like `/v1.2` out of the `v1.2` tag
run: |
echo -e '[params.version]\nstatus="historical"' > historical.toml
hugo --config config.toml,historical.toml --baseURL "/${GITHUB_REF/refs\/tags\//}" -d "spec"
- name: "π₯ Spec definition download"
uses: actions/download-artifact@v2
with:
name: openapi-artifact
- name: "π Unpack the OpenAPI definitions in the right location"
run: |
tar -xzf openapi.tar.gz
- name: "π¦ Tarball creation"
run: tar -czf spec-historical.tar.gz spec
- name: "π€ Artifact upload"
uses: actions/upload-artifact@v2
with:
name: spec-historical-artifact
path: spec-historical.tar.gz