Skip to content

Commit

Permalink
Added generate-schema workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Qwizi committed May 14, 2024
1 parent 43ca274 commit c154b37
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 2 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/docker-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Publish API Docker Image
on:
push:
branches:
- master
- monorepo
paths:
- 'api/**'
Expand Down Expand Up @@ -36,5 +37,11 @@ jobs:
context: ./api
file: ./api/Dockerfile
push: true
tags: ${{ github.repository }}-api-test:${{ steps.extract_metadata.outputs.version }}, ${{ github.repository }}:latest
tags: qwizii/cs2-battle-bot-api-test:${{ steps.extract_metadata.outputs.version }}, qwizii/cs2-battle-bot-api-test:latest
labels: ${{ steps.extract_metadata.outputs.labels }}
- name: Discord notification
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
uses: Ilshidur/action-discord@master
with:
args: '${{ EVENT_PAYLOAD.repository.full_name }} successfully built and pushed Docker images qwizii/cs2-battle-bot-api-test:${{ steps.extract_metadata.outputs.version }} and qwizii/cs2-battle-bot-api-test:latest.'
79 changes: 79 additions & 0 deletions .github/workflows/generate-schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Generate Client

on:
workflow_run:
workflows: ["docker-api.yml"]
types:
- completed

jobs:
generate-schema:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.RELEASE_GIT_TOKEN }}
- name: "Install Poetry"
run: "pipx install poetry"
- name: Set up Python ${{matrix.python-version}}
uses: "actions/setup-python@v5"
with:
python-version: 3.11
- name: "Install the project"
run: "poetry install"
- name: Install jq
run: |
sudo apt-get update
sudo apt-get install -y jq
- name: Generate Schema
run: |
cd api/src
poetry run python manage.py spectacular --file openapi.json --validate --format openapi-json
echo "Schema generated"
API_VERSION=$(jq -r .info.version openapi.json)
echo "API_RELEASE_VERSION=API_VERSION" >> $GITHUB_ENV
- name: Commit and push changes
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions "
git add .
if [[ -n "$(git diff --cached)" ]]; then
git commit -m "Generate OpenAPI schema [skip ci]"
git push
else
echo "No changes to commit"
fi
- name: Extract bot version from pyproject.toml
run: |
cd src
BOT_VERSION=$(jq -r .info.version openapi.json)
echo "BOT_RELEASE_VERSION=$BOT_VERSION" >> $GITHUB_ENV
- name: Discord notification
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
uses: Ilshidur/action-discord@master
with:
args: '${{ EVENT_PAYLOAD.repository.full_name }} successfully generated openapi schema.'
# - name: Trigger Client Generation
# uses: peter-evans/repository-dispatch@v2
# with:
# token: ${{ secrets.RELEASE_GIT_TOKEN }}
# repository: Qwizi/cs2-battle-bot-api-client
# event-type: generate-client
- name: Release New Version
uses: softprops/action-gh-release@v1
with:
name: Build-${{ github.run_id }}
tag_name: Build-${{ github.run_id }}
token: ${{ secrets.RELEASE_GIT_TOKEN }}
body: |
API Version: ${{ env.API_RELEASE_VERSION }}
Bot Version: ${{ env.BOT_RELEASE_VERSION }}
- name: Discord notification
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
uses: Ilshidur/action-discord@master
with:
args: 'Successfuly released new version of ${{ EVENT_PAYLOAD.repository.full_name }}. API Version: ${{ env.API_RELEASE_VERSION }}, Bot Version: ${{ env.BOT_RELEASE_VERSION }}.'
2 changes: 1 addition & 1 deletion api/src/cs2_battle_bot/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,4 @@

SWAGGER_SETTINGS = {"SECURITY_DEFINITIONS": {"Basic": {"type": "basic"}}}

TEST = 7
TEST = 8

0 comments on commit c154b37

Please sign in to comment.