From c38be568f4761ecd9a94a796af6cf8c7217b6e5b Mon Sep 17 00:00:00 2001 From: iamvigneshwars Date: Mon, 1 Jul 2024 16:12:28 +0100 Subject: [PATCH] add schema diff as PR comment --- .github/workflows/schema-compose.yaml | 100 +++++++++++++++++--------- schema/placeholder.graphql | 2 +- 2 files changed, 67 insertions(+), 35 deletions(-) diff --git a/.github/workflows/schema-compose.yaml b/.github/workflows/schema-compose.yaml index 083f210..f922418 100644 --- a/.github/workflows/schema-compose.yaml +++ b/.github/workflows/schema-compose.yaml @@ -15,36 +15,8 @@ jobs: curl -sSL https://rover.apollo.dev/nix/v0.23.0-rc.3 | sh echo "$HOME/.rover/bin" >> $GITHUB_PATH - - name: Install graphql inspector - uses: borales/actions-yarn@v5.0.0 - with: - cmd: global add @graphql-inspector/cli graphql - - - name: Checkout source + - name: Checkout Source uses: actions/checkout@v4.1.4 - with: - ref: main - - - name: Compose old Supergraph Schema - run: > - rover supergraph compose - --config supergraph-config.yaml - --elv2-license=accept - > old_supergraph.graphql - - - name: Upload old Schema Artifact - uses: actions/upload-artifact@v4.3.3 - with: - name: old_supergraph.graphql - path: old_supergraph.graphql - - - name: Checkout main branch - uses: actions/checkout@v4.1.4 - - - name: Download old Schema Artifact - uses: actions/download-artifact@v4.1.7 - with: - name: old_supergraph.graphql - name: Compose Supergraph Schema run: > @@ -53,15 +25,12 @@ jobs: --elv2-license=accept > supergraph.graphql - - name: Check composed schema - run: graphql-inspector diff old_supergraph.graphql supergraph.graphql - - - name: Upload Schema Artifact + - name: Upload New Schema Artifact uses: actions/upload-artifact@v4.3.3 with: name: supergraph.graphql path: supergraph.graphql - + publish: # Deduplicate jobs from pull requests and branch pushes within the same repo. if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository @@ -101,3 +70,66 @@ jobs: - name: Publish Chart if: github.event_name == 'push' && github.ref == 'refs/heads/main' run: helm push $(ls supergraph-*.tgz) ${{ env.IMAGE_REPOSITORY }} + + compare_schema: + runs-on: ubuntu-latest + if: ${{ github.event_name == 'pull_request' }} + steps: + - name: Install Rover CLI + run: | + curl -sSL https://rover.apollo.dev/nix/v0.23.0-rc.3 | sh + echo "$HOME/.rover/bin" >> $GITHUB_PATH + + - name: Checkout main branch + uses: actions/checkout@v4.1.4 + with: + ref: main + + - name: Compose old Supergraph Schema + run: > + rover supergraph compose + --config supergraph-config.yaml + --elv2-license=accept + > old_supergraph.graphql + + - name: Upload Old Schema Artifact + uses: actions/upload-artifact@v4.3.3 + with: + name: old_supergraph.graphql + path: old_supergraph.graphql + + - name: Checkout Source + uses: actions/checkout@v4.1.4 + + - name: Download old Schema Artifact + uses: actions/download-artifact@v4.1.7 + with: + name: old_supergraph.graphql + + - name: Compose New Supergraph Schema + run: > + rover supergraph compose + --config supergraph-config.yaml + --elv2-license=accept + > supergraph.graphql + + - name: Generate Diff + continue-on-error: true + run: | + git diff --no-index old_supergraph.graphql supergraph.graphql > diff.md + + - name: Check if Diff is Empty + id: diff-check + run: | + if [ -s diff.md ]; then echo "has_diff=true" >> $GITHUB_ENV; else echo "has_diff=false" >> $GITHUB_ENV; fi + + - name: Format Diff into Markdown + run: | + sed -i '1s/^/```diff\n/; $a```' diff.md + + - name: Comment PR with artefact comparison report + if: env.has_diff == 'true' + uses: JoseThen/comment-pr@v1.2.0 + with: + file_path: diff.md + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/schema/placeholder.graphql b/schema/placeholder.graphql index e22c2bc..5cd7294 100644 --- a/schema/placeholder.graphql +++ b/schema/placeholder.graphql @@ -3,5 +3,5 @@ schema { } type Query { - empty: String + _empty: String }