formattering på backend #94
Workflow file for this run
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
| 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: Format | ||
| run: pnpm format:check | ||
| - name: Lint | ||
| run: pnpm lint | ||
| - name: Build | ||
| run: pnpm build | ||
| - name: Test | ||
| run: pnpm -r --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 | ||