Skip to content

Feature/backend sort #134

Feature/backend sort

Feature/backend sort #134

Workflow file for this run

name: CI
on:
pull_request:
branches: [main, dev]
push:
branches: [main, dev]
workflow_dispatch:
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: false
jobs:
check-and-deploy:
runs-on: self-hosted
env:
DEPLOY_DIR: /var/www/project2
SERVICE: project2-backend.service
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 24.21.0
- uses: pnpm/action-setup@v4
with:
version: 11.25.0
- name: Get pnpm store path
id: pnpm-store
run: echo "path=$(pnpm store path --silent)" >> "$GITHUB_OUTPUT"
- uses: actions/cache@v4
with:
path: ${{ steps.pnpm-store.outputs.path }}
key: pnpm-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: pnpm-${{ runner.os }}-
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Format
run: pnpm format:check
- name: Lint frontend
if: ${{ !cancelled() }}
run: pnpm --filter frontend lint
- name: Lint backend
if: ${{ !cancelled() }}
run: pnpm --filter backend lint
- name: Build frontend
if: ${{ !cancelled() }}
run: pnpm --filter frontend build
- name: Build backend
if: ${{ !cancelled() }}
run: pnpm --filter backend build
- name: Test frontend
if: ${{ !cancelled() }}
run: pnpm --filter frontend --if-present run test
- name: Test backend
if: ${{ !cancelled() }}
run: pnpm --filter backend --if-present run test
- name: Deploy frontend
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
run: rsync -a --delete frontend/dist/ "$DEPLOY_DIR/frontend/"
- name: Deploy backend
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
run: |
rm -rf "$DEPLOY_DIR/backend.new" "$DEPLOY_DIR/backend.old"
pnpm --filter backend deploy --prod "$DEPLOY_DIR/backend.new"
if [ -d "$DEPLOY_DIR/backend" ]; then mv "$DEPLOY_DIR/backend" "$DEPLOY_DIR/backend.old"; fi
mv "$DEPLOY_DIR/backend.new" "$DEPLOY_DIR/backend"
sudo -n /usr/bin/systemctl restart "$SERVICE"
rm -rf "$DEPLOY_DIR/backend.old"
- name: Check backend
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
run: |
for i in $(seq 1 10); do
if curl -sf -X POST -H 'Content-Type: application/json' \
-d '{"query":"{ genres { id } }"}' http://localhost:3001/ > /dev/null; then
echo "Backend is up"
exit 0
fi
sleep 2
done
echo "Backend did not respond"
systemctl status "$SERVICE" --no-pager || true
exit 1