From 69810bee6bbdfa3030ef014230dd5834e6f338ac Mon Sep 17 00:00:00 2001 From: sonwonjae Date: Tue, 22 Apr 2025 02:29:51 +0900 Subject: [PATCH] fix: add deploy condition --- .github/workflows/Release.yml | 44 ++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml index 3a7da63..70ad3f8 100644 --- a/.github/workflows/Release.yml +++ b/.github/workflows/Release.yml @@ -15,9 +15,39 @@ env: CODEDEPLOY_DEPLOYMENT_GROUP: weplate-deploy-group jobs: - Merge-Master-Branch-In-Develop-Branch: + check-main-updated: runs-on: ubuntu-latest - if: github.actor != 'github-actions[bot]' + outputs: + should_deploy: ${{ steps.compare.outputs.should_deploy }} + steps: + - name: Checkout main + uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: main + + - name: Compare main with origin/main + id: compare + run: | + git remote set-url origin https://github.com/${{ github.repository }}.git + git fetch origin main + LOCAL_SHA=$(git rev-parse HEAD) + REMOTE_SHA=$(git rev-parse origin/main) + + echo "📟 Local HEAD: $LOCAL_SHA" + echo "📟 Remote HEAD: $REMOTE_SHA" + + if [ "$LOCAL_SHA" = "$REMOTE_SHA" ]; then + echo "✅ No changes. Skipping deploy." + echo "should_deploy=false" >> $GITHUB_OUTPUT + else + echo "🚀 Main branch changed. Proceeding with deploy." + echo "should_deploy=true" >> $GITHUB_OUTPUT + + deploy-if-updated: + runs-on: ubuntu-latest + needs: check-main-updated + if: needs.check-main-updated.outputs.should_deploy == 'true' steps: - name: Checkout main uses: actions/checkout@v4 @@ -38,10 +68,6 @@ jobs: git merge origin/main --no-ff --no-edit --allow-unrelated-histories git push origin develop - - name: Checkout main - run: | - git checkout main - - name: Get latest tag id: get_tag run: | @@ -111,10 +137,13 @@ jobs: for NAME in "${!services[@]}"; do echo "🔨 Pushing weplate/$NAME:$VERSION" - echo "🔨 weplate/$NAME:$VERSION tagging clear" docker push $ECR_REGISTRY/weplate/$NAME:$VERSION echo "🔨 Push Complete weplate/$NAME:$VERSION in $ECR_REGISTRY" done + + determine-asg-and-deploy: + runs-on: ubuntu-latest + steps: - name: Determine ASG and Apply Desired Scaling run: | BLUE_NAME="blue" @@ -288,7 +317,6 @@ jobs: --auto-scaling-group-name "$DELETE_ASG" \ --min-size 0 --desired-capacity 0 --max-size 0 - # Step 2: Terminate instances (if any) INSTANCE_IDS=$(aws autoscaling describe-auto-scaling-groups \ --auto-scaling-group-names "$DELETE_ASG" \ --query "AutoScalingGroups[0].Instances[*].InstanceId" \