77 - " *"
88
99 pull_request :
10- types : [opened, ready_for_review, synchronize]
10+ types : [opened, ready_for_review, synchronize, closed ]
1111
1212 pull_request_review :
1313 types : [submitted]
@@ -185,7 +185,11 @@ jobs:
185185 # Deployment to production folder in S3 bucket
186186 deploy_to_production :
187187 runs-on : ubuntu-latest
188- if : github.ref == 'refs/heads/main' # Run for main branch
188+ # if: github.ref == 'refs/heads/main' # Run for main branch
189+ if : github.event_name == 'pull_request' &&
190+ github.event.action == 'closed' &&
191+ github.event.pull_request.merged == true &&
192+ github.event.pull_request.base.ref == 'main'
189193 steps :
190194 - name : configure aws credentials
191195 uses : aws-actions/configure-aws-credentials@v2
@@ -212,31 +216,15 @@ jobs:
212216 run : |
213217 echo "inside pr_number=$PR_NUMBER"
214218 echo "Before pr_number=$PR_NUMBER"
215-
216- # Query all pull requests (open, closed, and merged)
217- PR_API_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls"
218- PR_NUMBER=$(curl -s -H "Accept: application/vnd.github.v3+json" \
219- -H "Authorization: Bearer $GITHUB_TOKEN" \
220- $PR_API_URL | jq '.[] | select(.head.sha == "'${GITHUB_SHA}'") | .number')
221-
222- # Fallback: Retrieve PR number from GITHUB_EVENT_PATH if API fails
223- if [ -z "$PR_NUMBER" ]; then
224- echo "PR number not found via API. Attempting fallback..."
225- PR_NUMBER=$(jq -r '.pull_request.number // empty' < "$GITHUB_EVENT_PATH")
226- fi
227-
228- if [ -z "$PR_NUMBER" ]; then
229- echo "No PR associated with this commit. Skipping deployment."
230- exit 0
231- fi
232-
233-
219+ PR_NUMBER=${{ github.event.pull_request.number }}
220+ echo "USING PR_NUMBER =$PR_NUMBER"
234221
235222 #PR_API_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/commits/${GITHUB_SHA}/pulls"
236223 #PR_NUMBER=$(curl -s -H "Accept: application/vnd.github.groot-preview+json" \
237224 # -H "Authorization: Bearer $GITHUB_TOKEN" \
238225 # $PR_API_URL | jq '.[0].number')
239- #echo "after pr_number=$PR_NUMBER"
226+ echo "after pr_number=$PR_NUMBER"
227+
240228 aws s3 sync s3://$S3_BUCKET_NAME/mergeRequest/$PR_NUMBER s3://$S3_BUCKET_NAME/production/
241229 echo "deploy complete to production !!!"
242230 # Delete contents of the pr folder
0 commit comments