From 1bc3e9868eff2b9f0079c6f77c35d51a6f14c1a9 Mon Sep 17 00:00:00 2001 From: dblock Date: Tue, 5 Mar 2024 11:23:04 -0500 Subject: [PATCH] Commit a Dockerfile, simplify coverage workflow. Signed-off-by: dblock --- .github/workflows/coverage.yml | 41 +++++++++------------------------- coverage/Dockerfile | 7 ++++++ coverage/README.md | 7 ++++++ 3 files changed, 25 insertions(+), 30 deletions(-) create mode 100644 coverage/Dockerfile create mode 100644 coverage/README.md diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index dd3459ea..922176c9 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -4,7 +4,6 @@ on: [push, pull_request] env: JAVA_VERSION: 11 - OPENSEARCH_VERSION: 2.12.0 OPENSEARCH_INITIAL_ADMIN_PASSWORD: BobgG7YrtsdKf9M jobs: @@ -15,47 +14,29 @@ jobs: steps: - name: Checkout Repo uses: actions/checkout@v2 - - name: Install API Plugin - run: | - wget https://github.com/dblock/opensearch-api/releases/download/v${{ env.OPENSEARCH_VERSION }}/opensearch-api-${{ env.OPENSEARCH_VERSION }}.0.zip - echo "FROM opensearchproject/opensearch:${{ env.OPENSEARCH_VERSION }}" >> Dockerfile - echo "ADD ./opensearch-api-${{ env.OPENSEARCH_VERSION }}.0.zip /tmp/" >> Dockerfile - echo "RUN /usr/share/opensearch/bin/opensearch-plugin install --batch file:/tmp/opensearch-api-${{ env.OPENSEARCH_VERSION }}.0.zip" >> Dockerfile - cat Dockerfile - name: Build and Run Docker Container run: | - docker build . --tag opensearch-with-api-plugin - docker run -d -p 9200:9200 -p 9600:9600 -e "discovery.type=single-node" -e OPENSEARCH_INITIAL_ADMIN_PASSWORD="${{ env.OPENSEARCH_INITIAL_ADMIN_PASSWORD }}" opensearch-with-api-plugin + 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 -u admin:${{ env.OPENSEARCH_INITIAL_ADMIN_PASSWORD }} --insecure https://localhost:9200/ | jq + curl -ks -u "admin:$OPENSEARCH_INITIAL_ADMIN_PASSWORD" https://localhost:9200/ | jq - name: Dump and Compare API run: | - curl -u admin:${{ env.OPENSEARCH_INITIAL_ADMIN_PASSWORD }} --insecure https://localhost:9200/_plugins/api | jq > OpenSearch.auto.openapi.json - docker run --mount type=bind,source=.,target=/specs openapitools/openapi-diff:latest /specs/OpenSearch.openapi.json /specs/OpenSearch.auto.openapi.json --json /specs/diff.json + 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.json /specs/OpenSearch.auto.openapi.json --json /specs/diff.json - name: Show Diff run: | echo "-------- Missing APIs" - cat diff.json | jq '.newEndpoints | group_by(.pathUrl)[] | .[0].pathUrl + ": " + (map(.method) | tostring)' --raw-output + jq -r '.newEndpoints | group_by(.pathUrl)[] | "\(.[0].pathUrl): \([.[].method])"' diff.json echo "-------- Legacy APIs" - cat diff.json | jq '.missingEndpoints | group_by(.pathUrl)[] | .[0].pathUrl + ": " + (map(.method) | tostring)' --raw-output + jq -r '.missingEndpoints | group_by(.pathUrl)[] | "\(.[0].pathUrl): \([.[].method])"' diff.json - name: Gather Coverage id: coverage shell: bash run: | - echo "current=`cat OpenSearch.openapi.json | jq '.paths | keys[]' | wc -l`" >> $GITHUB_OUTPUT - echo "total=`cat OpenSearch.auto.openapi.json | jq '.paths | keys[]' | wc -l`" >> $GITHUB_OUTPUT - - name: Calculate Percent - id: math - shell: bash - run: | - echo "percent=$((${{ steps.coverage.outputs.current }}*100/${{ steps.coverage.outputs.total }}))" >> $GITHUB_OUTPUT - - name: Report Coverage - shell: bash - run: | - echo "API specs implemented for ${{ steps.coverage.outputs.current }}/${{ steps.coverage.outputs.total }} (${{ steps.math.outputs.percent }}%) APIs." - # - uses: mshick/add-pr-comment@v2 - # with: - # message: | - # API specs implemented for ${{ steps.coverage.outputs.current }}/${{ steps.coverage.outputs.total }} (${{ steps.math.outputs.percent }}%) APIs. + current=`jq -r '.paths | keys | length' OpenSearch.openapi.json` + 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 00000000..3f34b3b3 --- /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 00000000..f88aca97 --- /dev/null +++ b/coverage/README.md @@ -0,0 +1,7 @@ +### 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 [OpenAPI spec checked into this repo](../OpenSearch.openapi.json). + +API coverage is run on all pull requests via the [coverage workflow](../.github/workflows/coverage.yml). + +