diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 1a5e99e..4dbaab6 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -7,7 +7,7 @@ on: - "*" pull_request: - types: [opened, ready_for_review, synchronize] + types: [opened, ready_for_review, synchronize, closed] pull_request_review: types: [submitted] @@ -185,7 +185,11 @@ jobs: # Deployment to production folder in S3 bucket deploy_to_production: runs-on: ubuntu-latest - if: github.ref == 'refs/heads/main' # Run for main branch + #if: github.ref == 'refs/heads/main' # Run for main branch + if: github.event_name == 'pull_request' && + github.event.action == 'closed' && + github.event.pull_request.merged == true && + github.event.pull_request.base.ref == 'main' steps: - name: configure aws credentials uses: aws-actions/configure-aws-credentials@v2 @@ -212,31 +216,15 @@ jobs: run: | echo "inside pr_number=$PR_NUMBER" echo "Before pr_number=$PR_NUMBER" - - # Query all pull requests (open, closed, and merged) - PR_API_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls" - PR_NUMBER=$(curl -s -H "Accept: application/vnd.github.v3+json" \ - -H "Authorization: Bearer $GITHUB_TOKEN" \ - $PR_API_URL | jq '.[] | select(.head.sha == "'${GITHUB_SHA}'") | .number') - - # Fallback: Retrieve PR number from GITHUB_EVENT_PATH if API fails - if [ -z "$PR_NUMBER" ]; then - echo "PR number not found via API. Attempting fallback..." - PR_NUMBER=$(jq -r '.pull_request.number // empty' < "$GITHUB_EVENT_PATH") - fi - - if [ -z "$PR_NUMBER" ]; then - echo "No PR associated with this commit. Skipping deployment." - exit 0 - fi - - + PR_NUMBER=${{ github.event.pull_request.number }} + echo "USING PR_NUMBER =$PR_NUMBER" #PR_API_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/commits/${GITHUB_SHA}/pulls" #PR_NUMBER=$(curl -s -H "Accept: application/vnd.github.groot-preview+json" \ # -H "Authorization: Bearer $GITHUB_TOKEN" \ # $PR_API_URL | jq '.[0].number') - #echo "after pr_number=$PR_NUMBER" + echo "after pr_number=$PR_NUMBER" + aws s3 sync s3://$S3_BUCKET_NAME/mergeRequest/$PR_NUMBER s3://$S3_BUCKET_NAME/production/ echo "deploy complete to production !!!" # Delete contents of the pr folder