From 9e9b475be261477e5d1de51499ebb356ba407d74 Mon Sep 17 00:00:00 2001 From: "Daniel (dB.) Doubrovkine" Date: Wed, 27 Nov 2024 16:15:10 -0500 Subject: [PATCH] Split coverage checklist into its own workflow. (#698) Signed-off-by: dblock --- .github/workflows/analyze-pr-changes.yml | 12 ---- .github/workflows/coverage.yml | 73 ++++++++++++++++++++++++ DEVELOPER_GUIDE.md | 7 ++- 3 files changed, 79 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/coverage.yml diff --git a/.github/workflows/analyze-pr-changes.yml b/.github/workflows/analyze-pr-changes.yml index c9f143961..80074cbb6 100644 --- a/.github/workflows/analyze-pr-changes.yml +++ b/.github/workflows/analyze-pr-changes.yml @@ -116,18 +116,6 @@ jobs: $AFTER_COVERAGE \ | tee $COVERAGE_DIFF - - name: Display Coverage Checklist - shell: bash -eo pipefail {0} - run: | - jq -sc ' - (map(.endpoints .uncovered | to_entries | sort_by(.value) | map((.value[] | ascii_upcase) + " " + .key)) | .[] | to_entries | map({path: .value, covered: false})) as $uncovered | - (map(.endpoints .covered | to_entries | sort_by(.value) | map((.value[] | ascii_upcase) + " " + .key)) | .[] | to_entries | map({path: .value, covered: true})) as $covered | - $covered+$uncovered | - sort_by(.path) | - map(if .covered then "- [x] \(.path)" else "- [ ] \(.path)" end) | - .[] - ' $AFTER_COVERAGE | jq -r - - name: Upload Coverage Data id: upload-coverage uses: actions/upload-artifact@v4 diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 000000000..2a1016ceb --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,73 @@ +name: Analyze Spec Coverage + +on: + push: + paths: + - .github/workflows/coverage.yml + - package*.json + - spec/** + - tsconfig.json + pull_request: + paths: + - .github/workflows/coverage.yml + - package*.json + - spec/** + - tsconfig.json + +jobs: + coverage: + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Dump OpenSearch Cluster's API + shell: bash -eo pipefail {0} + run: | + docker build coverage --tag opensearch-with-api-plugin + + docker run \ + --name opensearch \ + --rm -d \ + -p 9200:9200 -p 9600:9600 \ + -e "discovery.type=single-node" \ + -e OPENSEARCH_INITIAL_ADMIN_PASSWORD="$OPENSEARCH_PASSWORD" \ + opensearch-with-api-plugin + + npm ci + + npm run dump-cluster-spec -- --opensearch-insecure --output build/opensearch-cluster.yaml + + docker stop opensearch + env: + OPENSEARCH_PASSWORD: BobgG7YrtsdKf9M + + - name: Build Spec + shell: bash -eo pipefail {0} + run: | + npm ci + npm run merge -- --source ./spec --output build/opensearch-openapi.yaml + + - name: Calculate Coverage + shell: bash -eo pipefail {0} + run: | + npm run coverage:spec -- \ + --cluster build/opensearch-cluster.yaml \ + --specification build/opensearch-openapi.yaml \ + --output build/coverage.yaml + + jq . build/coverage.yaml + + - name: Display Coverage Checklist + shell: bash -eo pipefail {0} + run: | + jq -sc ' + (map(.endpoints .uncovered | to_entries | sort_by(.value) | map((.value[] | ascii_upcase) + " " + .key)) | .[] | to_entries | map({path: .value, covered: false})) as $uncovered | + (map(.endpoints .covered | to_entries | sort_by(.value) | map((.value[] | ascii_upcase) + " " + .key)) | .[] | to_entries | map({path: .value, covered: true})) as $covered | + $covered+$uncovered | + sort_by(.path) | + map(if .covered then "- [x] \(.path)" else "- [ ] \(.path)" end) | + .[] + ' build/coverage.yaml | jq -r diff --git a/DEVELOPER_GUIDE.md b/DEVELOPER_GUIDE.md index 209057325..9709132fc 100644 --- a/DEVELOPER_GUIDE.md +++ b/DEVELOPER_GUIDE.md @@ -21,6 +21,7 @@ - [Tools Linting](#tools-linting) - [Workflows](#workflows) - [Analyze PR Changes](#analyze-pr-changes) + - [Analyze Spec Coverage](#analyze-spec-coverage) - [Build](#build) - [Deploy GitHub Pages](#deploy-github-pages) - [Comment on PR](#comment-on-pr) @@ -355,7 +356,11 @@ npm run lint--fix ### [Analyze PR Changes](.github/workflows/analyze-pr-changes.yml) -This workflow runs on all pull requests to analyze any potential changes to the specification. It uses the [coverage](#coverage) tool and [openapi-changes](https://pb33f.io/openapi-changes/) to calculate coverage metrics and provide a report on the changes when comparing with the commit at which the PR was branched off. In addition, the "Display Coverage Checklist" step will output a list of OpenSearch APIs with a checkbox indicating whether the API exists in the spec that can be directly copy-pasted into the [Add Missing API Specs issue](https://github.com/opensearch-project/opensearch-api-specification/issues/168). +This workflow runs on all pull requests to analyze any potential changes to the specification. It uses the [coverage](#coverage) tool and [openapi-changes](https://pb33f.io/openapi-changes/) to calculate coverage metrics and provide a report on the changes when comparing with the commit at which the PR was branched off. + +### [Analyze Spec Coverage](.github/workflows/coverage.yml) + +This workflow uses the [coverage](#coverage) tool and [openapi-changes](https://pb33f.io/openapi-changes/) to calculate coverage metrics showing the APIs described by the spec vs. registered in OpenSearch. The "Display Coverage Checklist" step will output a list of OpenSearch APIs with a checkbox indicating whether the API exists in the spec that can be directly copy-pasted into the [Add Missing API Specs issue](https://github.com/opensearch-project/opensearch-api-specification/issues/168). ### [Build](.github/workflows/build.yml)