@@ -43,10 +43,19 @@ jobs:
43
43
steps :
44
44
# Initial checkout only for pull_request and push events
45
45
- name : Checkout code
46
+ if : github.event_name == 'pull_request' || github.event_name == 'push'
47
+ uses : actions/checkout@v4
48
+ with :
49
+ fetch-depth : 0
50
+ ref : ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.ref }}
51
+
52
+ # Basic checkout for other events (workflow_dispatch, issue_comment)
53
+ # We'll do proper checkout after getting PR info
54
+ - name : Initial checkout
55
+ if : github.event_name == 'workflow_dispatch' || github.event_name == 'issue_comment'
46
56
uses : actions/checkout@v4
47
57
with :
48
58
fetch-depth : 0
49
- ref : ${{ github.sha }}
50
59
51
60
- name : Validate Required Secrets and Variables
52
61
shell : bash
72
81
exit 1
73
82
fi
74
83
84
+ - name : Get PR HEAD Ref
85
+ id : getRef
86
+ env :
87
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
88
+ run : |
89
+ # For push events, try to find associated PR first
90
+ if [[ "${{ github.event_name }}" == "push" ]]; then
91
+ PR_DATA=$(gh pr list --head "${{ github.ref_name }}" --json number,headRefName,headRefOid --jq '.[0]')
92
+ if [[ -n "$PR_DATA" ]]; then
93
+ PR_NUMBER=$(echo "$PR_DATA" | jq -r .number)
94
+ else
95
+ echo "No PR found for branch ${{ github.ref_name }}, skipping deployment"
96
+ echo "DO_DEPLOY=false" >> $GITHUB_ENV
97
+ exit 0
98
+ fi
99
+ else
100
+ # Get PR number based on event type
101
+ case "${{ github.event_name }}" in
102
+ "workflow_dispatch")
103
+ PR_NUMBER="${{ github.event.inputs.pr_number }}"
104
+ ;;
105
+ "issue_comment")
106
+ PR_NUMBER="${{ github.event.issue.number }}"
107
+ ;;
108
+ "pull_request")
109
+ PR_NUMBER="${{ github.event.pull_request.number }}"
110
+ ;;
111
+ *)
112
+ echo "Error: Unsupported event type ${{ github.event_name }}"
113
+ exit 1
114
+ ;;
115
+ esac
116
+ fi
117
+
118
+ if [[ -z "$PR_NUMBER" ]]; then
119
+ echo "Error: Could not determine PR number"
120
+ echo "Event type: ${{ github.event_name }}"
121
+ echo "Event action: ${{ github.event.action }}"
122
+ echo "Ref name: ${{ github.ref_name }}"
123
+ echo "Available event data:"
124
+ echo "- PR number from inputs: ${{ github.event.inputs.pr_number }}"
125
+ echo "- PR number from issue: ${{ github.event.issue.number }}"
126
+ echo "- PR number from pull_request: ${{ github.event.pull_request.number }}"
127
+ exit 1
128
+ fi
129
+
130
+ # Get PR data
131
+ if [[ -z "$PR_DATA" ]]; then
132
+ PR_DATA=$(gh pr view "$PR_NUMBER" --json headRefName,headRefOid)
133
+ if [[ -z "$PR_DATA" ]]; then
134
+ echo "Error: PR DATA for PR #$PR_NUMBER not found"
135
+ echo "Event type: ${{ github.event_name }}"
136
+ echo "Event action: ${{ github.event.action }}"
137
+ echo "Ref name: ${{ github.ref_name }}"
138
+ echo "Attempted to fetch PR data with: gh pr view $PR_NUMBER"
139
+ exit 1
140
+ fi
141
+ fi
142
+
143
+ # Extract and set PR data
144
+ echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
145
+ echo "APP_NAME=${{ vars.REVIEW_APP_PREFIX }}-$PR_NUMBER" >> $GITHUB_ENV
146
+ echo "PR_REF=$(echo $PR_DATA | jq -r .headRefName)" >> $GITHUB_OUTPUT
147
+ echo "PR_SHA=$(echo $PR_DATA | jq -r .headRefOid)" >> $GITHUB_ENV
148
+
75
149
- name : Setup Environment
76
150
uses : ./.github/actions/setup-environment
77
151
with :
@@ -228,7 +302,7 @@ jobs:
228
302
with :
229
303
script : |
230
304
const buildingMessage = [
231
- '🏗️ Building Docker image for PR #${{ env.PR_NUMBER }}, commit ${{ github.sha }}',
305
+ '🏗️ Building Docker image for PR #${{ env.PR_NUMBER }}, commit ${{ env.PR_SHA }}',
232
306
'',
233
307
'📝 [View Build Logs](${{ env.WORKFLOW_URL }})',
234
308
'',
@@ -248,7 +322,7 @@ jobs:
248
322
with :
249
323
app_name : ${{ env.APP_NAME }}
250
324
org : ${{ vars.CPLN_ORG_STAGING }}
251
- commit : ${{ github.sha }}
325
+ commit : ${{ env.PR_SHA }}
252
326
PR_NUMBER : ${{ env.PR_NUMBER }}
253
327
254
328
- name : Update Status - Deploying
@@ -307,7 +381,7 @@ jobs:
307
381
308
382
// Define messages based on deployment status
309
383
const successMessage = [
310
- '✅ Deployment complete for PR #' + prNumber + ', commit ' + '${{ github.sha }}',
384
+ '✅ Deployment complete for PR #' + prNumber + ', commit ' + '${{ env.PR_SHA }}',
311
385
'',
312
386
'🚀 [Review App for PR #' + prNumber + '](' + appUrl + ')',
313
387
consoleLink,
@@ -316,7 +390,7 @@ jobs:
316
390
].join('\n');
317
391
318
392
const failureMessage = [
319
- '❌ Deployment failed for PR #' + prNumber + ', commit ' + '${{ github.sha }}',
393
+ '❌ Deployment failed for PR #' + prNumber + ', commit ' + '${{ env.PR_SHA }}',
320
394
'',
321
395
consoleLink,
322
396
'',
0 commit comments