From 1b11cfbe64faf2ad2dad1d48ee2750f8c7f82e63 Mon Sep 17 00:00:00 2001 From: hshah-mitre Date: Tue, 23 Dec 2025 18:10:05 -0500 Subject: [PATCH 1/5] Simplify PR number retrieval in deploy workflow Removed redundant PR number retrieval logic and fallback mechanism. --- .github/workflows/deploy.yml | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 1a5e99e..cffb0fd 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -211,32 +211,14 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 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 + echo "Before pr_number=$PR_NUMBER" - if [ -z "$PR_NUMBER" ]; then - echo "No PR associated with this commit. Skipping deployment." - exit 0 - fi - - + 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" - #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" 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 From c73bfef861336de67d579d50c3e60ca1f676edae Mon Sep 17 00:00:00 2001 From: hshah-mitre Date: Tue, 23 Dec 2025 18:26:40 -0500 Subject: [PATCH 2/5] Modify deployment workflow for debugging Commented out the condition for running deployment on the main branch and added debug echo statements for PR number. --- .github/workflows/deploy.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index cffb0fd..388d36e 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -185,7 +185,7 @@ 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 steps: - name: configure aws credentials uses: aws-actions/configure-aws-credentials@v2 @@ -211,7 +211,9 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | echo "inside pr_number=$PR_NUMBER" - echo "Before pr_number=$PR_NUMBER" + echo "Before pr_number=$PR_NUMBER" + PR='${{ steps.pr.outputs.PR_NUMBER }}' + echo "USING PR =$PR" 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" \ From ffe6c27d7958a055981ad89ff0936f5318351a33 Mon Sep 17 00:00:00 2001 From: hshah-mitre Date: Tue, 23 Dec 2025 18:30:24 -0500 Subject: [PATCH 3/5] Refactor PR_NUMBER handling in deploy.yml Updated the way PR_NUMBER is retrieved and echoed in the deploy workflow. --- .github/workflows/deploy.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 388d36e..46815d4 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -212,13 +212,13 @@ jobs: run: | echo "inside pr_number=$PR_NUMBER" echo "Before pr_number=$PR_NUMBER" - PR='${{ steps.pr.outputs.PR_NUMBER }}' - echo "USING PR =$PR" + PR_NUMBER='${{ steps.pr.outputs.PR_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') + #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" aws s3 sync s3://$S3_BUCKET_NAME/mergeRequest/$PR_NUMBER s3://$S3_BUCKET_NAME/production/ From f88b45d4c1c450f9362a4bcbfd80bde85fe26b3e Mon Sep 17 00:00:00 2001 From: hshah-mitre Date: Tue, 23 Dec 2025 18:37:40 -0500 Subject: [PATCH 4/5] Update pull request types and PR number retrieval --- .github/workflows/deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 46815d4..d31788c 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] @@ -212,7 +212,7 @@ jobs: run: | echo "inside pr_number=$PR_NUMBER" echo "Before pr_number=$PR_NUMBER" - PR_NUMBER='${{ steps.pr.outputs.PR_NUMBER }}' + 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" From 679233001a13cf2a30fbd4c77c15050547ced487 Mon Sep 17 00:00:00 2001 From: hshah-mitre Date: Tue, 23 Dec 2025 18:40:59 -0500 Subject: [PATCH 5/5] Update deployment condition for production --- .github/workflows/deploy.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d31788c..4dbaab6 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -186,6 +186,10 @@ jobs: deploy_to_production: runs-on: ubuntu-latest #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