Skip to content

Merge pull request #502 from stacklok/issue-416 #1

Merge pull request #502 from stacklok/issue-416

Merge pull request #502 from stacklok/issue-416 #1

Workflow file for this run

name: Generate OpenAPI Documentation
on:
workflow_dispatch:
push:
branches:
- main
jobs:
generate_openapi:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- name: Set up Python 3.12
uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5
with:
python-version: "3.12"
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
- name: Configure Poetry
run: |
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Install dependencies
run: |
poetry install
- name: Generate OpenAPI JSON
run: |
poetry run generate-openapi > api/openapi.json
- name: Check if OpenAPI changed
id: check-openapi
run: |
if ! git diff --quiet api/openapi.json ; then
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "changed=false" >> "$GITHUB_OUTPUT"
fi
- name: Set git config
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
- name: Generate PR if needed
if: steps.check-openapi.outputs.changed == 'true'
run: |
git checkout -b update-openapi-$GITHUB_SHA
git add api/openapi.json
git commit -m "Update OpenAPI to version generated from ref $GITHUB_SHA"
echo "Pushing branch so we can create a PR..."
git push --set-upstream origin update-openapi-$GITHUB_SHA
gh pr create --title "Update OpenAPI" \
--body "This PR updates the OpenAPI definition to the version generated from ref $GITHUB_SHA" \
--repo "$GITHUB_REPOSITORY" \
--base main \
--head update-openapi-$GITHUB_SHA
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}