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

PR comment for OpenAPI Diff output #227

Draft
wants to merge 24 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 32 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,21 @@ jobs:
uses: mhiew/redoc-lint-github-action@v4
with:
args: 'openapi/task_execution_service.openapi.yaml'
validate:
name: Validate OpenAPI definition
runs-on: ubuntu-latest
steps:
- name: Check out head branch
uses: actions/checkout@v4
- name: Run OpenAPI Validate Action
uses: char0n/swagger-editor-validate@v1
with:
definition-file: openapi/task_execution_service.openapi.yaml
diff:
name: Show OpenAPI differences relative to target branch
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' }}
outputs:
diff_generated: ${{ steps.upload-log.outputs.artifact_id }}
steps:
- name: Check out head branch
uses: actions/checkout@v4
Expand All @@ -27,19 +38,24 @@ jobs:
with:
ref: ${{ github.event.pull_request.base.ref }}
path: base
- name: Run OpenAPI Diff Action
uses: mvegter/[email protected]
- name: Create output directory
run: mkdir -p diff-artifacts/
- name: Run openapi-diff tool
run: |
docker run --rm \
-v $(pwd)/head:/head:ro \
-v $(pwd)/base:/base:ro \
-v $(pwd)/diff-artifacts:/local \
openapitools/openapi-diff:2.0.1 \
/head/openapi/task_execution_service.openapi.yaml \
/base/openapi/task_execution_service.openapi.yaml \
--markdown /local/diff.md
- name: Get PR number
id: get-pr-number
run: |
echo "${{ github.event.pull_request.number }}" > diff-artifacts/pr_number
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
head-spec: head/openapi/task_execution_service.openapi.yaml
base-spec: base/openapi/task_execution_service.openapi.yaml

validate:
name: Validate OpenAPI definition
runs-on: ubuntu-latest
steps:
- name: Check out head branch
uses: actions/checkout@v4
- name: Run OpenAPI Validate Action
uses: char0n/swagger-editor-validate@v1
with:
definition-file: openapi/task_execution_service.openapi.yaml
name: diff-artifacts
path: diff-artifacts/
30 changes: 30 additions & 0 deletions .github/workflows/diff_comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: OpenAPI diff comment
on:
workflow_run:
workflows: ["Lint and validate OpenAPI specs"]
types: [completed]
jobs:
comment:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Download diff
uses: actions/download-artifact@v4
with:
name: diff-artifacts
path: diff-artifacts/
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Create PR comment
uses: actions/github-script@v7
with:
script: |
const diff = require('fs').readFileSync('diff-artifacts/diff.md', 'utf8');
const pr_number = require('fs').readFileSync('diff-artifacts/pr_number', 'utf8').trim();
github.rest.issues.createComment({
issue_number: pr_number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '## OpenAPI diff:\n\n' + diff
})