Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f688c51
updated packages
vb2007 Oct 25, 2025
4d6fa55
created build & deploy gh workflow file
vb2007 Oct 25, 2025
b3e07bd
added job logic for auto deploy
vb2007 Oct 25, 2025
d719a33
added task for deploying new commands
vb2007 Oct 25, 2025
6b0d2b4
added steps for db updates & config.json syntax verification
vb2007 Oct 25, 2025
e6648ba
removed step for config.json syntax verification
vb2007 Oct 25, 2025
6a5ffc9
added missing work dirs, added verifiaction for command deployment
vb2007 Oct 25, 2025
2e7e6b1
added process exit at the end of table create script
vb2007 Oct 25, 2025
c23f307
added output verification for table create script
vb2007 Oct 25, 2025
8a9f415
added multiple branch choice for deploy workflow
vb2007 Oct 25, 2025
a3f0695
added pr trigger for testing
vb2007 Oct 25, 2025
08ed163
updated debug trigger
vb2007 Oct 25, 2025
da090e8
changed node install method
vb2007 Oct 25, 2025
0d7e4f7
removed unused import from create-tables script
vb2007 Oct 25, 2025
c2c10a3
fixed exit code in create-tables
vb2007 Oct 25, 2025
92b88ba
fixed node packag lock delete in workflow
vb2007 Oct 25, 2025
cc28891
updated variables in workflow
vb2007 Oct 25, 2025
3fb99d8
added .env variable checks to command deploy script
vb2007 Oct 25, 2025
3c21fd6
fixed extra variable in script
vb2007 Oct 25, 2025
e558c90
added extra echos for debugging workflow
vb2007 Oct 25, 2025
05cbf84
removed debug logs
vb2007 Oct 25, 2025
4f38ed2
added env paths to jobs that use npm
vb2007 Oct 25, 2025
9dccfbc
updated echo formatting
vb2007 Oct 25, 2025
b609683
temporarly changed default branch
vb2007 Oct 25, 2025
676b4a2
fixed test branch
vb2007 Oct 25, 2025
84b03b7
removed debug triggers
vb2007 Oct 25, 2025
65b322d
supressed codeql permission warnings
vb2007 Oct 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Build and Deploy
permissions: {}

on:
push:
branches: [main]
workflow_dispatch:
inputs:
branch:
description: "Branch to deploy"
required: true
default: "main"
type: string

jobs:
deploy:
runs-on: self-hosted # REQUIRES SOME SUDO EXECUTION PRIVILEGES WITHOUT A PASSWORD PROMPT

steps:
- name: Stopping systemd service
run: sudo systemctl stop discordbot

- name: Pulling latest changes
working-directory: /home/vb2007/prod/discordbot
run: |
BRANCH="${{ github.event.inputs.branch || 'main' }}"
echo "Deploying branch: $BRANCH"
git fetch origin
git reset --hard origin/$BRANCH
git clean -fd
echo "✅ Successfully pulled latest changes from $BRANCH"

# i use manual node paths and manage version manually w/ nvm
# - name: Setup Node.js
# uses: actions/setup-node@v4
# with:
# node-version: "24.8.0"

- name: Intalling Node.js dependencies
working-directory: /home/vb2007/prod/discordbot
env:
PATH: /home/vb2007/.nvm/versions/node/v24.8.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
run: |
rm -rf node_modules
npm ci
echo "✅ Dependencies installed successfully"

# for now we run without building
# - name: Build the application
# working-directory: /home/vb2007/prod/discordbot
# run: |
# npm run build
# echo "Application built successfully"

- name: Deploying possible new commands
working-directory: /home/vb2007/prod/discordbot
env:
PATH: /home/vb2007/.nvm/versions/node/v24.8.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
run: |
echo "Starting command deployment..."
deployOutput=$(npm run deploy 2>&1)
echo "$deployOutput"

if echo "$deployOutput" | grep -q "Registered .* slash (/) commands at Discord"; then
echo "✅ Command deployment successful"
else
echo "❌ Command deployment failed"
exit 1
fi
sleep 8

- name: Updating command data
working-directory: /home/vb2007/prod/discordbot
env:
PATH: /home/vb2007/.nvm/versions/node/v24.8.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
run: |
echo "Starting table creation and command data update..."
queriesOutput=$(npm run create-tables 2>&1)
echo "$queriesOutput"

if echo "$queriesOutput" | grep -q "All queries are executed & all tables are processed." && echo "$queriesOutput" | grep -q "Command data has been updated successfully."; then
echo "✅ Table creation and command data update successful"
else
echo "❌ Table creation or command data update failed"
exit 1
fi
sleep 5

- name: Starting systemd service
run: |
sudo systemctl start discordbot
sleep 5
sudo systemctl status discordbot --no-pager
echo "Systemd service started"

- name: Verifying deployment outcome
run: |
echo "Waiting for the service to start"
sleep 10

if sudo systemctl is-active --quiet discordbot.service; then
echo "✅ Deployment successful - service is running"
else
echo "❌ Deployment failed - service is not running"
sudo systemctl status discordbot.service --no-pager
exit 1
fi
Comment on lines +17 to +107

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {}

Copilot Autofix

AI 9 months ago

The best way to address this is to explicitly set the minimal possible permissions at the workflow or job level. Since this workflow does not interact with the GitHub API (e.g., does not push, create issues/PRs, etc.), it likely does not require any permissions, so we can set permissions: {} (no permissions). For maximum clarity and compatibility, and to make explicit the restricted policy, we add at the top-level of the workflow (after the name key and before on:) a permissions: {} block. If in future the workflow is extended to perform any GitHub API operations, only the minimum required permissions should be added.

Edits required:
Insert the permissions: {} line after name: Build and Deploy, i.e., between lines 1 and 2.


Suggested changeset 1
.github/workflows/build-deploy.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/build-deploy.yml b/.github/workflows/build-deploy.yml
--- a/.github/workflows/build-deploy.yml
+++ b/.github/workflows/build-deploy.yml
@@ -1,4 +1,5 @@
 name: Build and Deploy
+permissions: {}
 
 on:
   push:
EOF
@@ -1,4 +1,5 @@
name: Build and Deploy
permissions: {}

on:
push:
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
Loading