-
Notifications
You must be signed in to change notification settings - Fork 9
167 lines (155 loc) · 5.9 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
# Copyright (c) 2021 Cisco Systems, Inc. and its affiliates
# All rights reserved.
# Use of this source code is governed by a BSD 3-Clause License
# that can be found in the LICENSE file.
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on pull request events but only for the main branch
pull_request:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# Use addlicense tool to check that all files have a license header
check_license_headers_applied:
name: check_license_headers_applied
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
name: Checkout code
- uses: docker://ghcr.io/google/addlicense
name: Run license header check
with:
args: -check -ignore **/swagger.yaml -ignore **/models.py .
# bundle the spec and upload it to be used in other jobs
bundle_openapi_spec:
name: bundle_openapi_spec
runs-on: ubuntu-latest
container: node:16-alpine
steps:
- uses: actions/checkout@v2
name: Checkout code
- run: npm install -g swagger-cli
name: Install Swagger CLI
- run: mkdir -p tmp/artifacts
name: Create Directory for Artifacts
- run: swagger-cli bundle transmitter_spec/openapi.yaml > tmp/artifacts/bundled.yaml
name: Bundle OpenAPI spec
- uses: actions/upload-artifact@v2
name: Upload Bundled Spec
with:
name: bundled-spec
path: tmp/artifacts/bundled.yaml
# download the bundled spec, generate the swagger server, upload the generated spec
generate_transmitter_server_spec:
name: generate_transmitter_server_spec
needs: bundle_openapi_spec
runs-on: ubuntu-latest
container: swaggerapi/swagger-codegen-cli-v3
steps:
- run: mkdir -p tmp/artifacts
name: Create Directory for Artifacts
- uses: actions/download-artifact@v2
name: Download Bundled Spec
with:
name: bundled-spec
path: tmp/artifacts
- run: java -jar /opt/swagger-codegen-cli/swagger-codegen-cli.jar generate -i tmp/artifacts/bundled.yaml -l python-flask -o tmp/artifacts/transmitter
name: Generate Example Transmitter Server
- uses: actions/upload-artifact@v2
name: Upload Generated Spec
with:
name: generated-spec
path: tmp/artifacts/transmitter/swagger_server/swagger/swagger.yaml
# download the transmitter server spec, then generate and upload the pydantic models
generate_pydantic_models:
name: generate_pydantic_models
needs: generate_transmitter_server_spec
runs-on: ubuntu-latest
container: python:3.9-slim-buster
steps:
- run: mkdir -p tmp/artifacts
name: Create Directory for Artifacts
- uses: actions/download-artifact@v2
name: Download Generated Spec
with:
name: generated-spec
path: tmp/artifacts
- run: pip install datamodel-code-generator
name: Install Datamodel Code Generator
- run: datamodel-codegen --input tmp/artifacts/swagger.yaml --enum-field-as-literal one --use-default --strict-nullable --target-python-version 3.9 --use-schema-description --disable-timestamp > tmp/artifacts/models.py
name: Generate models.py
- uses: actions/upload-artifact@v2
name: Upload models.py
with:
name: models
path: tmp/artifacts/models.py
# ensure examples/transmitter/swagger_server/swagger/swagger.yaml is up to date
check_swagger_yaml_up_to_date:
name: check_swagger_yaml_up_to_date
needs: generate_transmitter_server_spec
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
name: Checkout code
- run: mkdir -p tmp/artifacts
name: Create Directory for Artifacts
- uses: actions/download-artifact@v2
name: Download Generated Spec
with:
name: generated-spec
path: tmp/artifacts
- run: cmp examples/transmitter/swagger_server/swagger/swagger.yaml tmp/artifacts/swagger.yaml
name: Compare to Spec in examples/transmitter
id: cmp
# ensure examples/transmitter/swagger_server/models.py is up to date
check_models_py_up_to_date:
name: check_models_py_up_to_date
needs: generate_pydantic_models
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
name: Checkout code
- run: mkdir -p tmp/artifacts
name: Create Directory for Artifacts
- uses: actions/download-artifact@v2
name: Download models.py
with:
name: models
path: tmp/artifacts
- run: cmp examples/transmitter/swagger_server/models.py tmp/artifacts/models.py
name: Compare to examples/transmitter/models.py
id: cmp
# Validate our OpenAPI spec
validate_open_api_spec:
name: validate_open_api_spec
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
name: Checkout code
- name: Validate OpenAPI definition
id: validate
uses: char0n/[email protected]
with:
definition-file: examples/transmitter/swagger_server/swagger/swagger.yaml
# runs tests on our example transmitter
test_example_transmitter:
name: test_example_transmitter
runs-on: ubuntu-latest
container: python:3.9
steps:
- uses: actions/checkout@v2
name: Checkout code
- run: pip3 install -r requirements.txt
name: Install requirements
working-directory: examples/transmitter
- run: pip3 install -r test-requirements.txt
name: Install test requirements
working-directory: examples/transmitter
- run: python3 -m tox swagger_server/test
name: Run tests
id: tox
working-directory: examples/transmitter