16
16
CPLN_ORG : ${{secrets.CPLN_ORG_STAGING}}
17
17
CPLN_TOKEN : ${{secrets.CPLN_TOKEN_STAGING}}
18
18
PR_NUMBER : ${{ github.event.pull_request.number || github.event.issue.number }}
19
- STATUS_URL : ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/job/${{ steps.get_job_id.outputs.job_id }}?pr=${{ github.event.pull_request.number || github.event.issue.number }}
20
19
21
20
jobs :
22
21
check-concurrent :
@@ -55,43 +54,36 @@ jobs:
55
54
deployment_id : ${{ steps.create-deployment.outputs.result }}
56
55
57
56
steps :
58
- - name : Get job ID
59
- id : get_job_id
57
+ - name : Create initial comment and get job URL
58
+ id : init
60
59
uses : actions/github-script@v7
61
60
with :
62
61
script : |
62
+ // Get the job ID from the Actions API
63
63
const { data: jobs } = await github.rest.actions.listJobsForWorkflowRun({
64
64
owner: context.repo.owner,
65
65
repo: context.repo.repo,
66
66
run_id: context.runId,
67
67
});
68
68
69
69
const currentJob = jobs.jobs.find(job => job.name === context.job);
70
- const jobId = currentJob.id;
71
-
72
- return jobId;
73
-
74
- - name : Create comment
75
- id : create-comment
76
- uses : actions/github-script@v7
77
- env :
78
- JOB_ID : ${{ steps.get_job_id.outputs.result }}
79
- with :
80
- script : |
81
- async function createComment(message) {
82
- await github.rest.issues.createComment({
83
- issue_number: context.issue.number || context.payload.pull_request.number,
84
- owner: context.repo.owner,
85
- repo: context.repo.repo,
86
- body: message
87
- });
70
+ if (!currentJob) {
71
+ throw new Error('Could not find current job in the workflow run');
88
72
}
89
73
74
+ const statusUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/job/${currentJob.id}?pr=${context.issue.number || context.payload.pull_request.number}`;
75
+ core.exportVariable('statusUrl', statusUrl);
76
+
90
77
const message = `🚀 Starting new deployment for commit: ${context.sha.substring(0, 7)}
91
78
${context.payload.commits ? `\nChanges: ${context.payload.commits[0].message}` : ''}
92
- Status: ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/job/${JOB_ID}?pr=${context.issue.number || context.payload.pull_request.number }`;
79
+ Status: ${statusUrl }`;
93
80
94
- await createComment(message);
81
+ await github.rest.issues.createComment({
82
+ issue_number: context.issue.number || context.payload.pull_request.number,
83
+ owner: context.repo.owner,
84
+ repo: context.repo.repo,
85
+ body: message
86
+ });
95
87
96
88
- name : Create GitHub Deployment
97
89
id : create-deployment
@@ -148,7 +140,7 @@ jobs:
148
140
app_name : ${{ env.APP_NAME }}
149
141
org : ${{ env.CPLN_ORG }}
150
142
151
- - name : Update deployment status ( success)
143
+ - name : Update deployment status success
152
144
if : success()
153
145
uses : actions/github-script@v7
154
146
with :
@@ -157,9 +149,14 @@ jobs:
157
149
Environment: review-app
158
150
Commit: ${context.sha.substring(0, 7)}
159
151
URL: ${{ steps.deploy.outputs.app_url }}
160
- Status: ${{ env.STATUS_URL } }`;
152
+ Status: ${process. env.statusUrl }`;
161
153
162
- await eval(process.env.createComment)(message);
154
+ await github.rest.issues.createComment({
155
+ issue_number: context.issue.number || context.payload.pull_request.number,
156
+ owner: context.repo.owner,
157
+ repo: context.repo.repo,
158
+ body: message
159
+ });
163
160
164
161
await github.rest.repos.createDeploymentStatus({
165
162
owner: context.repo.owner,
@@ -170,16 +167,21 @@ jobs:
170
167
description: 'Deployment successful'
171
168
});
172
169
173
- - name : Update deployment status ( failure)
170
+ - name : Update deployment status failure
174
171
if : failure()
175
172
uses : actions/github-script@v7
176
173
with :
177
174
script : |
178
175
const message = `❌ Deployment failed
179
176
Commit: ${context.sha.substring(0, 7)}
180
- Status: ${{ env.STATUS_URL } }`;
177
+ Status: ${process. env.statusUrl }`;
181
178
182
- await eval(process.env.createComment)(message);
179
+ await github.rest.issues.createComment({
180
+ issue_number: context.issue.number || context.payload.pull_request.number,
181
+ owner: context.repo.owner,
182
+ repo: context.repo.repo,
183
+ body: message
184
+ });
183
185
184
186
await github.rest.repos.createDeploymentStatus({
185
187
owner: context.repo.owner,
0 commit comments