PR comment for OpenAPI Diff output #46
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Lint and validate OpenAPI specs | |
on: | |
- pull_request | |
jobs: | |
lint: | |
name: Lint OpenAPI definition | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out head branch | |
uses: actions/checkout@v4 | |
- name: Run OpenAPI Lint Action | |
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' }} | |
steps: | |
- name: Check out head branch | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.ref }} | |
path: head | |
- name: Check out base branch | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.base.ref }} | |
path: base | |
- name: Run OpenAPI Diff Action | |
id: openapi_diff | |
continue-on-error: true | |
uses: mvegter/[email protected] | |
with: | |
head-spec: head/openapi/task_execution_service.openapi.yaml | |
base-spec: base/openapi/task_execution_service.openapi.yaml | |
- name: Store log | |
id: check_log | |
run: | | |
if [ -n "${{ steps.openapi_diff.outputs.errors }}" ]; then | |
echo "::set-output name=log_empty::false" | |
echo ${{ steps.openapi_diff.outputs.errors }} > openapi_diff.json | |
fi | |
- name: Upload log | |
if: steps.check_log.outputs.log_empty == 'false' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: openapi-diff-log | |
path: openapi_diff.json | |
diff-comment: | |
name: Create PR comment with OpenAPI diff log (if not empty) | |
runs-on: ubuntu-latest | |
needs: diff | |
if: needs.diff.outputs.log_empty == 'false' | |
permissions: | |
issues: write | |
steps: | |
- name: Download OpenAPI diff log | |
uses: actions/download-artifact@v4 | |
with: | |
name: openapi-diff-log | |
- name: Create PR comment | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const output = require('fs').readFileSync('openapi_diff.json', 'utf8'); | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: '## OpenAPI diff:\n\n```json' + output + '```' | |
}) |