From 9a6679ec3e71f2d5b7c067b11a1953620ad0094a Mon Sep 17 00:00:00 2001 From: dblock Date: Tue, 5 Mar 2024 11:55:12 -0500 Subject: [PATCH] Added API coverage workflow. Signed-off-by: dblock --- .github/workflows/coverage.yml | 42 ++++++++++++++++++++++++++++++++++ coverage/Dockerfile | 7 ++++++ coverage/README.md | 5 ++++ 3 files changed, 54 insertions(+) create mode 100644 .github/workflows/coverage.yml create mode 100644 coverage/Dockerfile create mode 100644 coverage/README.md diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 000000000..fdedb7f0e --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,42 @@ +name: API Coverage + +on: [push, pull_request] + +env: + JAVA_VERSION: 11 + OPENSEARCH_INITIAL_ADMIN_PASSWORD: BobgG7YrtsdKf9M + +jobs: + coverage: + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + - name: Checkout Repo + uses: actions/checkout@v2 + - name: Build and Run Docker Container + run: | + docker build coverage --tag opensearch-with-api-plugin + 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 + sleep 15 + - name: Display OpenSearch Info + run: | + curl -ks -u "admin:$OPENSEARCH_INITIAL_ADMIN_PASSWORD" https://localhost:9200/ | jq + - name: Dump and Compare API + run: | + curl -ks -u "admin:$OPENSEARCH_INITIAL_ADMIN_PASSWORD" https://localhost:9200/_plugins/api | jq > OpenSearch.auto.openapi.json + docker run --rm --mount type=bind,source=.,target=/specs openapitools/openapi-diff:latest /specs/OpenSearch.openapi.yaml /specs/OpenSearch.auto.openapi.json --json /specs/diff.json + - name: Show Diff + run: | + echo "-------- Missing APIs" + jq -r '.newEndpoints | group_by(.pathUrl)[] | "\(.[0].pathUrl): \([.[].method])"' diff.json + echo "-------- Legacy APIs" + jq -r '.missingEndpoints | group_by(.pathUrl)[] | "\(.[0].pathUrl): \([.[].method])"' diff.json + - name: Gather Coverage + id: coverage + shell: bash + run: | + current=`docker run --rm -i mikefarah/yq:latest -r '.paths | keys | length' < OpenSearch.openapi.yaml` + total=`jq -r '.paths | keys | length' OpenSearch.auto.openapi.json` + percent=$((current * 100 / total)) + echo "API specs implemented for $current/$total ($percent%) APIs." diff --git a/coverage/Dockerfile b/coverage/Dockerfile new file mode 100644 index 000000000..3f34b3b3b --- /dev/null +++ b/coverage/Dockerfile @@ -0,0 +1,7 @@ +ARG OPENSEARCH_VERSION=2.12.0 +FROM opensearchproject/opensearch:${OPENSEARCH_VERSION} +ARG OPENSEARCH_VERSION +RUN /usr/share/opensearch/bin/opensearch-plugin \ + install \ + --batch \ + https://github.com/dblock/opensearch-api/releases/download/v${OPENSEARCH_VERSION}/opensearch-api-${OPENSEARCH_VERSION}.0.zip diff --git a/coverage/README.md b/coverage/README.md new file mode 100644 index 000000000..b561d80f2 --- /dev/null +++ b/coverage/README.md @@ -0,0 +1,5 @@ +### API Coverage + +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 [generated OpenAPI spec](../OpenSearch.openapi.yaml). + +API coverage is run on all pull requests via the [coverage workflow](../.github/workflows/coverage.yml).