Skip to content

Commit 9c4e43f

Browse files
chore: fix ci (#1781)
1 parent c35adf0 commit 9c4e43f

2 files changed

Lines changed: 146 additions & 114 deletions

File tree

β€Ž.github/workflows/internal-promotion.ymlβ€Ž

Lines changed: 82 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
# This workflow is used to manually deploy a Browser Agent version
1+
# This workflow is used to manually deploy a specific Browser Agent version
22
# to NR1 environments by updating the "released" asset that NR1 pages load.
33
# This workflow enforces a strict sequential promotion path:
44
# staging -> jp-prod -> eu-prod -> prod
55
# Each environment requires manual approval via GitHub Environment protection rules.
66
#
77
# Two deployment modes:
8-
# 1. "release candidate" (default): Builds fresh from current branch state and
9-
# deploys to environment-specific paths (/staging/, /jp-prod/, /eu-prod/, /prod/)
10-
# 2. Specific version/URL: Uses an existing versioned build for rollbacks or
11-
# re-promotions (e.g., "1.314.0" or full URL)
8+
# 1. Release Candidate (default on release-please branches): Builds fresh RC assets
9+
# from current branch and uploads to environment-specific CDN paths
10+
# 2. Existing Version: Promotes an already-published CDN version (for rollbacks)
1211

1312
name: Internal Promotion
1413

@@ -151,7 +150,7 @@ jobs:
151150

152151
# Notify staging deployment
153152
notify-staging:
154-
needs: [deploy-staging]
153+
needs: [resolve-version, deploy-staging]
155154
runs-on: ubuntu-latest
156155
timeout-minutes: 5
157156
steps:
@@ -233,7 +232,7 @@ jobs:
233232

234233
# Notify JP production deployment
235234
notify-jp-prod:
236-
needs: [deploy-jp-prod]
235+
needs: [resolve-version, deploy-jp-prod]
237236
runs-on: ubuntu-latest
238237
timeout-minutes: 5
239238
steps:
@@ -315,7 +314,7 @@ jobs:
315314

316315
# Notify EU production deployment
317316
notify-eu-prod:
318-
needs: [deploy-eu-prod]
317+
needs: [resolve-version, deploy-eu-prod]
319318
runs-on: ubuntu-latest
320319
timeout-minutes: 5
321320
steps:
@@ -397,7 +396,7 @@ jobs:
397396

398397
# Notify US production deployment
399398
notify-us-prod:
400-
needs: [deploy-us-prod]
399+
needs: [resolve-version, deploy-us-prod]
401400
runs-on: ubuntu-latest
402401
timeout-minutes: 5
403402
steps:
@@ -409,3 +408,77 @@ jobs:
409408
dem_platform_ops_channel_url: ${{ secrets.SLACK_DEM_PLATFORM_OPS_WEBHOOK_URL }}
410409
message: ":rocket: New Browser Agent version promoted to \\`us-prod\\` environment. See <https://github.com/newrelic/newrelic-browser-agent/actions/runs/${{ github.run_id }}|workflow run>."
411410

411+
# Re-trigger Release Gate check for Release-Please PRs
412+
retrigger-release-gate:
413+
needs: [deploy-us-prod]
414+
runs-on: ubuntu-latest
415+
permissions:
416+
contents: read
417+
pull-requests: write
418+
checks: write
419+
timeout-minutes: 5
420+
steps:
421+
- uses: actions/checkout@v4
422+
423+
- name: Find Release-Please PR for this branch
424+
id: find-pr
425+
env:
426+
GH_TOKEN: ${{ github.token }}
427+
BRANCH: ${{ github.ref_name }}
428+
run: |
429+
# Check if this is a release-please branch
430+
if [[ ! "$BRANCH" =~ ^release-please-- ]]; then
431+
echo "Not a release-please branch, skipping"
432+
echo "skip=true" >> "$GITHUB_OUTPUT"
433+
exit 0
434+
fi
435+
436+
echo "πŸ” Looking for Release-Please PR for branch: $BRANCH"
437+
438+
# Find the PR for this branch
439+
PR_NUMBER=$(gh pr list \
440+
--head "$BRANCH" \
441+
--state open \
442+
--json number \
443+
--jq '.[0].number')
444+
445+
if [[ -z "$PR_NUMBER" || "$PR_NUMBER" == "null" ]]; then
446+
echo "No open PR found for branch $BRANCH"
447+
echo "skip=true" >> "$GITHUB_OUTPUT"
448+
exit 0
449+
fi
450+
451+
echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
452+
echo "skip=false" >> "$GITHUB_OUTPUT"
453+
echo "βœ… Found PR #$PR_NUMBER"
454+
455+
- name: Re-request Release Gate check
456+
if: steps.find-pr.outputs.skip != 'true'
457+
env:
458+
GH_TOKEN: ${{ github.token }}
459+
PR_NUMBER: ${{ steps.find-pr.outputs.pr_number }}
460+
run: |
461+
echo "πŸ”„ Re-requesting checks for PR #$PR_NUMBER to unblock merge"
462+
463+
# Get the latest commit SHA for the PR
464+
HEAD_SHA=$(gh pr view "$PR_NUMBER" --json headRefOid --jq '.headRefOid')
465+
466+
echo "πŸ“Œ HEAD SHA: $HEAD_SHA"
467+
468+
# Find the Release Gate check suite for this commit
469+
CHECK_SUITE_ID=$(gh api \
470+
"repos/${{ github.repository }}/commits/$HEAD_SHA/check-suites" \
471+
--jq '.check_suites[] | select(.app.slug == "github-actions" and .conclusion != null and any(.check_runs[]?; .name == "Verify Internal Promotion")) | .id' \
472+
| head -1)
473+
474+
if [[ -n "$CHECK_SUITE_ID" ]]; then
475+
echo "πŸ”„ Requesting re-run of check suite $CHECK_SUITE_ID"
476+
gh api -X POST "repos/${{ github.repository }}/check-suites/$CHECK_SUITE_ID/rerequest"
477+
echo "βœ… Check re-requested successfully"
478+
else
479+
echo "⚠️ Could not find Release Gate check suite, it may run automatically"
480+
fi
481+
482+
echo ""
483+
echo "πŸŽ‰ Internal Promotion complete! PR #$PR_NUMBER should now be unblocked."
484+

β€Ž.github/workflows/release-gate.ymlβ€Ž

Lines changed: 64 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ name: Release Gate
1111
on:
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

1916
permissions:
@@ -39,25 +36,9 @@ jobs:
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

Comments
Β (0)