Don't spam pull requests with coverage comments. (#296) #14
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Gather 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 Spec | |
run: |- | |
mkdir -p ./build | |
npm install | |
npm run merge -- --source ./spec --output ./build/opensearch-openapi.yaml | |
- 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 > ./build/local-openapi.json | |
docker run --rm --mount type=bind,source=./build,target=/build openapitools/openapi-diff:latest /build/opensearch-openapi.yaml /build/local-openapi.json --json /build/diff.json | |
- name: Show Diff | |
run: | | |
echo "-------- Missing APIs" | |
jq -r '.newEndpoints | group_by(.pathUrl)[] | "\(.[0].pathUrl): \([.[].method])"' build/diff.json | |
echo "-------- Legacy APIs" | |
jq -r '.missingEndpoints | group_by(.pathUrl)[] | "\(.[0].pathUrl): \([.[].method])"' build/diff.json | |
- name: Gather Coverage | |
id: coverage | |
shell: bash | |
run: | | |
current=`docker run --rm -i mikefarah/yq:latest -r '.paths | keys | length' < build/opensearch-openapi.yaml` | |
total=`jq -r '.paths | keys | length' build/local-openapi.json` | |
percent=$((current * 100 / total)) | |
echo "API specs implemented for $current/$total ($percent%) APIs." | |
cat >>"coverage-api.json" <<EOL | |
{ | |
"pull_request":${{ github.event.number }}, | |
"sha":"${{ github.sha }}", | |
"current":$current, | |
"total":$total, | |
"percent":$percent | |
} | |
EOL | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: coverage-api | |
path: coverage-api.json |