Skip to content

Commit 27d1750

Browse files
committed
fixes
1 parent 45b512c commit 27d1750

File tree

1 file changed

+23
-86
lines changed

1 file changed

+23
-86
lines changed

.github/workflows/deploy-to-control-plane.yml

+23-86
Original file line numberDiff line numberDiff line change
@@ -106,24 +106,36 @@ jobs:
106106
run: |
107107
if ! cpflow exists -a ${{ env.APP_NAME }}; then
108108
echo "No review app exists for this PR"
109-
exit 0
109+
echo "app_exists=false" >> $GITHUB_OUTPUT
110+
if [[ "${{ github.event_name }}" == "push" ]]; then
111+
exit 0
112+
fi
110113
fi
111114
echo "app_exists=true" >> $GITHUB_OUTPUT
112115
113116
- name: Validate Deployment Request
114117
id: validate
115118
run: |
116-
if [[ "${{ github.event_name }}" == "pull_request" && "${{ steps.check-app.outputs.app_exists }}" == "true" ]] || \
117-
[[ "${{ github.event_name }}" == "workflow_dispatch" ]] || \
118-
[[ "${{ github.event_name }}" == "issue_comment" && "${{ github.event.comment.body }}" == "/deploy-review-app" ]] || \
119-
[[ "${{ github.event_name }}" == "push" ]]; then
120-
echo "SHOULD_DEPLOY=true" >> $GITHUB_ENV
121-
else
122-
echo "SHOULD_DEPLOY=false" >> $GITHUB_ENV
119+
if ! [[ "${{ github.event_name }}" == "workflow_dispatch" || \
120+
("${{ github.event_name }}" == "issue_comment" && "${{ github.event.comment.body }}" == "/deploy-review-app") || \
121+
"${{ github.event_name }}" == "push" ]]; then
123122
echo "Skipping deployment - not a valid trigger (event: ${{ github.event_name }})"
124123
exit 0
125124
fi
126125
126+
- name: Create Initial Comment
127+
id: create-comment
128+
uses: actions/github-script@v7
129+
with:
130+
script: |
131+
const result = await github.rest.issues.createComment({
132+
owner: context.repo.owner,
133+
repo: context.repo.repo,
134+
issue_number: process.env.PR_NUMBER,
135+
body: '🚀 Starting deployment process...\n\n' + process.env.CONSOLE_LINK
136+
});
137+
core.setOutput('comment-id', result.data.id);
138+
127139
- name: Set Deployment URLs
128140
id: set-urls
129141
uses: actions/github-script@v7
@@ -146,81 +158,6 @@ jobs:
146158
'https://console.cpln.io/console/org/' + process.env.CPLN_ORG + '/gvc/' + process.env.APP_NAME + '/-info)'
147159
);
148160
149-
- name: Create Initial Comment
150-
id: create-comment
151-
uses: actions/github-script@v7
152-
with:
153-
script: |
154-
const result = await github.rest.issues.createComment({
155-
owner: context.repo.owner,
156-
repo: context.repo.repo,
157-
issue_number: process.env.PR_NUMBER,
158-
body: '🚀 Deploying Review App...\n\n' + process.env.CONSOLE_LINK
159-
});
160-
return result.data.id;
161-
162-
- name: Set Comment ID
163-
run: echo "COMMENT_ID=${{ fromJSON(steps.create-comment.outputs.result).commentId }}" >> $GITHUB_ENV
164-
165-
- name: Initialize Deployment
166-
id: init-deployment
167-
uses: actions/github-script@v7
168-
with:
169-
script: |
170-
async function getWorkflowUrl(runId) {
171-
const jobs = await github.rest.actions.listJobsForWorkflowRun({
172-
owner: context.repo.owner,
173-
repo: context.repo.repo,
174-
run_id: runId
175-
});
176-
177-
const currentJob = jobs.data.jobs.find(job => job.status === 'in_progress');
178-
const jobId = currentJob?.id;
179-
180-
if (!jobId) {
181-
console.log('Warning: Could not find current job ID');
182-
return `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`;
183-
}
184-
185-
return `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}/job/${jobId}`;
186-
}
187-
188-
// Create initial deployment comment
189-
const comment = await github.rest.issues.createComment({
190-
owner: context.repo.owner,
191-
repo: context.repo.repo,
192-
issue_number: process.env.PR_NUMBER,
193-
body: '⏳ Initializing deployment...'
194-
});
195-
196-
// Create GitHub deployment
197-
const deployment = await github.rest.repos.createDeployment({
198-
owner: context.repo.owner,
199-
repo: context.repo.repo,
200-
ref: context.sha,
201-
environment: 'review',
202-
auto_merge: false,
203-
required_contexts: []
204-
});
205-
206-
const workflowUrl = await getWorkflowUrl(context.runId);
207-
208-
return {
209-
deploymentId: deployment.data.id,
210-
commentId: comment.data.id,
211-
workflowUrl
212-
};
213-
214-
- name: Set comment ID and workflow URL
215-
run: |
216-
echo "COMMENT_ID=${{ fromJSON(steps.init-deployment.outputs.result).commentId }}" >> $GITHUB_ENV
217-
echo "WORKFLOW_URL=${{ fromJSON(steps.init-deployment.outputs.result).workflowUrl }}" >> $GITHUB_ENV
218-
219-
- name: Set commit hash
220-
run: |
221-
FULL_COMMIT="${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || steps.getRef.outputs.PR_SHA || github.sha }}"
222-
echo "COMMIT_HASH=${FULL_COMMIT:0:7}" >> $GITHUB_ENV
223-
224161
- name: Update Status - Building
225162
uses: actions/github-script@v7
226163
with:
@@ -237,7 +174,7 @@ jobs:
237174
await github.rest.issues.updateComment({
238175
owner: context.repo.owner,
239176
repo: context.repo.repo,
240-
comment_id: process.env.COMMENT_ID,
177+
comment_id: ${{ steps.create-comment.outputs.comment-id }},
241178
body: buildingMessage
242179
});
243180
@@ -269,7 +206,7 @@ jobs:
269206
await github.rest.issues.updateComment({
270207
owner: context.repo.owner,
271208
repo: context.repo.repo,
272-
comment_id: process.env.COMMENT_ID,
209+
comment_id: ${{ steps.create-comment.outputs.comment-id }},
273210
body: deployingMessage
274211
});
275212
@@ -329,6 +266,6 @@ jobs:
329266
await github.rest.issues.updateComment({
330267
owner: context.repo.owner,
331268
repo: context.repo.repo,
332-
comment_id: process.env.COMMENT_ID,
269+
comment_id: ${{ steps.create-comment.outputs.comment-id }},
333270
body: isSuccess ? successMessage : failureMessage
334271
});

0 commit comments

Comments
 (0)