Skip to content

Commit

Permalink
Pytv1 migration of github workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
t0mz06 committed Jan 8, 2024
1 parent 7c3174c commit 8c1a049
Show file tree
Hide file tree
Showing 44 changed files with 804 additions and 183 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: build

on:
push:
branches: [main]
pull_request:
branches: [develop, release-**]

defaults:
run:
working-directory: ./python/pytv1

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.7
uses: actions/setup-python@v4
with:
python-version: "3.7"
- name: Install hatch
run: pip install --upgrade hatch
- name: Run hatch build
run: hatch --verbose build
67 changes: 67 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: coverage

on:
push:
branches: [main]
pull_request:
branches: [develop, release-**]

defaults:
run:
working-directory: ./python/pytv1

jobs:
coverage:
runs-on: ubuntu-latest
outputs:
total: ${{ steps.cov.outputs.total }}
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.7
uses: actions/setup-python@v4
with:
python-version: "3.7"
- name: Install dependencies
run: pip install -e ".[dev]"
- name: Run pytest coverage
id: cov
shell: bash {0}
run: |
pytest --mock-url="${{ secrets.API_URL }}" --cov-fail-under=95 --cov-report=term-missing --cov-report=xml --cov=pytmv1 --verbose
rc=$?
echo "total=$(head -2 coverage.xml|grep -Po 'line-rate="\K\d{1}\.?\d{0,4}' |awk '{print $1 * 100}'|cut -d. -f1)" >> $GITHUB_OUTPUT
exit $rc
badge:
runs-on: ubuntu-latest
needs: coverage
if: ${{ always() && github.event_name == 'push' && needs.coverage.outputs.total != '' }}
steps:
- name: Install curl
run: sudo apt install -y curl
- if: ${{ needs.coverage.outputs.total < 25 }}
run: echo "color=red" >> $GITHUB_ENV
- if: ${{ needs.coverage.outputs.total >= 25 && needs.coverage.outputs.total < 50 }}
run: echo "color=orange" >> $GITHUB_ENV
- if: ${{ needs.coverage.outputs.total >= 50 && needs.coverage.outputs.total < 75 }}
run: echo "color=yellow" >> $GITHUB_ENV
- if: ${{ needs.coverage.outputs.total >= 75 && needs.coverage.outputs.total < 90 }}
run: echo "color=yellowgreen" >> $GITHUB_ENV
- if: ${{ needs.coverage.outputs.total >= 90 && needs.coverage.outputs.total < 95 }}
run: echo "color=green" >> $GITHUB_ENV
- if: ${{ needs.coverage.outputs.total >= 95 }}
run: echo "color=brightgreen" >> $GITHUB_ENV
- name: Update coverage badge
run: |
curl \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GIST_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/gists/6c39ef59cc8beb9595e91fc96793de5b \
-d '{
"files": {
"coverage.json": {
"content": "{\n\"schemaVersion\": 1,\n\"label\": \"coverage\",\n\"message\": \"${{ needs.coverage.outputs.total }}%\",\n\"color\": \"${{ env.color }}\"\n}"
}
}
}'
61 changes: 61 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: lint

on:
push:
branches: [main]
pull_request:
branches: [develop, release-**]

defaults:
run:
working-directory: ./python/pytv1

jobs:
black:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.7
uses: actions/setup-python@v4
with:
python-version: "3.7"
- name: Install dependencies
run: pip install --upgrade pip black
- name: Run black
run: black --check --diff --verbose .
isort:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.7
uses: actions/setup-python@v4
with:
python-version: "3.7"
- name: Install dependencies
run: pip install --upgrade pip isort[colors]
- name: Run isort
run: isort --check-only --diff --verbose .
flake8:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.7
uses: actions/setup-python@v4
with:
python-version: "3.7"
- name: Install dependencies
run: pip install --upgrade pip flake8
- name: Run flake8
run: flake8 --verbose .
mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.7
uses: actions/setup-python@v4
with:
python-version: "3.7"
- name: Install dependencies
run: pip install --upgrade pip mypy==1.0.1 pydantic==1.10.4
- name: Run mypy
run: mypy --install-types --non-interactive ./src
55 changes: 55 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: release

on:
workflow_dispatch:
inputs:
version:
description: "Release version"
required: true
type: string

defaults:
run:
working-directory: ./python/pytv1

jobs:
release:
runs-on: ubuntu-latest
env:
VERSION: ${{ github.event.inputs.version }}
BRANCH: release-${{ github.event.inputs.version }}
steps:
- uses: actions/checkout@v3
with:
ssh-key: ${{ secrets.GIT_BOT_SSH_KEY }}
fetch-depth: 0
- name: Set up Python 3.7
uses: actions/setup-python@v4
with:
python-version: "3.7"
- name: Set up Git
run: |
git config --add user.name "TrendATI-bot"
git config --add user.email "[email protected]"
- name: Run build
run: |
pip install --upgrade hatch
hatch version ${{ env.VERSION }}
hatch --verbose build
- name: Publish package to PyPI
uses: pypa/[email protected]
with:
password: ${{ secrets.PYPI_TOKEN }}
verbose: true
- name: Merge release branch
run: |
git checkout ${{ env.BRANCH }}
git commit -am "Release ${{ env.VERSION }}: increment version"
git checkout main
git merge --no-ff ${{ env.BRANCH }}
git tag -a ${{ env.VERSION }} -m "Release ${{ env.VERSION }}"
git checkout ${{ env.BRANCH }}
git merge main
git checkout develop
git merge --no-ff ${{ env.BRANCH }}
git push --atomic origin main develop ${{ env.BRANCH }} refs/tags/${{ env.VERSION }}
43 changes: 43 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: test

on:
push:
branches: [main]
pull_request:
branches: [develop, release-**]

defaults:
run:
working-directory: ./python/pytv1

jobs:
unit:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11" ]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install -e ".[dev]"
- name: Run pytest
run: pytest --mock-url="https://dummy.com" --verbose ./tests/unit
integration:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11" ]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install -e ".[dev]"
- name: Run pytest
run: pytest --mock-url="${{ secrets.API_URL }}" --verbose ./tests/integration
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
*.DS_Store
**\*.DS_Store
.idea/
__pycache__/
.mypy_cache/
.pytest_cache/
.coverage
venv/
File renamed without changes.
Loading

0 comments on commit 8c1a049

Please sign in to comment.