4242 steps :
4343 # Initial checkout only for pull_request and push events
4444 - 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'
5545 uses : actions/checkout@v4
5646 with :
5747 fetch-depth : 0
8070 exit 1
8171 fi
8272
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-
14873 - name : Setup Environment
14974 uses : ./.github/actions/setup-environment
15075 with :
@@ -272,7 +197,7 @@ jobs:
272197 id : init-deployment
273198 with :
274199 script : |
275- const ref = process.env.PR_SHA ;
200+ const ref = github.sha ;
276201 const environment = process.env.ENVIRONMENT_NAME || 'review-app';
277202
278203 const deployment = await github.rest.repos.createDeployment({
@@ -301,7 +226,7 @@ jobs:
301226 with :
302227 script : |
303228 const buildingMessage = [
304- '🏗️ Building Docker image for PR #${{ env.PR_NUMBER }}, commit ${{ env.PR_SHA }}',
229+ '🏗️ Building Docker image for PR #${{ env.PR_NUMBER }}, commit ${{ github.sha }}',
305230 '',
306231 '📝 [View Build Logs](${{ env.WORKFLOW_URL }})',
307232 '',
@@ -321,7 +246,7 @@ jobs:
321246 with :
322247 app_name : ${{ env.APP_NAME }}
323248 org : ${{ vars.CPLN_ORG_STAGING }}
324- commit : ${{ env.PR_SHA }}
249+ commit : ${{ github.sha }}
325250 PR_NUMBER : ${{ env.PR_NUMBER }}
326251
327252 - name : Update Status - Deploying
@@ -380,7 +305,7 @@ jobs:
380305
381306 // Define messages based on deployment status
382307 const successMessage = [
383- '✅ Deployment complete for PR #' + prNumber + ', commit ' + '${{ env.PR_SHA }}',
308+ '✅ Deployment complete for PR #' + prNumber + ', commit ' + '${{ github.sha }}',
384309 '',
385310 '🚀 [Review App for PR #' + prNumber + '](' + appUrl + ')',
386311 consoleLink,
@@ -389,7 +314,7 @@ jobs:
389314 ].join('\n');
390315
391316 const failureMessage = [
392- '❌ Deployment failed for PR #' + prNumber + ', commit ' + '${{ env.PR_SHA }}',
317+ '❌ Deployment failed for PR #' + prNumber + ', commit ' + '${{ github.sha }}',
393318 '',
394319 consoleLink,
395320 '',
0 commit comments