Skip to content

Commit 91c5064

Browse files
authored
Merge pull request #227 from uniqueg/develop
Uploads error log for OpenAPI Diff output if it fails and all diff outputs as artifacts
2 parents f099807 + b52443b commit 91c5064

File tree

2 files changed

+77
-15
lines changed

2 files changed

+77
-15
lines changed

.github/workflows/ci.yml

+47-15
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,22 @@ jobs:
1212
uses: mhiew/redoc-lint-github-action@v4
1313
with:
1414
args: 'openapi/task_execution_service.openapi.yaml'
15+
validate:
16+
name: Validate OpenAPI definition
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Check out head branch
20+
uses: actions/checkout@v4
21+
- name: Run OpenAPI Validate Action
22+
uses: swaggerexpert/swagger-editor-validate@v1
23+
with:
24+
definition-file: openapi/task_execution_service.openapi.yaml
25+
1526
diff:
1627
name: Show OpenAPI differences relative to target branch
1728
runs-on: ubuntu-latest
18-
if: ${{ github.event_name == 'pull_request' }}
29+
outputs:
30+
diff_generated: ${{ steps.upload-log.outputs.artifact_id }}
1931
steps:
2032
- name: Check out head branch
2133
uses: actions/checkout@v4
@@ -27,19 +39,39 @@ jobs:
2739
with:
2840
ref: ${{ github.event.pull_request.base.ref }}
2941
path: base
30-
- name: Run OpenAPI Diff Action
31-
uses: mvegter/[email protected]
42+
- name: Create output directory
43+
run: mkdir -p diff-artifacts/
44+
- name: Pull Docker Image
45+
run: docker pull openapitools/openapi-diff:2.0.1
46+
- name: Run openapi-diff tool
47+
run: |
48+
docker run --rm \
49+
-v $(pwd)/head:/head:ro \
50+
-v $(pwd)/base:/base:ro \
51+
-v $(pwd)/diff-artifacts:/local \
52+
openapitools/openapi-diff:2.0.1 \
53+
/head/openapi/task_execution_service.openapi.yaml \
54+
/base/openapi/task_execution_service.openapi.yaml \
55+
--markdown /local/diff.md 2> diff-artifacts/error.log
56+
- name: Get PR number
57+
id: get-pr-number
58+
run: |
59+
echo "${{ github.event.pull_request.number }}" > diff-artifacts/pr_number
60+
- name: Upload artifacts
61+
uses: actions/upload-artifact@v4
3262
with:
33-
head-spec: head/openapi/task_execution_service.openapi.yaml
34-
base-spec: base/openapi/task_execution_service.openapi.yaml
63+
name: diff-artifacts
64+
path: diff-artifacts/
65+
if-no-files-found: ignore
66+
- name: Check if OpenAPI Diff failed
67+
id: check-diff
68+
run: |
69+
if [ -s diff-artifacts/error.log ]; then
70+
echo "The diff failed. Please see artifact error.log."
71+
exit 1
72+
fi
3573
36-
validate:
37-
name: Validate OpenAPI definition
38-
runs-on: ubuntu-latest
39-
steps:
40-
- name: Check out head branch
41-
uses: actions/checkout@v4
42-
- name: Run OpenAPI Validate Action
43-
uses: char0n/swagger-editor-validate@v1
44-
with:
45-
definition-file: openapi/task_execution_service.openapi.yaml
74+
permissions:
75+
contents: read
76+
pull-requests: write
77+
issues: write

.github/workflows/diff_comment.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: OpenAPI diff comment
2+
on:
3+
workflow_run:
4+
workflows: ["Lint and validate OpenAPI specs"]
5+
types: [completed]
6+
jobs:
7+
comment:
8+
runs-on: ubuntu-latest
9+
permissions:
10+
issues: write
11+
steps:
12+
- name: Download diff
13+
uses: actions/download-artifact@v4
14+
with:
15+
name: diff-artifacts
16+
path: diff-artifacts/
17+
run-id: ${{ github.event.workflow_run.id }}
18+
github-token: ${{ secrets.GITHUB_TOKEN }}
19+
- name: Create PR comment
20+
uses: actions/github-script@v7
21+
with:
22+
script: |
23+
const diff = require('fs').readFileSync('diff-artifacts/diff.md', 'utf8');
24+
const pr_number = require('fs').readFileSync('diff-artifacts/pr_number', 'utf8').trim();
25+
github.rest.issues.createComment({
26+
issue_number: pr_number,
27+
owner: context.repo.owner,
28+
repo: context.repo.repo,
29+
body: '## OpenAPI diff:\n\n' + diff
30+
})

0 commit comments

Comments
 (0)