|
| 1 | +name: Build and Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + no_cache: |
| 9 | + description: '빌드 캐시 무시 (secret 변경 시 체크)' |
| 10 | + type: boolean |
| 11 | + default: false |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + packages: write |
| 16 | + |
| 17 | +jobs: |
| 18 | + resolve: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + outputs: |
| 21 | + frontend: ${{ steps.out.outputs.frontend }} |
| 22 | + backend: ${{ steps.out.outputs.backend }} |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v6 |
| 25 | + |
| 26 | + - id: filter |
| 27 | + if: github.event_name == 'push' |
| 28 | + uses: dorny/paths-filter@v4 |
| 29 | + with: |
| 30 | + filters: | |
| 31 | + frontend: |
| 32 | + - 'frontend/**' |
| 33 | + - 'pnpm-lock.yaml' |
| 34 | + - 'pnpm-workspace.yaml' |
| 35 | + backend: |
| 36 | + - 'backend/**' |
| 37 | + - 'pnpm-lock.yaml' |
| 38 | + - 'pnpm-workspace.yaml' |
| 39 | +
|
| 40 | + - id: out |
| 41 | + run: | |
| 42 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 43 | + echo "frontend=true" >> "$GITHUB_OUTPUT" |
| 44 | + echo "backend=true" >> "$GITHUB_OUTPUT" |
| 45 | + else |
| 46 | + echo "frontend=${{ steps.filter.outputs.frontend }}" >> "$GITHUB_OUTPUT" |
| 47 | + echo "backend=${{ steps.filter.outputs.backend }}" >> "$GITHUB_OUTPUT" |
| 48 | + fi |
| 49 | +
|
| 50 | + build-frontend: |
| 51 | + needs: resolve |
| 52 | + if: needs.resolve.outputs.frontend == 'true' |
| 53 | + uses: ./.github/workflows/_build-image.yml |
| 54 | + with: |
| 55 | + component: frontend |
| 56 | + dockerfile: ./frontend/Dockerfile |
| 57 | + image: ${{ github.repository_owner }}/greedyreader-fe |
| 58 | + version: ${{ github.run_number }} |
| 59 | + no_cache: ${{ inputs.no_cache || false }} |
| 60 | + secrets: |
| 61 | + BUILD_ENV: ${{ secrets.FRONTEND_ENV }} |
| 62 | + |
| 63 | + build-backend: |
| 64 | + needs: resolve |
| 65 | + if: needs.resolve.outputs.backend == 'true' |
| 66 | + uses: ./.github/workflows/_build-image.yml |
| 67 | + with: |
| 68 | + component: backend |
| 69 | + dockerfile: ./backend/Dockerfile |
| 70 | + image: ${{ github.repository_owner }}/greedyreader-be |
| 71 | + version: ${{ github.run_number }} |
| 72 | + no_cache: ${{ inputs.no_cache || false }} |
| 73 | + |
| 74 | + deploy: |
| 75 | + needs: [resolve, build-frontend, build-backend] |
| 76 | + if: | |
| 77 | + always() && |
| 78 | + !cancelled() && |
| 79 | + needs.resolve.result == 'success' && |
| 80 | + needs.build-frontend.result != 'failure' && |
| 81 | + needs.build-backend.result != 'failure' && |
| 82 | + (needs.resolve.outputs.frontend == 'true' || needs.resolve.outputs.backend == 'true') |
| 83 | + uses: ./.github/workflows/_deploy-compose.yml |
| 84 | + with: |
| 85 | + frontend_tag: ${{ needs.resolve.outputs.frontend == 'true' && github.run_number || 'latest' }} |
| 86 | + backend_tag: ${{ needs.resolve.outputs.backend == 'true' && github.run_number || 'latest' }} |
| 87 | + secrets: |
| 88 | + BACKEND_ENV: ${{ secrets.BACKEND_ENV }} |
0 commit comments