Skip to content

Commit

Permalink
Commit a Dockerfile, simplify coverage workflow.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <dblock@amazon.com>
  • Loading branch information
dblock committed Mar 5, 2024
1 parent 60f5d32 commit 1bc3e98
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 30 deletions.
41 changes: 11 additions & 30 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on: [push, pull_request]

env:
JAVA_VERSION: 11
OPENSEARCH_VERSION: 2.12.0
OPENSEARCH_INITIAL_ADMIN_PASSWORD: BobgG7YrtsdKf9M

jobs:
Expand All @@ -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."
7 changes: 7 additions & 0 deletions coverage/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions coverage/README.md
Original file line number Diff line number Diff line change
@@ -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).


0 comments on commit 1bc3e98

Please sign in to comment.