-
Notifications
You must be signed in to change notification settings - Fork 0
ci: create test and deployment workflow #1
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
07e1226
chore: create nvm file
wiktoriavh c90cbea
ci: add GitHub Actions workflow for testing and building
wiktoriavh 67351d5
ci: implement deployment workflow using GitHub Actions
wiktoriavh ad38bd3
chore: add test script and initial sanity test
wiktoriavh 356041c
ci: migrate workflows from pnpm to npm for dependency management and …
wiktoriavh 45c1309
ci: remove npm cache configuration from workflows
wiktoriavh 38ef756
Merge branch 'main' into ci/create-workflow
wiktoriavh 8c188e7
chore: update build scripts in package.json for CI and development
wiktoriavh 85ce51a
ci: update build command in workflows to use build:ci for consistency
wiktoriavh 0b0b1ff
ci: update deploy workflow to allow manual triggering and comment out…
wiktoriavh b30d4c1
ci: enhance workflows with concurrency settings and paths-ignore for …
wiktoriavh 172a540
ci: rename APPLICATION_ID to CLIENT_ID in environment files and workf…
wiktoriavh 2d566b2
ci: update test workflow to use CLIENT_ID instead of APPLICATION_ID
wiktoriavh 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
DISCORD_TOKEN="" # Your bot token | ||
APPLICATION_ID="" # Your bot's application ID | ||
CLIENT_ID="" # Your bot's application ID |
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 |
---|---|---|
@@ -0,0 +1,122 @@ | ||
name: Deploy | ||
|
||
on: | ||
workflow_dispatch: # Manual trigger only | ||
# Uncomment below when VPS is ready: | ||
# push: | ||
# branches: [ "main" ] | ||
# paths-ignore: | ||
# - 'docs/**' | ||
# - '.gitignore' | ||
# - 'LICENSE' | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: false | ||
|
||
jobs: | ||
build-test-and-deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version-file: .nvmrc | ||
|
||
- name: Install dependencies | ||
run: | | ||
if [ -f package-lock.json ]; then | ||
npm ci --no-audit --no-fund | ||
else | ||
npm install --no-audit --no-fund | ||
fi | ||
|
||
- name: Lint | ||
run: npm run lint | ||
|
||
- name: Build | ||
run: npm run build:ci | ||
env: | ||
DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }} | ||
CLIENT_ID: ${{ secrets.CLIENT_ID }} | ||
|
||
- name: Run tests | ||
run: npm test | ||
|
||
- name: Package artifact | ||
run: | | ||
tar -czf release.tar.gz dist package.json package-lock.json .nvmrc || tar -czf release.tar.gz dist package.json .nvmrc | ||
|
||
- name: Create .env file from secrets | ||
env: | ||
DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }} | ||
CLIENT_ID: ${{ secrets.CLIENT_ID }} | ||
run: | | ||
set -euo pipefail | ||
printf "DISCORD_TOKEN=%s\n" "$DISCORD_TOKEN" > .env | ||
printf "CLIENT_ID=%s\n" "$CLIENT_ID" >> .env | ||
printf "NODE_ENV=production\n" >> .env | ||
|
||
- name: Copy artifact to VPS | ||
env: | ||
SSH_HOST: ${{ secrets.SSH_HOST }} | ||
SSH_USER: ${{ secrets.SSH_USER }} | ||
SSH_PORT: ${{ secrets.SSH_PORT }} | ||
SSH_KEY: ${{ secrets.SSH_KEY }} | ||
run: | | ||
mkdir -p ~/.ssh | ||
echo "$SSH_KEY" > ~/.ssh/id_ed25519 | ||
chmod 600 ~/.ssh/id_ed25519 | ||
ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_ed25519 -p ${SSH_PORT:-22} $SSH_USER@$SSH_HOST "mkdir -p ~/apps/webdev-bot/releases" | ||
scp -i ~/.ssh/id_ed25519 -P ${SSH_PORT:-22} -o StrictHostKeyChecking=no release.tar.gz $SSH_USER@$SSH_HOST:~/apps/webdev-bot/releases/release.tar.gz | ||
|
||
- name: Upload .env to VPS | ||
env: | ||
SSH_HOST: ${{ secrets.SSH_HOST }} | ||
SSH_USER: ${{ secrets.SSH_USER }} | ||
SSH_PORT: ${{ secrets.SSH_PORT }} | ||
SSH_KEY: ${{ secrets.SSH_KEY }} | ||
APP_DIR: ${{ secrets.APP_DIR }} | ||
run: | | ||
mkdir -p ~/.ssh | ||
echo "$SSH_KEY" > ~/.ssh/id_ed25519 | ||
chmod 600 ~/.ssh/id_ed25519 | ||
ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_ed25519 -p ${SSH_PORT:-22} $SSH_USER@$SSH_HOST "mkdir -p ${APP_DIR:-\"~/apps/webdev-bot\"}/shared && chmod 700 ${APP_DIR:-\"~/apps/webdev-bot\"}/shared" | ||
scp -i ~/.ssh/id_ed25519 -P ${SSH_PORT:-22} -o StrictHostKeyChecking=no .env $SSH_USER@$SSH_HOST:${APP_DIR:-"~/apps/webdev-bot"}/shared/.env | ||
ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_ed25519 -p ${SSH_PORT:-22} $SSH_USER@$SSH_HOST "chmod 600 ${APP_DIR:-\"~/apps/webdev-bot\"}/shared/.env" | ||
|
||
- name: Deploy on VPS | ||
env: | ||
SSH_HOST: ${{ secrets.SSH_HOST }} | ||
SSH_USER: ${{ secrets.SSH_USER }} | ||
SSH_PORT: ${{ secrets.SSH_PORT }} | ||
SSH_KEY: ${{ secrets.SSH_KEY }} | ||
APP_DIR: ${{ secrets.APP_DIR }} | ||
run: | | ||
mkdir -p ~/.ssh | ||
echo "$SSH_KEY" > ~/.ssh/id_ed25519 | ||
chmod 600 ~/.ssh/id_ed25519 | ||
ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_ed25519 -p ${SSH_PORT:-22} $SSH_USER@$SSH_HOST << 'EOF' | ||
set -euo pipefail | ||
APP_DIR=${APP_DIR:-"~/apps/webdev-bot"} | ||
mkdir -p "$APP_DIR/current" "$APP_DIR/releases" "$APP_DIR/shared" | ||
cd "$APP_DIR" | ||
rm -rf current/* | ||
tar -xzf releases/release.tar.gz -C current | ||
cd current | ||
# Load env from shared/.env for the PM2 process | ||
set -a | ||
if [ -f "$APP_DIR/shared/.env" ]; then . "$APP_DIR/shared/.env"; fi | ||
set +a | ||
if [ -f package-lock.json ]; then | ||
npm ci --omit=dev --no-audit --no-fund || true | ||
else | ||
npm install --omit=dev --no-audit --no-fund || true | ||
fi | ||
pm2 describe webdev-bot >/dev/null 2>&1 && pm2 restart webdev-bot || pm2 start "node dist/index.js" --name webdev-bot | ||
pm2 save || true | ||
EOF | ||
|
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: Test | ||
|
||
on: | ||
pull_request: | ||
branches: [ "**" ] | ||
paths-ignore: | ||
- 'docs/**' | ||
- '.gitignore' | ||
- 'LICENSE' | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
build-and-test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version-file: .nvmrc | ||
|
||
- name: Install dependencies | ||
run: | | ||
if [ -f package-lock.json ]; then | ||
npm ci --no-audit --no-fund | ||
else | ||
npm install --no-audit --no-fund | ||
fi | ||
|
||
- name: Lint | ||
run: npm run lint | ||
|
||
- name: Build | ||
run: npm run build:ci | ||
env: | ||
DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }} | ||
CLIENT_ID: ${{ secrets.CLIENT_ID }} | ||
|
||
- name: Run tests | ||
run: npm test | ||
|
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
v22.20.0 |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import assert from 'node:assert/strict'; | ||
import test from 'node:test'; | ||
|
||
test('sanity: 1 + 1 equals 2', () => { | ||
assert.equal(1 + 1, 2); | ||
}); | ||
|
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.