Repository navigation
202 lines (173 loc) · 6.64 KB
/
Copy pathci.yml
File metadata and controls
202 lines (173 loc) · 6.64 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
name: CI
on:
push:
branches: [ "master", "main" ]
tags:
- 'v*'
pull_request:
branches: [ "master", "main" ]
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
DATABASE_URL: postgres://user:password@localhost/dummy
jobs:
build_and_test:
name: Build, Test & Checks
runs-on: ubuntu-latest
services:
petstore:
image: swaggerapi/petstore
ports:
- 8080:8080
steps:
- uses: actions/checkout@v7
- name: Set up Rust
run: |
rustup override set stable
rustup component add rustfmt
rustup component add clippy
rustup target add wasm32-unknown-unknown
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libpq-dev make
- name: Check Formatting
run: cargo fmt --all -- --check
- name: Clippy (Linting)
run: cargo clippy --workspace --all-targets --all-features -- -D warnings
- name: Build Workspace
run: cargo build --verbose --workspace --all-targets
- name: Build WASM
run: |
make build_wasm
- name: Run Tests
run: cargo test --verbose --workspace
- name: Download Petstore Specs
run: |
curl --retry 5 --retry-all-errors --retry-delay 2 -fsSL \
https://raw.githubusercontent.com/swagger-api/swagger-petstore/master/src/main/resources/openapi.yaml \
-o petstore_oas3.yaml || \
curl --retry 5 --retry-all-errors --retry-delay 2 -fsSL \
https://raw.githubusercontent.com/SamuelMarks/cdd-openapi-test-harness/master/petstore_oas3.json \
-o petstore_oas3.yaml
# Download a standard swagger 2.0 petstore (preferring local service container or canonical GitHub mirror over flaky petstore.swagger.io)
curl --retry 5 --retry-all-errors --retry-delay 2 -fsSL \
http://localhost:8080/v2/swagger.json \
-o petstore.json || \
curl --retry 5 --retry-all-errors --retry-delay 2 -fsSL \
https://raw.githubusercontent.com/SamuelMarks/cdd-openapi-test-harness/master/petstore.json \
-o petstore.json || \
curl --retry 5 --retry-all-errors --retry-delay 2 -fsSL \
https://petstore.swagger.io/v2/swagger.json \
-o petstore.json
python3 -c '
import json
with open("petstore.json", "r", encoding="utf-8") as f:
data = json.load(f)
assert isinstance(data, dict) and ("swagger" in data or "openapi" in data), "Invalid petstore.json"
' || curl --retry 5 --retry-all-errors --retry-delay 2 -fsSL \
https://raw.githubusercontent.com/SamuelMarks/cdd-openapi-test-harness/master/petstore.json \
-o petstore.json
- name: Test Swagger 2.0 Petstore SDK Generation
run: cargo run -p cdd-cli -- from_openapi to_sdk -i ./petstore.json -o ./target/petstore2
- name: Test OpenAPI 3.2.0 Petstore SDK Generation
run: cargo run -p cdd-cli -- from_openapi to_sdk -i ./petstore_oas3.yaml -o ./target/petstore3
- name: Test Swagger 2.0 Petstore Server & Client
run: python scripts/test_server_and_client.py ./petstore.json ./target/server_petstore2 ./target/client_petstore2
- name: Test OpenAPI 3.2.0 Petstore Server & Client
run: python scripts/test_server_and_client.py ./petstore_oas3.yaml ./target/server_petstore3 ./target/client_petstore3
- name: Check Documentation Coverage
run: |
rustup toolchain install nightly
RUSTDOCFLAGS="-Z unstable-options --show-coverage" cargo +nightly doc --workspace --no-deps
- name: Install cargo-tarpaulin
run: cargo install cargo-tarpaulin
- name: Run Test Coverage
env:
RUSTFLAGS: "--cfg coverage"
run: cargo tarpaulin --workspace --out Xml --fail-under 100 -- --test-threads=1
build-native:
needs: build_and_test
if: github.event_name == 'push'
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact_name: cdd-rust-x86_64-unknown-linux-gnu
- os: macos-latest
target: aarch64-apple-darwin
artifact_name: cdd-rust-aarch64-apple-darwin
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v7
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Build Native
run: |
cargo build --release -p cdd-cli --target ${{ matrix.target }}
cp target/${{ matrix.target }}/release/cdd-rust ${{ matrix.artifact_name }} || cp target/release/cdd-rust ${{ matrix.artifact_name }}
- name: Upload Artifact
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.artifact_name }}
path: ${{ matrix.artifact_name }}
build-wasm:
needs: build_and_test
if: github.event_name == 'push'
runs-on: ubuntu-latest
services:
petstore:
image: swaggerapi/petstore
ports:
- 8080:8080
steps:
- uses: actions/checkout@v7
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-wasip1
- name: Install binaryen
run: |
wget -qO- https://github.com/WebAssembly/binaryen/releases/download/version_129/binaryen-version_129-x86_64-linux.tar.gz | tar xvz
echo "$PWD/binaryen-version_129/bin" >> $GITHUB_PATH
- name: Build WASM
run: |
make build_wasm
cp target/wasm32-wasip1/release/*.wasm cdd-rust.wasm || true
# Optimize if present
if [ -f "cdd-rust.wasm" ]; then
wasm-opt -O3 cdd-rust.wasm -o cdd-rust.wasm || true
fi
- name: Upload Artifact
uses: actions/upload-artifact@v7
with:
name: cdd-rust.wasm
path: cdd-rust.wasm
release:
needs: [build-native, build-wasm]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
services:
petstore:
image: swaggerapi/petstore
ports:
- 8080:8080
steps:
- uses: actions/checkout@v7
- name: Download Artifacts
uses: actions/download-artifact@v8
with:
path: artifacts
merge-multiple: true
- name: Create Versioned Release
uses: ncipollo/release-action@v1
with:
tag: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
artifacts: "artifacts/*"
generateReleaseNotes: true
makeLatest: true