name: CI/CD on: push: branches: [main] pull_request: branches: [main] jobs: # ── 1. 린트 + 테스트 + 빌드 ──────────────────────────────────────────────── test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Setup Node.js run: | if ! command -v node &>/dev/null || [ "$(node -v | cut -d. -f1 | tr -d v)" -lt 22 ]; then curl -fsSL https://deb.nodesource.com/setup_22.x | bash - apt-get install -y nodejs fi node -v && npm -v - name: Install dependencies run: npm ci --legacy-peer-deps - name: Lint run: npm run lint - name: Test run: npm test - name: Build run: npm run build env: VITE_API_BASE_URL: https://a301.api.tolelom.xyz # ── 2. Docker 빌드 & Gitea 레지스트리 푸시 (main 머지 시만) ─────────────── docker: needs: test if: github.event_name == 'push' && github.ref == 'refs/heads/main' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Login to Gitea Registry run: echo "${{ secrets.GITEA_TOKEN }}" | docker login git.tolelom.xyz -u "${{ github.actor }}" --password-stdin - name: Build and Push Docker Image run: | docker build \ --build-arg VITE_API_BASE_URL=https://a301.api.tolelom.xyz \ -t git.tolelom.xyz/${{ github.repository_owner }}/a301-web:latest \ . docker push git.tolelom.xyz/${{ github.repository_owner }}/a301-web:latest # ── 3. 서버 배포 ────────────────────────────────────────────────────────── deploy: needs: docker runs-on: ubuntu-latest steps: - name: Deploy to Server run: | mkdir -p ~/.ssh echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/deploy_key chmod 600 ~/.ssh/deploy_key ssh -o StrictHostKeyChecking=no -i ~/.ssh/deploy_key \ ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} \ 'export PATH=$PATH:/usr/local/bin:/opt/homebrew/bin:$HOME/.docker/bin && cd ~/server && docker compose pull web && docker compose up -d web' rm -f ~/.ssh/deploy_key