Files
BotNoticias/.gitea/workflows/deploy-new.yml
binlab b980aa70e3
Some checks failed
Update Bot / restart-bot (push) Has been cancelled
Update Bot / deploy-via-sftp (push) Has been cancelled
hay que cambiar esto, importante
2025-10-26 22:06:43 +01:00

114 lines
4.1 KiB
YAML

name: Deploy new Bot
on:
# allows the workflow to be run manually
workflow_dispatch:
env:
REPO_NAME: focabot
jobs:
install-requirements:
runs-on: ubuntu-latest
steps:
- name: Installing requirements for ${{ env.REPO_NAME }}
uses: https://github.com/fifsky/ssh-action@master
with:
# install the libraries required for your bot
command: |
pip install -r requirements.txt
sudo apt install sshpass
host: 172.17.0.1
user: binlab
pass: ${{ secrets.KEY }}
deploy-via-sftp:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- id: SFTPDeploy
uses: https://github.com/wlixcc/SFTP-Deploy-Action@v1.2.4
with:
username: binlab
server: 172.17.0.1
port: 22
# clones entire github repo
local_path: ./*
# destination of the code on the server
remote_path: /home/binlab/${{ env.REPO_NAME }}/
password: ${{ secrets.KEY }}
ssh_private_key: ignored
# you may or may not need this. It all depends on how your code retrieves your discord token
# environment variables or Github secrets are heavily recommended
add-bot-token:
needs: [ deploy-via-sftp ]
runs-on: ubuntu-latest
timeout-minutes: 2
env:
BOT_TOKEN: ${{ secrets.TOKEN }}
steps:
- id: add-bot-token
uses: https://github.com/fifsky/ssh-action@master
with:
command: |
cd ${{ env.REPO_NAME }}/lib/bot
touch token.0
echo ${{ env.BOT_TOKEN }} > token.0
echo $?
host: 172.17.0.1
user: binlab
pass: ${{ secrets.KEY }}
create-systemctl-service:
needs: [add-bot-token, deploy-via-sftp]
runs-on: ubuntu-latest
steps:
- id: creating-systemctl-service
uses: https://github.com/fifsky/ssh-action@master
with:
# Make sure ExecStart=, WorkingDirectory= and chmod +x point to the same directory. These may be unique to your code setup
command: |
sudo touch /etc/systemd/system/${{ env.REPO_NAME }}.service; chmod /etc/systemd/system/${{ env.REPO_NAME }}.service 666
echo "[Unit]
Description=${{ env.REPO_NAME }} Discord Bot
After=multi-user.target
[Service]
Type=simple
ExecStart=/usr/bin/python3.10 /home/binlab/${{ env.REPO_NAME }}/main.py
User=root
Restart=on-failure
RestartSec=30
WorkingDirectory=/home/binlab/${{ env.REPO_NAME }}/
[Install]
WantedBy=multi-user.target" >> /etc/systemd/system/${{ env.REPO_NAME }}.service
chmod +x /home/binlab/${{ env.REPO_NAME }}/main.py
sudo systemctl enable ${{ env.REPO_NAME }}.service
sudo systemctl daemon-reload
sudo systemctl start ${{ env.REPO_NAME }}.service
host: 172.17.0.1
user: binlab
key: ${{ secrets.KEY }}
create-systemctl-restart:
needs: [create-systemctl-service, add-bot-token, deploy-via-sftp]
runs-on: ubuntu-latest
steps:
- id: create-systemctl-restart-service
uses: https://github.com/fifsky/ssh-action@master
with:
command: |
sudo touch /etc/systemd/system/${{ env.REPO_NAME }}-watcher.service && chmod 666 /etc/systemd/system/${{ env.REPO_NAME }}-watcher.service
echo "[Unit]
Description=${{ env.REPO_NAME }} Discord Bot restart
After=multi-user.target
[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl restart ${{ env.REPO_NAME }}.service
[Install]
WantedBy=multi-user.target" >> /etc/systemd/system/${{ env.REPO_NAME }}-watcher.service
sudo systemctl enable ${{ env.REPO_NAME }}-watcher.service
sudo systemctl daemon-reload
sudo systemctl start ${{ env.REPO_NAME }}-watcher.service
host: 172.17.0.1
user: binlab
key: ${{ secrets.KEY }}