open-law/.github/workflows/python-app.yml

80 lines
2.3 KiB
YAML

# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: Simple Flask Application CI
on:
push:
branches: [main, develop, develop_tw]
pull_request:
branches: [main, develop, develop_tw]
jobs:
tests:
strategy:
fail-fast: true
matrix:
python-version: [3.11]
poetry-version: [1.4]
os: [macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3.5.2
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Set up Poetry
uses: abatilo/actions-poetry@v2.3.0
with:
poetry-version: ${{ matrix.poetry-version }}
- name: Install dependencies
run: |
poetry install
- name: Lint with flake8
run: |
poetry run flake8 . --count --show-source --statistics
poetry run flake8 . --count --exit-zero --max-complexity=10 --statistics
- name: Run Flask tests
run: |
poetry run pytest
build:
strategy:
fail-fast: false
matrix:
python-version: [3.11]
poetry-version: [1.4]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop'
needs: tests
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v4
with:
push: true
tags: simple2b/open-law-dev:latest
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST_IP_PROD }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
script: |
sudo su -l runner -c "cd open-law; ./up.sh"