From f96e8250de28db92732ad06b72d09b7b8b97f954 Mon Sep 17 00:00:00 2001 From: thiennatra Date: Wed, 15 Apr 2026 16:49:35 +0700 Subject: [PATCH] Update ci-cd.yml --- .github/workflows/ci-cd.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 4b9e738..750a6b5 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -1,9 +1,10 @@ name: CI-CD run-name: >- - ${{ format('Main deploy: {0}', github.sha) }} + ${{ format('Merge PR #{0}: {1}', github.event.pull_request.number, github.event.pull_request.title) }} on: - push: + pull_request: + types: [closed] branches: ["main"] permissions: @@ -12,6 +13,7 @@ permissions: jobs: quality-gate: runs-on: ubuntu-latest + if: ${{ github.event.pull_request.merged == true }} steps: - uses: actions/checkout@v4 @@ -43,13 +45,15 @@ jobs: name: Deploy Gate runs-on: ubuntu-latest needs: [quality-gate] + if: ${{ github.event.pull_request.merged == true }} steps: - - run: echo "Ready for build/push on main" + - run: echo "Ready for build/push on merged PR to main" build-and-push: name: Build and Push Docker runs-on: ubuntu-latest needs: [deploy-gate] + if: ${{ github.event.pull_request.merged == true }} permissions: contents: read packages: write @@ -69,7 +73,7 @@ jobs: - name: Extract version id: version run: | - SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-7) + SHORT_SHA=$(echo ${{ github.event.pull_request.merge_commit_sha || github.sha }} | cut -c1-7) VERSION="staging-${SHORT_SHA}" REGISTRY_IMAGE="ghcr.io/$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')/${{ matrix.service }}" echo "version=${VERSION}" >> $GITHUB_OUTPUT