-
Notifications
You must be signed in to change notification settings - Fork 0
104 lines (91 loc) · 3.09 KB
/
python-app.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
name: Python application
on:
push
permissions:
contents: read
jobs:
build:
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/python-init
with:
secrets: ${{ toJSON(secrets) }}
- name: set up Docker
run: |
sudo bash ./install_docker.sh
cat Dockerfile.compile > Dockerfile
docker build -t complements-bot-py .
- name: Check for syntax errors or undefined names
run: |
docker run complements-bot-py flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
- name: Lint with flake8
run: |
# The GitHub editor is 127 chars wide
docker run complements-bot-py flake8 . --count --max-complexity=10 --max-line-length=127 --statistics
- name: Lint with pylint
run: |
docker run complements-bot-py pylint src
- name: Typecheck with mypy
run: |
docker run complements-bot-py mypy .
test:
timeout-minutes: 15
runs-on: ubuntu-latest
needs: [build]
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/python-init
with:
secrets: ${{ toJSON(secrets) }}
- name: set up Docker
run: |
sudo bash ./install_docker.sh
echo "$FIREBASE_CONFIG" > src/.firebase_config.json
echo "TMI_TOKEN=$TMI_TOKEN" > src/.env
echo "DATABASE_URL=$DATABASE_URL" >> src/.env
echo "CLIENT_SECRET=$CLIENT_SECRET" >> src/.env
cat Dockerfile.test > Dockerfile
bash ./docker_build.sh
- name: Test with pytest
run: |
docker run complements-bot-py pytest test_complements_bot
- name: Bandit security check
run: |
docker run complements-bot-py bandit -c pyproject.toml --severity-level medium -r .
deploy:
timeout-minutes: 15
runs-on: ubuntu-latest
needs: [test]
if: github.ref == 'refs/heads/main' # Only deploy if this was a push to main
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/python-init
with:
secrets: ${{ toJSON(secrets) }}
- name: Copy repository contents
uses: appleboy/scp-action@master
with:
HOST: ${{ secrets.HOST_IP }}
USERNAME: ${{ secrets.VPS_USERNAME }}
PORT: ${{ secrets.VPS_PORT }}
KEY: ${{ secrets.SSH_KEY }}
source: "."
target: ${{ secrets.DEPLOY_TARGET_LOCATION }}
- name: build and run docker container on server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST_IP }}
USERNAME: ${{ secrets.VPS_USERNAME }}
PORT: ${{ secrets.VPS_PORT }}
KEY: ${{ secrets.SSH_KEY }}
script: |
cd ${{ secrets.DEPLOY_TARGET_LOCATION }}
echo '${{ secrets.FIREBASE_CONFIG }}' > src/.firebase_config.json
echo "TMI_TOKEN=${{ secrets.TMI_TOKEN }}" > src/.env
echo "DATABASE_URL=${{ secrets.DATABASE_URL }}" >> src/.env
echo "CLIENT_SECRET=${{ secrets.CLIENT_SECRET }}" >> src/.env
chmod +x ./docker_build.sh
chmod +x ./docker_run.sh
./docker_run.sh