@@ -11,9 +11,6 @@ name: Release Gate
1111on :
1212 pull_request :
1313 types : [opened, synchronize, reopened, ready_for_review]
14- workflow_run :
15- workflows : ["Internal Promotion"]
16- types : [completed]
1714 workflow_dispatch :
1815
1916permissions :
3936 if : github.event_name != 'workflow_dispatch'
4037 id : pr-info
4138 env :
42- GH_TOKEN : ${{ github.token }}
43- EVENT_NAME : ${{ github.event_name }}
44- PR_NUMBER_EVENT : ${{ github.event.pull_request.number }}
45- PR_HEAD_REF : ${{ github.event.pull_request.head.ref }}
46- WR_HEAD_BRANCH : ${{ github.event.workflow_run.head_branch }}
39+ PR_NUMBER : ${{ github.event.pull_request.number }}
40+ BRANCH_NAME : ${{ github.event.pull_request.head.ref }}
4741 run : |
48- # Determine the PR number and branch
49- if [[ "$EVENT_NAME" == "pull_request" ]]; then
50- PR_NUMBER="$PR_NUMBER_EVENT"
51- BRANCH_NAME="$PR_HEAD_REF"
52- elif [[ "$EVENT_NAME" == "workflow_run" ]]; then
53- # Get PR info from the workflow_run event
54- PR_NUMBER=$(gh pr list --json number,headRefName --jq '.[] | select(.headRefName == $branch) | .number' --arg branch "$WR_HEAD_BRANCH" | head -1)
55- BRANCH_NAME="$WR_HEAD_BRANCH"
56- else
57- echo "β Unexpected event type: $EVENT_NAME"
58- exit 1
59- fi
60-
6142 echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
6243 echo "branch_name=$BRANCH_NAME" >> "$GITHUB_OUTPUT"
6344 echo "π PR Number: $PR_NUMBER"
@@ -89,106 +70,84 @@ jobs:
8970 if : steps.is-release-pr.outputs.is_release_pr == 'true'
9071 env :
9172 GH_TOKEN : ${{ github.token }}
73+ PR_NUMBER : ${{ steps.pr-info.outputs.pr_number }}
9274 PR_BRANCH : ${{ steps.pr-info.outputs.branch_name }}
9375 run : |
9476 BRANCH="$PR_BRANCH"
9577
96- echo "π Checking for successful Internal Promotion workflow on branch: $BRANCH"
97-
98- # Get the most recent Internal Promotion workflow run for this branch
99- WORKFLOW_RUN=$(gh run list \
100- --workflow=internal-promotion.yml \
101- --branch="$BRANCH" \
102- --json databaseId,status,conclusion,createdAt,url \
103- --jq '.[0]')
104-
105- if [[ -z "$WORKFLOW_RUN" || "$WORKFLOW_RUN" == "null" ]]; then
106- echo "β ERROR: No Internal Promotion workflow found for branch $BRANCH"
107- echo ""
108- echo "π Required Action:"
109- echo " 1. Trigger the Internal Promotion workflow manually"
110- echo " 2. Complete deployments to: staging β jp-prod β eu-prod β prod"
111- echo " 3. Ensure all environments are approved and deployed successfully"
112- echo ""
113- echo "π Trigger workflow at:"
114- echo " https://github.com/${{ github.repository }}/actions/workflows/internal-promotion.yml"
115- exit 1
116- fi
117-
118- RUN_ID=$(echo "$WORKFLOW_RUN" | jq -r '.databaseId')
119- RUN_STATUS=$(echo "$WORKFLOW_RUN" | jq -r '.status')
120- RUN_CONCLUSION=$(echo "$WORKFLOW_RUN" | jq -r '.conclusion')
121- RUN_URL=$(echo "$WORKFLOW_RUN" | jq -r '.url')
78+ # Get the PR's head commit SHA
79+ PR_DATA=$(gh pr view "$PR_NUMBER" --json headRefOid)
80+ PR_HEAD_SHA=$(echo "$PR_DATA" | jq -r '.headRefOid')
12281
123- echo "π Workflow Run ID: $RUN_ID"
124- echo "π Status: $RUN_STATUS"
125- echo "π Conclusion: $RUN_CONCLUSION"
126- echo "π URL: $RUN_URL"
82+ # Get the commit timestamp for the head commit
83+ COMMIT_DATA=$(gh api "repos/${{ github.repository }}/commits/$PR_HEAD_SHA" --jq '{author: .commit.author.date, committer: .commit.committer.date}')
84+ COMMIT_TIMESTAMP=$(echo "$COMMIT_DATA" | jq -r '.committer')
12785
128- # Check if the workflow is still in progress
129- if [[ "$RUN_STATUS" != "completed" ]]; then
130- echo "β³ Internal Promotion workflow is still in progress"
131- echo ""
132- echo "Current status: $RUN_STATUS"
133- echo ""
134- echo "π Required Action:"
135- echo " Wait for the Internal Promotion workflow to complete all deployments"
136- echo " Track progress at: $RUN_URL"
137- exit 1
138- fi
86+ echo "π Verifying GitHub Environment deployments completed AFTER the current commit"
87+ echo "π Commit SHA: $PR_HEAD_SHA"
88+ echo "π
Commit Time: $COMMIT_TIMESTAMP"
89+ echo ""
90+ echo "Required environments: nr1-staging, nr1-jp-prod, nr1-eu-prod, nr1-us-prod"
91+ echo ""
13992
140- # Check if the workflow completed successfully
141- if [[ "$RUN_CONCLUSION" != "success" ]]; then
142- echo "β ERROR: Internal Promotion workflow did not complete successfully"
143- echo ""
144- echo "Conclusion: $RUN_CONCLUSION"
145- echo ""
146- echo "π Required Action:"
147- echo " 1. Review the failed workflow run at: $RUN_URL"
148- echo " 2. Fix any issues and re-run the workflow"
149- echo " 3. Ensure all environments deploy successfully"
150- exit 1
151- fi
93+ # Define the required environments in deployment order
94+ REQUIRED_ENVS=("nr1-staging" "nr1-jp-prod" "nr1-eu-prod" "nr1-us-prod")
95+ ALL_PASSED=true
96+
97+ for ENV in "${REQUIRED_ENVS[@]}"; do
98+ echo "π Checking environment: $ENV"
99+
100+ # Get the most recent successful deployment to this environment after commit time from this branch
101+ DEPLOYMENT=$(gh api \
102+ "repos/${{ github.repository }}/deployments" \
103+ -F environment="$ENV" \
104+ -F per_page=50 \
105+ --jq --arg commit_time "$COMMIT_TIMESTAMP" --arg branch "$BRANCH" \
106+ 'map(select(.created_at > $commit_time and .ref == $branch)) | sort_by(.created_at) | reverse | .[0]')
107+
108+ if [[ -z "$DEPLOYMENT" || "$DEPLOYMENT" == "null" ]]; then
109+ echo " β No deployment found for $ENV from branch $BRANCH after $COMMIT_TIMESTAMP"
110+ ALL_PASSED=false
111+ continue
112+ fi
113+
114+ DEPLOYMENT_ID=$(echo "$DEPLOYMENT" | jq -r '.id')
115+ DEPLOYMENT_CREATED=$(echo "$DEPLOYMENT" | jq -r '.created_at')
116+
117+ # Check the deployment status
118+ DEPLOYMENT_STATUS=$(gh api \
119+ "repos/${{ github.repository }}/deployments/$DEPLOYMENT_ID/statuses" \
120+ --jq 'map(select(.state == "success")) | .[0]')
121+
122+ if [[ -z "$DEPLOYMENT_STATUS" || "$DEPLOYMENT_STATUS" == "null" ]]; then
123+ echo " β No successful deployment status found for $ENV (Deployment ID: $DEPLOYMENT_ID)"
124+ ALL_PASSED=false
125+ else
126+ STATUS_CREATED=$(echo "$DEPLOYMENT_STATUS" | jq -r '.created_at')
127+ echo " β
Successfully deployed at $STATUS_CREATED"
128+ fi
129+ done
152130
153- # Verify that the prod job specifically completed
154131 echo ""
155- echo "π Verifying prod deployment job completion..."
156-
157- JOBS=$(gh run view "$RUN_ID" --json jobs --jq '.jobs')
158- PROD_JOB=$(echo "$JOBS" | jq -r '.[] | select(.name == "deploy-prod")')
159132
160- if [[ -z "$PROD_JOB" || "$PROD_JOB" == "null" ]]; then
161- echo "β ERROR: deploy-prod job not found in workflow run"
162- echo ""
163- echo "Available jobs:"
164- echo "$JOBS" | jq -r '.[].name'
133+ if [[ "$ALL_PASSED" != "true" ]]; then
134+ echo "β ERROR: Not all environments have been successfully deployed after commit $PR_HEAD_SHA"
165135 echo ""
166- echo "The workflow may not have reached the production deployment stage."
167- exit 1
168- fi
169-
170- PROD_STATUS=$(echo "$PROD_JOB" | jq -r '.status')
171- PROD_CONCLUSION=$(echo "$PROD_JOB" | jq -r '.conclusion')
172-
173- echo "π Prod Job Status: $PROD_STATUS"
174- echo "π Prod Job Conclusion: $PROD_CONCLUSION"
175-
176- if [[ "$PROD_STATUS" != "completed" ]] || [[ "$PROD_CONCLUSION" != "success" ]]; then
177- echo "β ERROR: Production deployment has not completed successfully"
136+ echo "π Required Action:"
137+ echo " 1. Trigger the Internal Promotion workflow manually"
138+ echo " 2. Complete deployments to: staging β jp-prod β eu-prod β us-prod"
139+ echo " 3. Ensure all environments are approved and deployed successfully"
178140 echo ""
179- echo "Status: $PROD_STATUS "
180- echo "Conclusion: $PROD_CONCLUSION "
141+ echo "βΉοΈ Note: All deployments must complete AFTER the commit timestamp ($COMMIT_TIMESTAMP) "
142+ echo " to ensure you're deploying the correct version. "
181143 echo ""
182- echo "π Required Action:"
183- echo " Complete the production deployment in the Internal Promotion workflow"
184- echo " Workflow: $RUN_URL"
144+ echo "π Trigger workflow at:"
145+ echo " https://github.com/${{ github.repository }}/actions/workflows/internal-promotion.yml"
185146 exit 1
186147 fi
187148
188149 # All checks passed
189- echo ""
190- echo "β
SUCCESS: Internal Promotion workflow completed successfully!"
191- echo "β
All environments deployed: staging β jp-prod β eu-prod β prod"
150+ echo "β
SUCCESS: All environments have been successfully deployed!"
151+ echo "β
Deployment chain completed: staging β jp-prod β eu-prod β us-prod"
192152 echo ""
193153 echo "π This Release-Please PR is ready to merge!"
194- echo "π Workflow run: $RUN_URL"
0 commit comments