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

Use PR diff as base and revision #55

Open
atd opened this issue Jul 24, 2024 · 3 comments
Open

Use PR diff as base and revision #55

atd opened this issue Jul 24, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@atd
Copy link

atd commented Jul 24, 2024

In a setup where you are tracking the oas.yaml in git, you would expect to check the diff in the context of a pull request. This means you automatically set the following:

  • base to the oas.yaml of the branch your pull request is on
  • revision to the oas.yaml of the last commit of your pull request

This is the behavior of other actions like https://github.com/kamilkisiela/graphql-inspector

Any thoughts?

@effoeffi effoeffi added the enhancement New feature or request label Jul 24, 2024
@mminklet
Copy link

Tried to do the same, unfortunately it's a deal breaker. Tried using checkout and supplying the path but it doesn't pick up changes. Tried giving it the blob url but doesn't play nicely with private repos

@mminklet
Copy link

My solution to use the oasdiff library separately rather than this action. Probably not the most efficient code but does the basics that we need for now

    runs-on: ubuntu-latest
    name: Check out and try oasdiff
    steps:
      - name: Set up Go 1.21.6
        uses: actions/setup-go@v5
        with:
          go-version: 1.21.6
          check-latest: true
          cache-dependency-path: backend/go.sum
      - name: code-checkout
        uses: actions/checkout@v2
        with:
          sparse-checkout: api-docs
          ref: ${{ github.base_ref }}
          path: base
      - name: code-checkout
        uses: actions/checkout@v4
        with:
          sparse-checkout: api-docs
          ref: ${{ github.head_ref }}
          path: head

      - name: install oasdiff
        run: |
          go install github.com/tufin/oasdiff@latest
      - name: run oasdiff diff
        run: |
          oasdiff diff ${{ github.workspace }}/base/api-docs/openapi.yaml ${{ github.workspace }}/head/api-docs/openapi.yaml
      - name: run oasdiff changelog
        run: |
          oasdiff breaking ${{ github.workspace }}/base/api-docs/openapi.yaml ${{ github.workspace }}/head/api-docs/openapi.yaml -f githubactions
      - name: run oasdiff breaking changes
        run: |
          oasdiff changelog ${{ github.workspace }}/base/api-docs/openapi.yaml ${{ github.workspace }}/head/api-docs/openapi.yaml -f githubactions

@marachimeno
Copy link

marachimeno commented Oct 30, 2024

It is possible to achieve this behaviour when you check out both the base and head branches in your GH action script.
I have managed to do it as follows:

const checkoutBaseBranch: Step = {
  name: 'Checkout base branch',
  uses: 'actions/checkout@v4',
  with: {
    ref: '${{ github.event.pull_request.base.ref }}',
    path: 'base'
  }
}

const checkoutHeadBranch: Step = {
  name: 'Checkout head branch',
  uses: 'actions/checkout@v4',
  with: {
    ref: '${{ github.event.pull_request.head.ref }}',
    path: 'head'
  }
}

const checkBreakingChanges: Step = {
  name: 'Running OpenAPI Spec diff action',
  uses: 'oasdiff/oasdiff-action/breaking@main',
  with: {
    base: `base/${PATH}`,
    revision: `head/${PATH}`
  }
}

export default new Workflow(CHECK_OAS)
  .on('pull_request', { paths: ... })
  .addJob('check', {
    steps: [
      checkoutBaseBranch,
      checkoutHeadBranch,
      checkBreakingChanges
    ]
  })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants