Skip to content

Commit 21b3e2b

Browse files
authoredMar 6, 2024··
Adds API spec coverage report. (#179)
* Added API spec coverage. Signed-off-by: dblock <dblock@amazon.com>
1 parent a39ba07 commit 21b3e2b

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed
 

‎.github/workflows/coverage.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: API Coverage
2+
3+
on: [push, pull_request]
4+
5+
env:
6+
JAVA_VERSION: 11
7+
OPENSEARCH_INITIAL_ADMIN_PASSWORD: BobgG7YrtsdKf9M
8+
9+
jobs:
10+
coverage:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
pull-requests: write
14+
steps:
15+
- name: Checkout Repo
16+
uses: actions/checkout@v2
17+
- name: Build and Run Docker Container
18+
run: |
19+
docker build coverage --tag opensearch-with-api-plugin
20+
docker run -d -p 9200:9200 -p 9600:9600 -e "discovery.type=single-node" -e OPENSEARCH_INITIAL_ADMIN_PASSWORD="$OPENSEARCH_INITIAL_ADMIN_PASSWORD" opensearch-with-api-plugin
21+
sleep 15
22+
- name: Display OpenSearch Info
23+
run: |
24+
curl -ks -u "admin:$OPENSEARCH_INITIAL_ADMIN_PASSWORD" https://localhost:9200/ | jq
25+
- name: Dump and Compare API
26+
run: |
27+
curl -ks -u "admin:$OPENSEARCH_INITIAL_ADMIN_PASSWORD" https://localhost:9200/_plugins/api | jq > OpenSearch.auto.openapi.json
28+
docker run --rm --mount type=bind,source=.,target=/specs openapitools/openapi-diff:latest /specs/OpenSearch.openapi.json /specs/OpenSearch.auto.openapi.json --json /specs/diff.json
29+
- name: Show Diff
30+
run: |
31+
echo "-------- Missing APIs"
32+
jq -r '.newEndpoints | group_by(.pathUrl)[] | "\(.[0].pathUrl): \([.[].method])"' diff.json
33+
echo "-------- Legacy APIs"
34+
jq -r '.missingEndpoints | group_by(.pathUrl)[] | "\(.[0].pathUrl): \([.[].method])"' diff.json
35+
- name: Gather Coverage
36+
id: coverage
37+
shell: bash
38+
run: |
39+
current=`jq -r '.paths | keys | length' OpenSearch.openapi.json`
40+
total=`jq -r '.paths | keys | length' OpenSearch.auto.openapi.json`
41+
percent=$((current * 100 / total))
42+
echo "API specs implemented for $current/$total ($percent%) APIs."

‎coverage/Dockerfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ARG OPENSEARCH_VERSION=2.12.0
2+
FROM opensearchproject/opensearch:${OPENSEARCH_VERSION}
3+
ARG OPENSEARCH_VERSION
4+
RUN /usr/share/opensearch/bin/opensearch-plugin \
5+
install \
6+
--batch \
7+
https://github.com/dblock/opensearch-api/releases/download/v${OPENSEARCH_VERSION}/opensearch-api-${OPENSEARCH_VERSION}.0.zip

‎coverage/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
### API Coverage
2+
3+
Uses the [opensearch-api plugin](https://github.com/dblock/opensearch-api), and [openapi-diff](https://github.com/OpenAPITools/openapi-diff) to show the difference between OpenSearch APIs, and the [OpenAPI spec checked into this repo](../OpenSearch.openapi.json).
4+
5+
API coverage is run on all pull requests via the [coverage workflow](../.github/workflows/coverage.yml).
6+
7+

0 commit comments

Comments
 (0)
Please sign in to comment.