This repository has been archived by the owner on Oct 14, 2024. It is now read-only.
Fetch OpenAPI spec #112
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
name: Fetch OpenAPI spec | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 0 * * *' | |
jobs: | |
fetch: | |
name: Fetch pi OpenAPI spec | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- name: Checkout this repo | |
uses: actions/checkout@v4 | |
with: | |
ref: main | |
fetch-depth: 0 | |
- name: fetch minder OpenAPI spec | |
shell: bash | |
run: | | |
set -euo pipefail | |
gh api -H "Accept: application/vnd.github+json" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
/repos/stacklok/minder/contents/pkg/api/openapi/minder/v1/minder.swagger.json | jq -r '.content' | base64 -d > src/openapi.json | |
env: | |
GH_TOKEN: ${{ secrets.REPO_READER_TOKEN }} | |
- name: Check if OpenAPI changed | |
id: check-openapi | |
run: | | |
if ! git diff --quiet src/openapi.json; then | |
echo "changed=true" >> "$GITHUB_OUTPUT" | |
else | |
echo "changed=false" >> "$GITHUB_OUTPUT" | |
fi | |
- name: Set Git config | |
run: | | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git config --global 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 src/openapi.json | |
git commit -m "Update minder 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 }} |