From 38da7ce57a1b6a7a48c8d8e0ef445a56c9629cf4 Mon Sep 17 00:00:00 2001 From: tolelom <98kimsungmin@naver.com> Date: Wed, 18 Mar 2026 17:21:13 +0900 Subject: [PATCH] =?UTF-8?q?ci:=20vet=20+=20=EC=BB=A4=EB=B2=84=EB=A6=AC?= =?UTF-8?q?=EC=A7=80=20=EB=A6=AC=ED=8F=AC=ED=8A=B8=20+=20Docker=20GHCR=20?= =?UTF-8?q?=EB=B9=8C=EB=93=9C/=ED=91=B8=EC=8B=9C=20+=20SSH=20=EB=B0=B0?= =?UTF-8?q?=ED=8F=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - test job: go vet + go build + go test (coverage.out 아티팩트 업로드) - docker job: main 머지 시 GHCR 이미지 빌드/푸시 (tolchain 의존성 처리) - deploy job: SSH로 docker compose pull api && up Co-Authored-By: Claude Sonnet 4.6 --- .github/workflows/ci.yml | 80 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 74 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 35bc167..bb947cd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: CI +name: CI/CD on: push: @@ -7,13 +7,12 @@ on: branches: [main] jobs: - build: + # ── 1. 빌드 + 정적 분석 + 테스트 ─────────────────────────────────────────── + test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - # a301_server depends on tolchain via go.mod replace directive. - # Clone tolchain into ../tolchain so the replace path resolves. - name: Checkout tolchain dependency uses: actions/checkout@v4 with: @@ -23,9 +22,78 @@ jobs: - uses: actions/setup-go@v5 with: go-version: '1.25' + cache: true + + - name: Vet + run: go vet ./... - name: Build run: go build ./... - - name: Test - run: go test ./... -v + - name: Test (with coverage) + run: go test ./... -coverprofile=coverage.out -coverpkg=./... + + - name: Coverage report + run: go tool cover -func=coverage.out | tail -1 + + - name: Upload coverage artifact + uses: actions/upload-artifact@v4 + with: + name: coverage + path: coverage.out + + # ── 2. Docker 빌드 & GHCR 푸시 (main 머지 시만) ─────────────────────────── + docker: + needs: test + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + # Dockerfile이 context 루트에 tolchain/ + a301_server/ 를 기대하므로 + # 각각 하위 디렉토리로 체크아웃 + - name: Checkout a301_server + uses: actions/checkout@v4 + with: + path: a301_server + + - name: Checkout tolchain dependency + uses: actions/checkout@v4 + with: + repository: ${{ github.repository_owner }}/tolchain + path: tolchain + + - uses: docker/setup-buildx-action@v3 + + - uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - uses: docker/build-push-action@v5 + with: + context: . + file: ./a301_server/Dockerfile + push: true + tags: ghcr.io/${{ github.repository_owner }}/a301-server:latest + platforms: linux/arm64 + cache-from: type=gha + cache-to: type=gha,mode=max + + # ── 3. 서버 배포 (Docker 푸시 완료 후) ──────────────────────────────────── + deploy: + needs: docker + runs-on: ubuntu-latest + steps: + - uses: appleboy/ssh-action@v1 + with: + host: ${{ secrets.SERVER_HOST }} + username: ${{ secrets.SERVER_USER }} + key: ${{ secrets.SSH_PRIVATE_KEY }} + script: | + export PATH=$PATH:/usr/local/bin:/opt/homebrew/bin:$HOME/.docker/bin + cd ~/server + docker compose pull api + docker compose up -d api