1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-01 13:47:27 +02:00

chore: improve openapi diff output (#10570)

This will output the comment of openapi diffs in proper markdown format.
This commit is contained in:
Gastón Fournier 2025-08-28 14:15:18 -07:00 committed by GitHub
parent 8364498c22
commit 091aa2e8e9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,9 @@
name: OpenAPI Diff name: OpenAPI Diff
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: true
on: on:
pull_request: pull_request:
paths: paths:
@ -121,16 +125,20 @@ jobs:
id: diff id: diff
run: | run: |
docker run --rm -t -v $(pwd):/specs:ro tufin/oasdiff changelog --format markdown /specs/openapi-stable.json /specs/openapi-current.json > openapi-diff.txt || true docker run --rm -t -v $(pwd):/specs:ro tufin/oasdiff changelog --format markdown /specs/openapi-stable.json /specs/openapi-current.json > openapi-diff.txt || true
# then output in a format that can be used in GitHub Actions # then output in a format that is useful when you go inside the job output
docker run --rm -t -v $(pwd):/specs:ro tufin/oasdiff changelog --format githubactions /specs/openapi-stable.json /specs/openapi-current.json docker run --rm -t -v $(pwd):/specs:ro tufin/oasdiff changelog --format githubactions /specs/openapi-stable.json /specs/openapi-current.json
- name: Show OpenAPI diff
if: github.event_name != 'pull_request'
run: cat openapi-diff.txt
- name: Comment on PR with OpenAPI diff - name: Comment on PR with OpenAPI diff
if: github.event_name == 'pull_request'
uses: actions/github-script@v7 uses: actions/github-script@v7
with: with:
script: | script: |
const fs = require('fs'); const fs = require('fs');
const diff = fs.readFileSync('openapi-diff.txt', 'utf8'); const diff = fs.readFileSync('openapi-diff.txt', 'utf8');
const diffLines = diff.split('\n').filter(line => line.trim() !== '' && !line.startsWith('#')).length; const diffLines = diff.split('\n').filter(line => line.trim() !== '' && !line.startsWith('#')).length;
const marker = '### OpenAPI Diff'; const marker = '[//]: # (OpenAPI diff - used to identify the comment)';
// Get all comments on the PR // Get all comments on the PR
const { data: comments } = await github.rest.issues.listComments({ const { data: comments } = await github.rest.issues.listComments({
issue_number: context.issue.number, issue_number: context.issue.number,
@ -144,7 +152,7 @@ jobs:
body = `${marker} too long, check the this task output for details.`; body = `${marker} too long, check the this task output for details.`;
console.log(diff); console.log(diff);
} else if (diffLines > 0) { } else if (diffLines > 0) {
body = `${marker}\n\n\`\`\`diff\n${diff}\n\`\`\``; body = `${marker}\n${diff}`;
} else { } else {
body = null; body = null;
} }