Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

summary - suppress spinner if noColor is true #151

Merged
merged 1 commit into from
Jul 30, 2024

Conversation

jzweifel
Copy link
Contributor

@jzweifel jzweifel commented Jul 26, 2024

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

  • BREAKING Changes: 1 out of 1
  • Removals: 1
  • Breaking Removals: 1
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

  • Total Changes: 14
  • Modifications: 5
  • Additions: 9
Document Element Total Changes Breaking Changes
paths 1 1

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

  • BREAKING Changes: 1 out of 1
  • Additions: 1
  • Breaking Additions: 1
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

  • BREAKING Changes: 3 out of 13
  • Modifications: 3
  • Additions: 10
  • Breaking Additions: 3

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

  • BREAKING Changes: 1 out of 1
  • Removals: 1
  • Breaking Removals: 1
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

  • Total Changes: 14
  • Modifications: 5
  • Additions: 9
Document Element Total Changes Breaking Changes
paths 1 1

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

  • BREAKING Changes: 1 out of 1
  • Additions: 1
  • Breaking Additions: 1
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

  • BREAKING Changes: 3 out of 13
  • Modifications: 3
  • Additions: 10
  • Breaking Additions: 3

ERROR: breaking changes discovered
Error: breaking changes discovered

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.
Copy link
Member

@daveshanley daveshanley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for fixing this!

@daveshanley daveshanley merged commit d2b3d1b into pb33f:main Jul 30, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants