mirror of
https://github.com/TheRealOwenRees/plantid-discord-bot.git
synced 2026-07-22 20:16:57 +00:00
96 lines
3.1 KiB
YAML
96 lines
3.1 KiB
YAML
name: Production Deploy
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-24.04
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup BEAM / Elixir
|
|
uses: erlef/setup-beam@v1
|
|
with:
|
|
otp-version: 26
|
|
elixir-version: 1.16.2
|
|
|
|
- name: Cache dependencies
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: deps
|
|
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-mix-
|
|
|
|
- name: Install dependencies
|
|
run: mix deps.get
|
|
|
|
- name: Run tests
|
|
env:
|
|
PLANTID_DISCORD_BOT_TOKEN: ${{ secrets.PLANTID_DISCORD_BOT_TOKEN }}
|
|
run: mix test
|
|
|
|
- name: Clean build
|
|
run: MIX_ENV=prod mix clean --deps
|
|
|
|
- name: Build release
|
|
env:
|
|
PLANTNET_API_KEY: ${{ secrets.PLANTNET_API_KEY }}
|
|
PLANTID_DISCORD_BOT_TOKEN: ${{ secrets.PLANTID_DISCORD_BOT_TOKEN }}
|
|
PLANTID_LOGS_DISCORD_WEBHOOK_URL: ${{ secrets.PLANTID_LOGS_DISCORD_WEBHOOK_URL }}
|
|
run: MIX_ENV=prod mix release
|
|
|
|
- name: Compress build
|
|
run: tar -czf release.tar.gz -C _build/prod/rel plantid_discord_bot
|
|
|
|
- name: Upload release to server
|
|
uses: appleboy/scp-action@v0.1.7
|
|
with:
|
|
host: ${{ secrets.HOST }}
|
|
username: ${{ secrets.USERNAME }}
|
|
key: ${{ secrets.SSH_KEY }}
|
|
port: ${{ secrets.PORT }}
|
|
source: release.tar.gz
|
|
target: /home/${{ secrets.USERNAME }}/plantid_discord_bot/
|
|
|
|
- name: Deploy release
|
|
uses: appleboy/ssh-action@v1.2.0
|
|
with:
|
|
host: ${{ secrets.HOST }}
|
|
username: ${{ secrets.USERNAME }}
|
|
key: ${{ secrets.SSH_KEY }}
|
|
port: ${{ secrets.PORT }}
|
|
script: |
|
|
# setup environment variables
|
|
export PLANTID_LOGS_DISCORD_WEBHOOK_URL=${{ secrets.PLANTID_LOGS_DISCORD_WEBHOOK_URL }}
|
|
export PLANTNET_API_KEY=${{ secrets.PLANTNET_API_KEY }}
|
|
export PLANTID_DISCORD_BOT_TOKEN=${{ secrets.PLANTID_DISCORD_BOT_TOKEN }}
|
|
export PLANTID_FILESERVER_URL=${{ secrets.PLANTID_FILESERVER_URL }}
|
|
cd /home/${{ secrets.USERNAME }}/plantid_discord_bot
|
|
|
|
# extract artifacts
|
|
tar -xzf release.tar.gz
|
|
|
|
# save metrics and stop the bot - bot runs as a service
|
|
current_release/bin/plantid_discord_bot rpc "PlantidDiscordBot.Metrics.backup()"
|
|
echo "${{ secrets.SUDO_PASSWORD }}" | sudo -S sudo systemctl stop plantid_discord_bot
|
|
|
|
# switch releases
|
|
rm -rf old_release
|
|
mv current_release old_release || true
|
|
mv plantid_discord_bot current_release
|
|
|
|
# copy metrics from previous release to current release
|
|
mkdir -p current_release/priv/metrics
|
|
cp -r old_release/priv/metrics/* current_release/priv/metrics/ 2>/dev/null || true
|
|
|
|
# start the bot
|
|
echo "${{ secrets.SUDO_PASSWORD }}" | sudo -S sudo systemctl start plantid_discord_bot
|
|
|
|
# cleanup
|
|
rm -f release.tar.gz
|