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