@@ -32,22 +32,61 @@ jobs:
3232 issues : write
3333
3434 steps :
35+ - name : Get PR HEAD Ref
36+ if : ${{ github.event_name == 'issue_comment' }}
37+ id : getRef
38+ run : |
39+ echo "PR_REF=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json headRefName | jq -r '.headRefName')" >> $GITHUB_OUTPUT
40+ env :
41+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
42+
3543 - uses : actions/checkout@v4
44+ with :
45+ fetch-depth : 0
46+ ref : ${{ steps.getRef.outputs.PR_REF || github.ref }}
3647
37- - name : Create initial comment
38- id : create-comment
48+ - name : Initialize Deployment
49+ id : init-deployment
3950 uses : actions/github-script@v7
4051 with :
4152 script : |
42- const deploymentId = Date.now().toString();
43- core.exportVariable('deploymentId', deploymentId);
53+ // Create GitHub deployment
54+ const deployment = await github.rest.repos.createDeployment({
55+ owner: context.repo.owner,
56+ repo: context.repo.repo,
57+ ref: context.sha,
58+ environment: 'review-app',
59+ auto_merge: false,
60+ required_contexts: []
61+ });
62+
63+ // Create initial comment
4464 const comment = await github.rest.issues.createComment({
4565 issue_number: context.issue.number || context.payload.pull_request.number,
4666 owner: context.repo.owner,
4767 repo: context.repo.repo,
48- body: `🚀 Starting deployment [${deploymentId}] for ${context.sha.substring(0, 7)}`
68+ body: `🚀 Starting deployment for ${context.sha.substring(0, 7)}\nDeployment ID: ${deployment.data.id}`
69+ });
70+
71+ // Set deployment status to in_progress
72+ await github.rest.repos.createDeploymentStatus({
73+ owner: context.repo.owner,
74+ repo: context.repo.repo,
75+ deployment_id: deployment.data.id,
76+ state: 'in_progress',
77+ description: 'Deployment is in progress'
4978 });
50- core.setOutput('comment-id', comment.data.id);
79+
80+ return {
81+ deploymentId: deployment.data.id,
82+ commentId: comment.data.id
83+ };
84+
85+ - name : Setup cpflow app
86+ run : |
87+ if ! cpflow exists -a ${{ env.APP_NAME }} ; then
88+ cpflow setup-app -a ${{ env.APP_NAME }}
89+ fi
5190
5291 - name : Deploy to Control Plane
5392 id : deploy
@@ -60,13 +99,34 @@ jobs:
6099 org : ${{ env.CPLN_ORG }}
61100 github_token : ${{ secrets.GITHUB_TOKEN }}
62101
63- - name : Post deployment status
102+ - name : Update Status
64103 if : always()
65- uses : ./.github/ actions/post-deployment-status
104+ uses : actions/github-script@v7
66105 with :
67- status : ${{ job.status == 'success' && 'success' || 'failure' }}
68- rails-url : ${{ steps.deploy.outputs.rails_url }}
69- github-token : ${{ secrets.GITHUB_TOKEN }}
70- deployment-id : ${{ env.deploymentId }}
71- comment-id : ${{ steps.create-comment.outputs.comment-id }}
72- workflow-url : ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
106+ script : |
107+ const isSuccess = '${{ job.status }}' === 'success';
108+ const deploymentId = ${{ fromJSON(steps.init-deployment.outputs.result).deploymentId }};
109+ const commentId = ${{ fromJSON(steps.init-deployment.outputs.result).commentId }};
110+ const railsUrl = '${{ steps.deploy.outputs.rails_url }}';
111+
112+ // Update deployment status
113+ await github.rest.repos.createDeploymentStatus({
114+ owner: context.repo.owner,
115+ repo: context.repo.repo,
116+ deployment_id: deploymentId,
117+ state: isSuccess ? 'success' : 'failure',
118+ ...(isSuccess && { environment_url: railsUrl }),
119+ description: isSuccess ? '✅ Deployment successful' : '❌ Deployment failed'
120+ });
121+
122+ // Update comment
123+ const message = isSuccess
124+ ? `✅ Deployment successful!\n\n🚀 Rails app: ${railsUrl}\n📊 Status: ${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
125+ : `❌ Deployment failed\n\nCommit: ${context.sha.substring(0, 7)}\nWorkflow Status: ${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
126+
127+ await github.rest.issues.updateComment({
128+ owner: context.repo.owner,
129+ repo: context.repo.repo,
130+ comment_id: commentId,
131+ body: message
132+ });
0 commit comments