-
Notifications
You must be signed in to change notification settings - Fork 3
feat(#84): add tags functionality #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hmd-ali
wants to merge
43
commits into
main
Choose a base branch
from
feat/tags
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
799c3ed
chore: add prisma and SQLite deps
hmd-ali d70b32b
feat: add prisma schema
hmd-ali d07be56
ci: enhance CI/CD workflows with rollback support and Prisma integration
hmd-ali f4248db
chore: add lru-cache package
hmd-ali ccd4e7c
feat: add TAG_ACCESS_ROLE_ID env
hmd-ali 631cd30
feat: add prisma to tsconfig
hmd-ali 51d9003
feat: add utils
hmd-ali 25628ae
feat: export prisma singleton
hmd-ali 31e6196
feat: add ErrorMessages class
hmd-ali 0b2e912
feat: add bot options
hmd-ali 6c4b6bd
feat: add tags feature
hmd-ali 20033be
fix: add missing test env
hmd-ali 978bf69
fix: expiresAt column definition
hmd-ali 1398aa0
feat: add `createdAt` and `lastUsedAt` column indices
hmd-ali a3fc77e
feat: implement select menu interaction handling
hmd-ali de72d3c
feat: add methods for retrieving unused and prunable tags, and implem…
hmd-ali ac70fda
feat: make `/tags list` ephemeral
hmd-ali b9d0296
feat: add prune command for managing unused
hmd-ali e9c7dd7
test: add prune-tags tests
hmd-ali 3b1c609
feat: move prisma generated to src/ folder
hmd-ali 9584e16
ci: switch to building on the vps instead of in ci
hmd-ali 5ae4a86
feat: add pnpm `allowBuilds` list
hmd-ali 80b095a
chore: remove unused build entry
hmd-ali 8b9bb73
Merge branch 'main' of github.com:r-webdev/webdev-bot into feat/tags
hmd-ali baaf593
chore: revert deployment directory path in workflow
hmd-ali 8572ec3
fix: update Docker command for deploying Discord commands
hmd-ali a7ac042
docs: update Docker commands for development and production modes
hmd-ali a02241e
docs: document Prisma schema models and remove boilerplate comments
hmd-ali 818a1bf
refactor: remove fallback for tag primary alias
hmd-ali 7266555
refactor: rename parameter in tag alias parsing
hmd-ali 09499e1
refactor: extract BASE_NAME to be reused across the file
hmd-ali cfe5c4d
chore: remove dotenv dependency
hmd-ali 6b17e28
chore: remove GitHub token from deploy repo URL
hmd-ali d5f3a76
refactor: extract prune tags message input and output types
hmd-ali 682ec91
refactor: invert prune tags selection to select tags to prune
hmd-ali 9210e0c
refactor: rename buildTagWhere and use code block
hmd-ali b8c9b3f
refactor: update function name
hmd-ali 6fb5298
test: adjust prune tags tests to new logic
hmd-ali 47c77c0
chore: change vscode default prisma formatter
hmd-ali e06a181
refactor: change desc to description
hmd-ali 7b9b864
refactor: consume description instead of desc in src files
hmd-ali be7d6b2
refactor: `where` -> `queryCondition`, `buildWhereCondition` ->`build…
hmd-ali 156e6d5
fix: add missing early return
hmd-ali File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,58 +1,126 @@ | ||
| name: Build, Test and Deploy Discord Bot to VPS | ||
|
|
||
| name: Deploy | ||
| on: | ||
| push: | ||
| branches: ['main'] | ||
| workflow_dispatch: # Allow manual deployment | ||
| branches: [main] | ||
| workflow_dispatch: | ||
| inputs: | ||
| ref: | ||
| description: 'Git ref (commit SHA or tag) to deploy. Leave blank for latest main.' | ||
| required: false | ||
| default: '' | ||
|
|
||
| concurrency: | ||
| group: deploy-${{ github.ref }} | ||
| cancel-in-progress: false | ||
|
|
||
| env: | ||
| MAX_BACKUPS: 4 | ||
|
hmd-ali marked this conversation as resolved.
|
||
| DIR: /home/${{ secrets.VPS_USER }}/webdev-bot-deploy | ||
|
|
||
| jobs: | ||
| deploy: | ||
| lint: | ||
| name: Lint & Format Check | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Read Node version | ||
| run: | | ||
| NODE_VERSION=$(cat .nvmrc | sed 's/v//') | ||
| echo "NODE_VERSION=$NODE_VERSION" >> $GITHUB_ENV | ||
| - name: Setup pnpm | ||
| uses: pnpm/action-setup@v4 | ||
|
|
||
| - name: Setup Node | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version-file: '.nvmrc' | ||
| cache: pnpm | ||
|
|
||
| - name: Install dependencies | ||
| run: pnpm install --frozen-lockfile | ||
|
|
||
| - name: Prisma generate (sanity check schema) | ||
| run: pnpm run prisma:generate | ||
| env: | ||
| DATABASE_URL: file:/tmp/ci.db | ||
|
|
||
| - name: Deploy to VPS | ||
| uses: appleboy/ssh-action@v1.0.3 | ||
| - name: Lint | ||
| run: pnpm lint | ||
|
|
||
| - name: Format | ||
| run: pnpm fmt:check | ||
|
|
||
| - name: Typecheck | ||
| run: pnpm typecheck | ||
|
|
||
| deploy: | ||
| name: Deploy to VPS | ||
| runs-on: ubuntu-latest | ||
| needs: [lint] | ||
| permissions: | ||
| contents: read | ||
| steps: | ||
| - name: Deploy via SSH | ||
| uses: appleboy/ssh-action@v1 | ||
| with: | ||
| host: ${{ secrets.VPS_HOST }} | ||
| username: ${{ secrets.VPS_USER }} | ||
| key: ${{ secrets.VPS_SSH_KEY }} | ||
| envs: REPO_URL,REF | ||
| script: | | ||
| cd /home/${{ secrets.VPS_USER }}/webdev-bot-deploy | ||
| set -eu | ||
| mkdir -p ${{ env.DIR }} | ||
| cd ${{ env.DIR }} | ||
|
|
||
| # Stash any local changes | ||
| git stash push -m "Auto-deploy $(date)" 2>/dev/null || true | ||
| if [ -d .git ]; then | ||
| git stash push -m "Auto-deploy $(date)" 2>/dev/null || true | ||
| git fetch origin | ||
| git checkout "$REF" | ||
| git reset --hard "origin/$REF" 2>/dev/null || git reset --hard "$REF" | ||
| else | ||
| git clone "$REPO_URL" . | ||
| git checkout "$REF" | ||
| fi | ||
|
|
||
| # Pull latest changes | ||
| git checkout main | ||
| git pull origin main | ||
| mkdir -p ${{ env.DIR }}/backups | ||
|
|
||
| # Read NODE_VERSION from .nvmrc | ||
| export NODE_VERSION=$(cat .nvmrc | sed 's/v//') | ||
| export NODE_VERSION=$(cat .nvmrc | tr -d 'v') | ||
| echo "Using Node version: $NODE_VERSION" | ||
|
|
||
| # Create .env file with secrets | ||
| # Public config comes from .env.production (committed to repo) | ||
| # NODE_ENV=production is set in docker-compose.yml | ||
| cat > .env << EOF | ||
| cat > .env <<'EOF' | ||
| DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} | ||
| CLIENT_ID=${{ secrets.CLIENT_ID }} | ||
| EOF | ||
| chmod 600 .env | ||
|
|
||
| # Backup the SQLite DB before touching anything | ||
| if docker volume inspect webdev-bot_guides-data >/dev/null 2>&1; then | ||
| docker run --rm \ | ||
| -v webdev-bot_guides-data:/data \ | ||
| -v ${{ env.DIR }}/backups:/backup \ | ||
| alpine sh -c "if [ -f /data/db.sqlite ]; then cp /data/db.sqlite /backup/db-\$(date +%Y%m%d%H%M%S).sqlite; fi" | ||
| ls -1t ${{ env.DIR }}/backups/*.sqlite 2>/dev/null \ | ||
| | tail -n +$((env.MAX_BACKUPS+1)) \ | ||
| | xargs -r rm -- | ||
| fi | ||
|
|
||
|
hmd-ali marked this conversation as resolved.
|
||
| docker compose config >/dev/null | ||
| docker compose build bot | ||
|
|
||
| if ! docker compose run --rm migrate; then | ||
| echo "Migration failed — leaving existing bot container untouched." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Stop any existing containers | ||
| docker compose down || true | ||
| docker compose up -d --remove-orphans bot | ||
|
|
||
| # Build and start production container with profile | ||
| # NODE_ENV=production is explicitly set in docker-compose.yml bot-prod service | ||
| docker compose --profile prod up -d --build | ||
| sleep 8 | ||
| if ! docker compose ps bot --status running | grep -q bot; then | ||
| echo "Bot container is not running after deploy!" | ||
| docker compose logs --tail=50 bot | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Check status | ||
| echo "Deployment completed. Container status:" | ||
| docker compose ps | ||
| docker image prune -f | ||
| env: | ||
| REPO_URL: https://github.com/${{ github.repository }}.git | ||
| REF: ${{ github.event.inputs.ref != '' && github.event.inputs.ref || 'main' }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.