41
41
contains(github.event.comment.body, '/deploy-review-app'))
42
42
runs-on : ubuntu-latest
43
43
steps :
44
- # Initial checkout only for pull_request and push events
45
- - name : Checkout code
46
- uses : actions/checkout@v4
47
- with :
48
- fetch-depth : 0
49
- ref : ${{ github.sha }}
50
44
51
45
- name : Validate Required Secrets and Variables
52
46
shell : bash
72
66
exit 1
73
67
fi
74
68
69
+ - name : Get PR HEAD Ref
70
+ id : getRef
71
+ env :
72
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
73
+ run : |
74
+ # For push events, try to find associated PR first
75
+ if [[ "${{ github.event_name }}" == "push" ]]; then
76
+ PR_DATA=$(gh pr list --head "${{ github.ref_name }}" --json number,headRefName,headRefOid --jq '.[0]')
77
+ if [[ -n "$PR_DATA" ]]; then
78
+ PR_NUMBER=$(echo "$PR_DATA" | jq -r .number)
79
+ else
80
+ echo "No PR found for branch ${{ github.ref_name }}, skipping deployment"
81
+ echo "DO_DEPLOY=false" >> $GITHUB_ENV
82
+ exit 0
83
+ fi
84
+ else
85
+ # Get PR number based on event type
86
+ case "${{ github.event_name }}" in
87
+ "workflow_dispatch")
88
+ PR_NUMBER="${{ github.event.inputs.pr_number }}"
89
+ ;;
90
+ "issue_comment")
91
+ PR_NUMBER="${{ github.event.issue.number }}"
92
+ ;;
93
+ "pull_request")
94
+ PR_NUMBER="${{ github.event.pull_request.number }}"
95
+ ;;
96
+ *)
97
+ echo "Error: Unsupported event type ${{ github.event_name }}"
98
+ exit 1
99
+ ;;
100
+ esac
101
+ fi
102
+
103
+ if [[ -z "$PR_NUMBER" ]]; then
104
+ echo "Error: Could not determine PR number"
105
+ echo "Event type: ${{ github.event_name }}"
106
+ echo "Event action: ${{ github.event.action }}"
107
+ echo "Ref name: ${{ github.ref_name }}"
108
+ echo "Available event data:"
109
+ echo "- PR number from inputs: ${{ github.event.inputs.pr_number }}"
110
+ echo "- PR number from issue: ${{ github.event.issue.number }}"
111
+ echo "- PR number from pull_request: ${{ github.event.pull_request.number }}"
112
+ exit 1
113
+ fi
114
+
115
+ # Get PR data
116
+ if [[ -z "$PR_DATA" ]]; then
117
+ PR_DATA=$(gh pr view "$PR_NUMBER" --json headRefName,headRefOid)
118
+ if [[ -z "$PR_DATA" ]]; then
119
+ echo "Error: PR DATA for PR #$PR_NUMBER not found"
120
+ echo "Event type: ${{ github.event_name }}"
121
+ echo "Event action: ${{ github.event.action }}"
122
+ echo "Ref name: ${{ github.ref_name }}"
123
+ echo "Attempted to fetch PR data with: gh pr view $PR_NUMBER"
124
+ exit 1
125
+ fi
126
+ fi
127
+
128
+ # Extract and set PR data
129
+ echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
130
+ echo "APP_NAME=${{ vars.REVIEW_APP_PREFIX }}-$PR_NUMBER" >> $GITHUB_ENV
131
+ echo "PR_REF=$(echo $PR_DATA | jq -r .headRefName)" >> $GITHUB_OUTPUT
132
+ echo "PR_SHA=$(echo $PR_DATA | jq -r .headRefOid)" >> $GITHUB_ENV
133
+
134
+ - name : Checkout code
135
+ uses : actions/checkout@v4
136
+ with :
137
+ fetch-depth : 0
138
+ ref : ${{ env.PR_SHA }}
139
+
75
140
- name : Setup Environment
76
141
uses : ./.github/actions/setup-environment
77
142
with :
@@ -228,7 +293,7 @@ jobs:
228
293
with :
229
294
script : |
230
295
const buildingMessage = [
231
- '🏗️ Building Docker image for PR #${{ env.PR_NUMBER }}, commit ${{ github.sha }}',
296
+ '🏗️ Building Docker image for PR #${{ env.PR_NUMBER }}, commit ${{ env.PR_SHA }}',
232
297
'',
233
298
'📝 [View Build Logs](${{ env.WORKFLOW_URL }})',
234
299
'',
@@ -248,7 +313,7 @@ jobs:
248
313
with :
249
314
app_name : ${{ env.APP_NAME }}
250
315
org : ${{ vars.CPLN_ORG_STAGING }}
251
- commit : ${{ github.sha }}
316
+ commit : ${{ env.PR_SHA }}
252
317
PR_NUMBER : ${{ env.PR_NUMBER }}
253
318
254
319
- name : Update Status - Deploying
@@ -307,7 +372,7 @@ jobs:
307
372
308
373
// Define messages based on deployment status
309
374
const successMessage = [
310
- '✅ Deployment complete for PR #' + prNumber + ', commit ' + '${{ github.sha }}',
375
+ '✅ Deployment complete for PR #' + prNumber + ', commit ' + '${{ env.PR_SHA }}',
311
376
'',
312
377
'🚀 [Review App for PR #' + prNumber + '](' + appUrl + ')',
313
378
consoleLink,
@@ -316,7 +381,7 @@ jobs:
316
381
].join('\n');
317
382
318
383
const failureMessage = [
319
- '❌ Deployment failed for PR #' + prNumber + ', commit ' + '${{ github.sha }}',
384
+ '❌ Deployment failed for PR #' + prNumber + ', commit ' + '${{ env.PR_SHA }}',
320
385
'',
321
386
consoleLink,
322
387
'',
0 commit comments