3939 if : github.event_name == 'issue_comment'
4040 id : getRef
4141 run : |
42- echo "PR_REF=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json headRefName | jq -r '.headRefName')" >> $GITHUB_OUTPUT
43- echo "PR_SHA=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json headRefOid | jq -r '.headRefOid')" >> $GITHUB_OUTPUT
42+ # For PR comments, get the actual PR head commit
43+ PR_DATA=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json headRefName,headRefOid)
44+ echo "PR_REF=$(echo "$PR_DATA" | jq -r '.headRefName')" >> $GITHUB_OUTPUT
45+ echo "PR_SHA=$(echo "$PR_DATA" | jq -r '.headRefOid')" >> $GITHUB_OUTPUT
4446 env :
4547 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
4648
5658 - uses : actions/checkout@v4
5759 with :
5860 fetch-depth : 0
59- ref : ${{ steps.getRef.outputs.PR_REF || github.ref }}
61+ # For PR events: use the head SHA
62+ # For PR comments: use the PR head SHA
63+ # For other events: use the push SHA
64+ ref : ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || steps.getRef.outputs.PR_SHA || github.sha }}
6065
6166 - name : Setup Environment
6267 uses : ./.github/actions/setup-environment
@@ -158,7 +163,8 @@ jobs:
158163 with :
159164 app_name : ${{ env.APP_NAME }}
160165 org : ${{ env.CPLN_ORG }}
161- commit : ${{ github.event.comment.body && steps.getRef.outputs.PR_SHA || github.sha }}
166+ # Use the same commit resolution as checkout
167+ commit : ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || steps.getRef.outputs.PR_SHA || github.sha }}
162168
163169 - name : Deploy to Control Plane
164170 if : steps.determine_action.outputs.action == 'deploy'
@@ -181,7 +187,6 @@ jobs:
181187 const workflowUrl = result.workflowUrl;
182188 const railsUrl = '${{ steps.deploy.outputs.rails_url }}';
183189 const prNumber = process.env.PR_NUMBER;
184- const commitSha = '${{ github.event.comment.body && steps.getRef.outputs.PR_SHA || github.sha }}';
185190
186191 // Update deployment status
187192 const deploymentStatus = {
@@ -196,40 +201,28 @@ jobs:
196201 deploymentStatus.environment_url = railsUrl;
197202 }
198203
199- try {
200- await github.rest.repos.createDeploymentStatus(deploymentStatus);
201- } catch (error) {
202- console.error('Failed to update deployment status:', error);
203- throw error;
204- }
204+ await github.rest.repos.createDeploymentStatus(deploymentStatus);
205205
206206 // Update the initial comment
207207 const successMessage = [
208- '🚀 Rails App Deployed to Control Plane for Commit ' + commitSha.substring(0, 7) ,
208+ '✅ Deployment successful for PR # ' + prNumber ,
209209 '',
210- '🌐 Rails App: [' + railsUrl + ' ](' + railsUrl + ')',
210+ '🚀 [Deployed Review App ](' + railsUrl + ')',
211211 '',
212- '⚡ [Control Plane Console for Review App ](https://console.cpln.io/console/org/' + process.env.CPLN_ORG + '/gvc/' + process.env.APP_NAME + '/workload)',
212+ '⚡ [Control Plane Console](https://console.cpln.io/console/org/' + process.env.CPLN_ORG + '/gvc/' + process.env.APP_NAME + '/workload)',
213213 '',
214214 '[View Workflow Status](' + workflowUrl + ')'
215215 ].join('\n');
216216
217217 const failureMessage = [
218- '❌ Deployment failed for PR ' + prNumber,
219- '',
220- 'Commit: ' + commitSha.substring(0, 7),
218+ '❌ Deployment failed for PR #' + prNumber,
221219 '',
222220 '[View Workflow Status](' + workflowUrl + ')'
223221 ].join('\n');
224222
225- try {
226- await github.rest.issues.updateComment({
227- owner: context.repo.owner,
228- repo: context.repo.repo,
229- comment_id: commentId,
230- body: isSuccess ? successMessage : failureMessage
231- });
232- } catch (error) {
233- console.error('Failed to update comment:', error);
234- throw error;
235- }
223+ await github.rest.issues.updateComment({
224+ owner: context.repo.owner,
225+ repo: context.repo.repo,
226+ comment_id: commentId,
227+ body: isSuccess ? successMessage : failureMessage
228+ });
0 commit comments