Skip to content

Commit

Permalink
🚀 Publish autogen client to PyPI via CI/CD (#8)
Browse files Browse the repository at this point in the history
* ✨ Add endpoints for c4p2n triggers

* 💩 Notes about client generation

* 🚀 Add GitHub Actions
  • Loading branch information
b0g3r authored and Sergey Sokolov committed Mar 14, 2020
1 parent 05520a4 commit 56c15cf
Show file tree
Hide file tree
Showing 8 changed files with 516 additions and 3 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/check-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: check-release

on:
pull_request:

jobs:
check-release:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Get latest tag
id: latesttag
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
run: |
git fetch
echo "::set-output name=latest_tag::$(git describe --always --tags `git rev-list --tags --max-count=1`)"
- name: Validate poetry version
run: |
poetry_version=$(cat pyproject.toml | grep 'version =' | cut -d ' ' -f 3 | sed 's/\"//g')
echo "$poetry_version $TAG"
python scripts/validate_poetry_version.py $poetry_version ${{ steps.latesttag.outputs.latest_tag }}
38 changes: 38 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: lint

on:
pull_request:

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install poetry
run: |
python -m pip install --upgrade pip
pip install poetry >=1.0.0
poetry config virtualenvs.in-project true
- name: Set up cache
uses: actions/cache@v1
id: cache
with:
path: .venv
key: venv-${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
run: |
poetry install
- name: Lint with black
run: |
poetry run black --check ppm_telegram_bot
- name: Check types with mypy
run: |
poetry run mypy ppm_telegram_bot
- name: Check if package can be built
run: |
poetry build
63 changes: 63 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: release

on:
push:
branches:
- master

jobs:
release:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install poetry
run: |
python -m pip install --upgrade pip
pip install poetry >=1.0.0
poetry config virtualenvs.in-project true
- name: Set up cache
uses: actions/cache@v1
id: cache
with:
path: .venv
key: venv-${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
run: |
poetry install
- name: Generate OpenAPI schema definition
env:
TELEGRAM_BOT_API_KEY: '1:a'
TELEGRAM_BOT_WEBHOOK_ENDPOINT: ''
TELEGRAM_BOT_WEBHOOK_SECRET: ''
ORG_CHAT_ID: '1'
run: |
poetry run python -c "from ppm_telegram_bot.api import app; import json; schema = app.openapi(); json.dump(schema, open('openapi.json', 'w'))"
- name: Generate client
id: generate_client
run: |
git clone https://github.com/b0g3r/fastapi_client
echo "::set-output name=poetry_version::$(poetry version | cut -d ' ' -f 2)"
./fastapi_client/scripts/generate.sh \
-i openapi.json \
-p ppm_telegram_bot_client \
-o . \
--with-meta \
-- \
--additional-properties=packageVersion=$(poetry version | cut -d ' ' -f 2) || true
- name: Publish to PyPI
run: |
cd ppm_telegram_bot_client
poetry run python setup.py sdist
poetry run twine upload --username __token__ --password ${{ secrets.PYPI_PASSWORD }} dist/*
- name: Create GitHub release
uses: actions/create-release@latest
with:
tag_name: ${{ steps.generate_client.outputs.poetry_version }}
release_name: Release ${{ steps.generate_client.outputs.poetry_version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Loading

0 comments on commit 56c15cf

Please sign in to comment.