-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (71 loc) · 2.63 KB
/
ci.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
name: Twitch Bot CI/CD Pipeline
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
jobs:
build:
runs-on: self-hosted # Runs directly on your Raspberry Pi
steps:
# 1. Checkout Repository
- name: Checkout Repository
uses: actions/checkout@v3
# 2. Create and Activate Virtual Environment, then Install Dependencies
- name: Set up Python Virtual Environment and Install Dependencies
run: |
# Create a virtual environment in the revbot directory if it doesn't exist
if [ ! -d "venv" ]; then
python3.11 -m venv venv # Adjust to python3.10 if necessary
fi
# Activate the virtual environment
source venv/bin/activate
# Upgrade pip inside the virtual environment
python -m pip install --upgrade pip
# Install the required dependencies inside the virtual environment
pip install -r requirements.txt
# 3. Run Black Formatter Check
- name: Run Black Formatter Check
run: |
# Activate the virtual environment
source venv/bin/activate
# Run Black with the necessary options
python -m black --check --diff --line-length 120 .
deploy:
runs-on: self-hosted # Use the self-hosted runner for deployment too
needs: build
steps:
- name: Deploy to Raspberry Pi
run: |
REVUBOT_DIR=~/revbot
REPO_URL=https://github.com/Revulate/revbot.git
# Create revbot directory if it doesn't exist
mkdir -p $REVUBOT_DIR
cd $REVUBOT_DIR
# If .git exists, pull; else, clone the repository
if [ -d ".git" ]; then
git fetch origin
git checkout main
git pull origin main
else
git clone --branch main $REPO_URL .
fi
# Use the existing virtual environment or create one if necessary
if [ ! -d "venv" ]; then
python3.11 -m venv venv # Adjust to python3.10 if necessary
fi
# Activate the virtual environment
source venv/bin/activate
# Install dependencies within the virtual environment
pip install -r requirements.txt
# Create or update the .env file
cat <<EOF > .env
TWITCH_CLIENT_ID=${{ secrets.TWITCH_CLIENT_ID }}
TWITCH_CLIENT_SECRET=${{ secrets.TWITCH_CLIENT_SECRET }}
ACCESS_TOKEN=${{ secrets.ACCESS_TOKEN }}
EOF
# Restart the Twitch bot service
sudo systemctl restart twitch-bot.service