From 036139f8c6ae97b73a5b91d4e9cdf01722b9bede Mon Sep 17 00:00:00 2001 From: MoritzWeber Date: Thu, 10 Oct 2024 14:00:08 +0200 Subject: [PATCH] ci: Auto-generate changelog for API changes --- .github/workflows/openapi-frontend.yml | 44 ------------ .github/workflows/openapi.yml | 98 ++++++++++++++++++++++++++ .github/workflows/storybook-diff.yml | 2 + 3 files changed, 100 insertions(+), 44 deletions(-) delete mode 100644 .github/workflows/openapi-frontend.yml create mode 100644 .github/workflows/openapi.yml diff --git a/.github/workflows/openapi-frontend.yml b/.github/workflows/openapi-frontend.yml deleted file mode 100644 index e4c98a3db5..0000000000 --- a/.github/workflows/openapi-frontend.yml +++ /dev/null @@ -1,44 +0,0 @@ -# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors -# SPDX-License-Identifier: CC0-1.0 - -name: 'OpenAPI frontend client' - -on: - pull_request: - branches: [main] - -jobs: - generate: - 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 - }) diff --git a/.github/workflows/openapi.yml b/.github/workflows/openapi.yml new file mode 100644 index 0000000000..887fd3f658 --- /dev/null +++ b/.github/workflows/openapi.yml @@ -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<> "$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 + }) diff --git a/.github/workflows/storybook-diff.yml b/.github/workflows/storybook-diff.yml index a389c660ce..da06d44a22 100644 --- a/.github/workflows/storybook-diff.yml +++ b/.github/workflows/storybook-diff.yml @@ -9,6 +9,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Install dependencies run: npm install storycap puppeteer http-server working-directory: ./frontend