pb33f / openapi-changes

The world's sexiest OpenAPI breaking changes detector. Discover what changed between two OpenAPI specs, or a single spec over time. Supports OpenAPI 3.1, 3.0 and Swagger
https://pb33f.io/openapi-changes/
Other
180 stars 16 forks source link

summary - suppress spinner if noColor is true #151

Closed jzweifel closed 2 months ago

jzweifel commented 2 months ago

This behavior is consistent with how html-report behaves, and is desireable for CI environments such as GitHub Actions where the spinner output won't look near as pretty.


I'm attempting to embed openapi-changes into a GitHub workflow, so that I can have it error a check on a PR if a PR were to introduce any breaking changes. I'm using the summary markdown output feature, in an action a little like this:

name: 'Check for Breaking OAS Changes'
description: 'Compares the version of a spec against what is currently in main.'
inputs:
  spec-to-scan: # local path to a spec to check for changes
    description: 'Repository-local path to a spec to check for breaking changes.'
    required: true
runs:
  using: 'composite'
  steps:
    # Check out the repository
    - uses: actions/checkout@v3

    - name: Install pb33f/openapi-changes
      uses: ./.github/actions/install-pb33f-openapi-breaking-changes

    - name: Get all changed oas files
      id: changed-oas-files
      uses: tj-actions/changed-files@v44
      with:
        # Avoid using single or double quotes for multiline patterns
        files: |
            services/**.{yml,yaml}

   name: 'Check for Breaking OAS Changes'
description: 'Compares the version of a spec against what is currently in main.'
inputs:
  spec-to-scan: # local path to a spec to check for changes
    description: 'Repository-local path to a spec to check for breaking changes.'
    required: true
runs:
  using: 'composite'
  steps:
    # Check out the repository
    - uses: actions/checkout@v3

    - name: Install pb33f/openapi-changes
      uses: ./.github/actions/install-pb33f-openapi-breaking-changes

    - name: Get all changed oas files
      id: changed-oas-files
      uses: tj-actions/changed-files@v44
      with:
        # Avoid using single or double quotes for multiline patterns
        files: |
            services/**.{yml,yaml}

    - name: Diff all changed oas files
      shell: bash
      if: steps.changed-oas-files.outputs.any_changed == 'true'
      env:
        ALL_CHANGED_FILES: ${{ steps.changed-oas-files.outputs.all_changed_files }}
      run: |
        set +e
        MARKDOWN_OUTPUT="# Summary of changes"
        SHOULD_FAIL=false
        for file in ${ALL_CHANGED_FILES}; do
          MARKDOWN_OUTPUT+="\n\n"
          MARKDOWN_OUTPUT+="## $file"
          MARKDOWN_OUTPUT+=$(openapi-changes summary --no-logo --no-color --markdown ./ "$file")
          CHANGES_EXIT_CODE=$?
          if [ $CHANGES_EXIT_CODE -ne 0 ]; then SHOULD_FAIL=true; fi;
        done
        EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
        echo "breaking_changes_markdown<<$EOF" >> $GITHUB_OUTPUT
        echo -e "$MARKDOWN_OUTPUT" >> $GITHUB_OUTPUT
        echo "$EOF" >> $GITHUB_OUTPUT
        echo "breaking_changes_detected=$SHOULD_FAIL" >> $GITHUB_OUTPUT
        set -e

I noticed that the output from summary, even with --no-logo --no-color --markdown would include many lines from the spinner, and ultimately caused a few rendering issues within the markdown as well.

Before:


starting work.

Extracting history for 'services/my-service.yml' in repo './

extacted commit '8ce8c30'

extacted commit '639401d'

extacted commit 'a7852bf'

extacted commit '06c5e75'

extacted commit 'cd766d0'

SPEC: 5 commits extracted Extracting 10 bytes extracted from commit '8ce8c30' Extracting 10 bytes extracted from commit '639401d' Extracting 9 bytes extracted from commit 'a7852bf' Extracting 9 bytes extracted from commit '06c5e75' Extracting 9 bytes extracted from commit 'cd766d0' Building original model for commit 06c5e7 Building original model for commit a7852b Building original model for commit 639401 Building original model for commit 8ce8c3

└─┬Paths
  └─┬/health
    └─┬GET
      └──[➖] parameters (31:7)❌ 
SPEC: 5 commits processed and populated Document Element Total Changes Breaking Changes
paths 1 1

Date: 07/25/24 | Commit: chore: remove test param fro my service getHealth

Document Element Total Changes Breaking Changes
info 1 0
paths 7 0
tags 2 0
servers 4 0

Date: 07/23/24 | Commit: chore: add tags and shorten server descriptions

Document Element Total Changes Breaking Changes
paths 1 1

Date: 07/23/24 | Commit: end to end test

Document Element Total Changes Breaking Changes
info 1 0
paths 7 0
servers 2 0
components 3 3

Date: 07/22/24 | Commit: chore: add linting via spectral

SPEC: extracted 5 commits from history

DONE: completed ERROR: breaking changes discovered


After:

└─┬Paths
  └─┬/health
    └─┬GET
      └──[➖] parameters (31:7)❌
Document Element Total Changes Breaking Changes
paths 1 1

Date: 07/25/24 | Commit: chore: remove test param fro app hub getHealth

Document Element Total Changes Breaking Changes
paths 7 0
tags 2 0
servers 4 0
info 1 0

Date: 07/23/24 | Commit: chore: add tags and shorten server descriptions

Document Element Total Changes Breaking Changes
paths 1 1

Date: 07/23/24 | Commit: end to end test

Document Element Total Changes Breaking Changes
info 1 0
paths 7 0
servers 2 0
components 3 3

Date: 07/22/24 | Commit: chore: add linting via spectral

ERROR: breaking changes discovered Error: breaking changes discovered