@@ -42,19 +42,10 @@ jobs:
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
48+ ref : github.sha
5849
5950 - name : Validate Required Secrets and Variables
6051 shell : bash
8071 exit 1
8172 fi
8273
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-
14874 - name : Setup Environment
14975 uses : ./.github/actions/setup-environment
15076 with :
@@ -272,7 +198,7 @@ jobs:
272198 id : init-deployment
273199 with :
274200 script : |
275- const ref = process.env.PR_SHA ;
201+ const ref = github.sha ;
276202 const environment = process.env.ENVIRONMENT_NAME || 'review-app';
277203
278204 const deployment = await github.rest.repos.createDeployment({
@@ -301,7 +227,7 @@ jobs:
301227 with :
302228 script : |
303229 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 }}',
305231 '',
306232 '📝 [View Build Logs](${{ env.WORKFLOW_URL }})',
307233 '',
@@ -321,7 +247,7 @@ jobs:
321247 with :
322248 app_name : ${{ env.APP_NAME }}
323249 org : ${{ vars.CPLN_ORG_STAGING }}
324- commit : ${{ env.PR_SHA }}
250+ commit : ${{ github.sha }}
325251 PR_NUMBER : ${{ env.PR_NUMBER }}
326252
327253 - name : Update Status - Deploying
@@ -380,7 +306,7 @@ jobs:
380306
381307 // Define messages based on deployment status
382308 const successMessage = [
383- '✅ Deployment complete for PR #' + prNumber + ', commit ' + '${{ env.PR_SHA }}',
309+ '✅ Deployment complete for PR #' + prNumber + ', commit ' + '${{ github.sha }}',
384310 '',
385311 '🚀 [Review App for PR #' + prNumber + '](' + appUrl + ')',
386312 consoleLink,
@@ -389,7 +315,7 @@ jobs:
389315 ].join('\n');
390316
391317 const failureMessage = [
392- '❌ Deployment failed for PR #' + prNumber + ', commit ' + '${{ env.PR_SHA }}',
318+ '❌ Deployment failed for PR #' + prNumber + ', commit ' + '${{ github.sha }}',
393319 '',
394320 consoleLink,
395321 '',
0 commit comments