bump-sh / github-action

GitHub action to deploy your API documentation on Bump
https://bump.sh
MIT License
41 stars 9 forks source link

Run `diff` against an uncommited file #496

Open leovinsen opened 3 months ago

leovinsen commented 3 months ago

Hi guys, thanks for the amazing product! I'm in the middle of POCing for my company's documentation needs. Deployment works well, but diff is not fully suited for my use case.

I am not committing the specs file into our repository and instead generate it in our CI workflow. Is it possible to run diff against the actual file inside the Github Action runner, similar to how deployment works?

name: diff OpenAPI
on:
  pull_request:
    branches:
      - development
jobs:
  api-diff:
    if: ${{ github.event_name == 'pull_request' }}
    name: Check API diff on Bump.sh
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3

     - name: Generate OpenAPI specs
        run: // script to generate OpenAPI specs in ./openapi.json

      - name: Comment pull request with API diff
        uses: bump-sh/github-action@v1
        with:
          doc: <doc>
          token: ${{ secrets.BUMPSH_SECRET }}
          file: openapi.json
          command: diff
        env:
          GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
paulRbr commented 3 months ago

Hi @leovinsen,

Thanks for your message!

If I understand correctly your provided action workflow, you would like to compute a diff between an already published documentation on bump.sh (your <doc> documentation slug + BUMPSH_SECRET token) and a generated openapi.json from the CI workflow. Is that correct?

It does sound like a legit use case which should already work with the current version of our GH action. Could you show me the logs of the action run which doesn't work as you expect please?

leovinsen commented 3 months ago

Hi @paulRbr thanks for the quick response!

Yes that's correct, I would like to diff the currently deployed docs against a generated openapi.json inside the CI workflow. Something similar to bump diff openapi.json --doc <doc> --token <token> using Bump CLI.

Here is the logs:

Run bump-sh/github-action@v1
  with:
    doc: <doc>
    token: ***
    file: openapi.json
    command: diff
    fail_on_breaking: false
  env:
    GITHUB_TOKEN: ***
/usr/bin/git fetch origin 2b450d31b2f193542b2b51b39a576e52f5f83d0a 6339eecfb67991bc22a9878ca3802e1406c2c309
From https://github.com/<redacted>
 * branch                2b450d31b2f193542b2b51b39a576e52f5f83d0a -> FETCH_HEAD
 * branch                6339eecfb67991bc22a9878ca3802e1406c2c309 -> FETCH_HEAD
/usr/bin/git merge-base 2b450d31b2f193542b2b51b39a576e52f5f83d0a 6339eecfb67991bc22a9878ca3802e1406c2c309
f1a025be5a33b7b3e4f08706117b37e28ed69ea3
/usr/bin/git --work-tree tmp/ restore -s f1a025be5a33b7b3e4f08706117b37e28ed69ea3 .
/usr/bin/git restore -s 6339eecfb67991bc22a9878ca3802e1406c2c309 .
No diff found, nothing more to do.

I observe that it checks out from 2 branches and then performs comparison on the two openapi.json file found on both branches. To test my theory:

paulRbr commented 3 months ago

Hi @leovinsen,

Sorry for the late reply. I took some time to try this out and I can't seem to reproduce the error with a generated API definition file.

Here's my test on our examples repo: https://github.com/bump-sh/examples/pull/35/files which lead to a correct diff.

Could you try to reproduce on a public repo so I can see both the git repository, the action workflow and the action logs?

Thanks a lot for your help :pray: