-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: Auto-generate changelog for API changes
- Loading branch information
1 parent
cacca7c
commit 036139f
Showing
3 changed files
with
100 additions
and
44 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors | ||
# SPDX-License-Identifier: CC0-1.0 | ||
|
||
name: 'OpenAPI Schema' | ||
|
||
on: | ||
pull_request: | ||
branches: ['**'] | ||
paths: | ||
- 'backend/**' | ||
- 'Makefile' | ||
- '.github/workflows/openapi.yml' | ||
|
||
jobs: | ||
generate-frontend-client: | ||
runs-on: ubuntu-latest | ||
if: github.actor != 'dependabot[bot]' | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install python | ||
uses: actions/setup-python@v5 | ||
with: | ||
cache: pip | ||
cache-dependency-path: ./backend/pyproject.toml | ||
python-version: '3.11' | ||
- name: Install dependencies | ||
working-directory: ./backend | ||
run: python -m venv .venv && .venv/bin/pip install -e ".[dev]" | ||
- name: Run openapi-generator | ||
run: make openapi | ||
- name: Compare against HEAD | ||
id: git-diff | ||
run: git add . && git diff --cached --exit-code | ||
- name: Post comment if client is outdated | ||
if: always() && steps.git-diff.outcome == 'failure' | ||
uses: actions/github-script@v7 | ||
env: | ||
TEXT: |- | ||
The generated OpenAPI client is not up to date with the latest changes in the OpenAPI specification. | ||
Please run `make openapi` locally and commit the changes. | ||
with: | ||
script: | | ||
github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: process.env.TEXT | ||
}) | ||
changelog: | ||
runs-on: ubuntu-latest | ||
if: github.actor != 'dependabot[bot]' | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Install python | ||
uses: actions/setup-python@v5 | ||
with: | ||
cache: pip | ||
cache-dependency-path: ./backend/pyproject.toml | ||
python-version: '3.11' | ||
- name: Install dependencies | ||
working-directory: ./backend | ||
run: python -m venv .venv && .venv/bin/pip install -e ".[dev]" | ||
- name: Run openapi-generator for target | ||
working-directory: ./backend | ||
run: make openapi | ||
- name: Move openapi schema file | ||
run: mv /tmp/openapi.json /tmp/openapi2.json | ||
- name: Checkout base | ||
run: git checkout "${{ github.event.pull_request.base.sha }}" | ||
- name: Run openapi-generator for base | ||
working-directory: ./backend | ||
run: make openapi | ||
- name: Install oasdiff | ||
run: go install github.com/tufin/oasdiff@latest | ||
- name: Compare openapi schema files | ||
id: oasdiff | ||
run: | | ||
{ | ||
echo 'changelog<<EOF' | ||
docker run --rm -v /tmp:/tmp:ro tufin/oasdiff changelog \ | ||
--format markup \ | ||
/tmp/openapi.json /tmp/openapi2.json | ||
echo 'EOF' | ||
} >> "$GITHUB_OUTPUT" | ||
- name: Post comment with changelog | ||
uses: actions/github-script@v7 | ||
env: | ||
TEXT: ${{ steps.oasdiff.outputs.changelog }} | ||
with: | ||
script: | | ||
github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: process.env.TEXT | ||
}) |
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