From 7f6dd5bf2543d7431c1fef9fd154f2af400fcaaf Mon Sep 17 00:00:00 2001 From: fakerdeft Date: Mon, 27 Jul 2026 09:07:59 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20PR=EA=B3=BC=20=EC=A7=81=EC=A0=91=20?= =?UTF-8?q?push=20=EB=B0=B0=ED=8F=AC=20=ED=9D=90=EB=A6=84=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC=20-=20CI=EB=A5=BC=20main=20=EB=B0=8F=20develop=20?= =?UTF-8?q?=EB=8C=80=EC=83=81=20PR=EC=97=90=EC=84=9C=EB=A7=8C=20=EC=8B=A4?= =?UTF-8?q?=ED=96=89=20-=20workflow=5Frun=20=EA=B8=B0=EB=B0=98=20CD=20?= =?UTF-8?q?=ED=8A=B8=EB=A6=AC=EA=B1=B0=20=EC=A0=9C=EA=B1=B0=20-=20develop?= =?UTF-8?q?=20push=20=EC=8B=9C=20dev=20CD=EB=A5=BC=20=EC=A7=81=EC=A0=91=20?= =?UTF-8?q?=EC=8B=A4=ED=96=89=20-=20PR=20=EB=A8=B8=EC=A7=80=20=EC=BB=A4?= =?UTF-8?q?=EB=B0=8B=EC=9D=80=20=EA=B8=B0=EC=A1=B4=20PR=20CI=20=EA=B2=B0?= =?UTF-8?q?=EA=B3=BC=EB=A5=BC=20=EC=82=AC=EC=9A=A9=ED=95=B4=20=EB=B0=94?= =?UTF-8?q?=EB=A1=9C=20=EB=B0=B0=ED=8F=AC=20-=20develop=20=EC=A7=81?= =?UTF-8?q?=EC=A0=91=20push=EB=8A=94=20=EC=A0=84=EC=B2=B4=20=EB=B9=8C?= =?UTF-8?q?=EB=93=9C=EC=99=80=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=ED=86=B5?= =?UTF-8?q?=EA=B3=BC=20=ED=9B=84=20=EB=B0=B0=ED=8F=AC=20-=20main=EC=9D=80?= =?UTF-8?q?=20PR=20=EB=A8=B8=EC=A7=80=20=EC=BB=A4=EB=B0=8B=EB=A7=8C=20?= =?UTF-8?q?=EC=9A=B4=EC=98=81=20=EB=B0=B0=ED=8F=AC=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EA=B2=80=EC=A6=9D=20-=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=98=EA=B2=8C=20=EC=83=9D=EC=84=B1=EB=90=98?= =?UTF-8?q?=EB=8D=98=20skipped=20CD=20=EC=8B=A4=ED=96=89=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-dev.yml | 35 ++++++++++++++++++++++++++++++----- .github/workflows/cd-prod.yml | 21 +++++++++++++++------ .github/workflows/ci.yml | 2 -- 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/.github/workflows/cd-dev.yml b/.github/workflows/cd-dev.yml index 5673c5e..e5358f4 100644 --- a/.github/workflows/cd-dev.yml +++ b/.github/workflows/cd-dev.yml @@ -1,28 +1,47 @@ name: CD (dev) on: - workflow_run: - workflows: ["CI"] - types: [completed] + push: branches: [develop] jobs: deploy: - if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push' }} concurrency: group: cd-dev cancel-in-progress: false runs-on: ubuntu-latest permissions: contents: read + pull-requests: read packages: write steps: - name: Checkout uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - ref: ${{ github.event.workflow_run.head_sha }} persist-credentials: false + - name: Detect direct push + id: push-source + env: + GH_TOKEN: ${{ github.token }} + run: | + MERGED_PR_COUNT=$( + curl --fail --silent --show-error --location \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer $GH_TOKEN" \ + -H "X-GitHub-Api-Version: 2026-03-10" \ + "https://api.github.com/repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/pulls" | + jq --arg branch "$GITHUB_REF_NAME" \ + '[.[] | select(.merged_at != null and .base.ref == $branch)] | length' + ) + if [ "$MERGED_PR_COUNT" -eq 0 ]; then + echo "direct_push=true" >> "$GITHUB_OUTPUT" + echo "Direct push detected: CI will run before deployment." + else + echo "direct_push=false" >> "$GITHUB_OUTPUT" + echo "Merged pull request detected: using the completed PR CI result." + fi + - name: Checkout config submodule env: SUBMODULE_PAT: ${{ secrets.SUBMODULE_PAT }} @@ -43,6 +62,12 @@ jobs: - name: Set up Gradle uses: gradle/actions/setup-gradle@3f131e8634966bd73d06cc69884922b02e6faf92 # v6.2.0 + - name: Build and test direct push + if: ${{ steps.push-source.outputs.direct_push == 'true' }} + run: | + chmod +x gradlew + ./gradlew build + - name: Build bootJar run: | chmod +x gradlew diff --git a/.github/workflows/cd-prod.yml b/.github/workflows/cd-prod.yml index 66c6566..867224c 100644 --- a/.github/workflows/cd-prod.yml +++ b/.github/workflows/cd-prod.yml @@ -1,29 +1,38 @@ name: CD (prod) -# main CI 성공 → prod 이미지(ghcr :prod) → prod EC2 배포. +# main PR CI 통과 후 merge → prod 이미지(ghcr :prod) → prod EC2 배포. on: - workflow_run: - workflows: ["CI"] - types: [completed] + push: branches: [main] jobs: deploy: - if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push' }} concurrency: group: cd-prod cancel-in-progress: false runs-on: ubuntu-latest permissions: contents: read + pull-requests: read packages: write steps: - name: Checkout uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - ref: ${{ github.event.workflow_run.head_sha }} persist-credentials: false + - name: Verify merged pull request + env: + GH_TOKEN: ${{ github.token }} + run: | + curl --fail --silent --show-error --location \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer $GH_TOKEN" \ + -H "X-GitHub-Api-Version: 2026-03-10" \ + "https://api.github.com/repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/pulls" | + jq --exit-status --arg branch "$GITHUB_REF_NAME" \ + 'any(.[]; .merged_at != null and .base.ref == $branch)' >/dev/null + - name: Checkout config submodule env: SUBMODULE_PAT: ${{ secrets.SUBMODULE_PAT }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 76abc4e..a787ded 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,8 +1,6 @@ name: CI on: - push: - branches: [main, develop] pull_request: branches: [main, develop]