Skip to content

Commit 28a6761

Browse files
committed
Revert "Enhance GitHub Actions workflows for pull request and issue management (#617)"
This reverts commit 4bf2c03.
1 parent 7b1b010 commit 28a6761

4 files changed

+220
-181
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,20 @@
1-
name: Add Comment on PR Creation
1+
name: Add helper Comment on PR creation
22

33
on:
44
pull_request:
55
types: [opened]
66

77
jobs:
8-
add-comment:
8+
comment-on-pr:
99
runs-on: ubuntu-latest
10-
permissions:
11-
pull-requests: write
1210
steps:
13-
name: Add GitHub Comment for review app instructions
11+
- name: Add GitHub Comment for review app instructions
1412
uses: actions/github-script@v7
1513
with:
1614
script: |
17-
await github.rest.issues.createComment({
15+
github.rest.issues.createComment({
16+
issue_number: context.issue.number,
1817
owner: context.repo.owner,
1918
repo: context.repo.repo,
20-
issue_number: context.payload.pull_request.number,
21-
body: [
22-
"Hi 👋 Here are the commands available for this PR:",
23-
"",
24-
"- `/deploy-review-app`: Deploy your changes to a review environment",
25-
"- `/delete-review-app`: Clean up the review environment when you're done",
26-
"- `/help`: Show detailed information about all commands",
27-
"",
28-
"Use `/help` to see full documentation, including configuration options."
29-
].join("\n")
30-
});
19+
body: "Hi 👋 To deploy a review app, please comment `/deploy-review-app`"
20+
})
+34-95
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
name: Delete Review App
22

33
on:
4-
pull_request:
5-
types: [closed]
64
issue_comment:
75
types: [created]
86

@@ -15,17 +13,33 @@ permissions:
1513
env:
1614
CPLN_ORG: ${{ secrets.CPLN_ORG }}
1715
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN }}
18-
APP_NAME: qa-react-webpack-rails-tutorial-pr-${{ github.event.pull_request.number || github.event.issue.number }}
19-
PR_NUMBER: ${{ github.event.pull_request.number || github.event.issue.number }}
16+
APP_NAME: qa-react-webpack-rails-tutorial-pr-${{ github.event.issue.number }}
17+
PR_NUMBER: ${{ github.event.issue.number }}
2018

2119
jobs:
20+
debug-trigger:
21+
if: always()
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Debug Trigger Conditions
25+
env:
26+
EVENT_NAME: ${{ github.event_name }}
27+
IS_PR: ${{ toJSON(github.event.issue.pull_request) }}
28+
COMMENT: ${{ github.event.comment.body }}
29+
run: |
30+
echo "Debug information for delete-review-app command:"
31+
echo "Event name: $EVENT_NAME"
32+
echo "Is PR (raw): $IS_PR"
33+
echo "Comment body: $COMMENT"
34+
echo "Raw event payload:"
35+
echo '${{ toJSON(github.event) }}'
36+
2237
Process-Delete-Command:
38+
needs: debug-trigger
2339
if: |
24-
(github.event_name == 'issue_comment' &&
25-
github.event.issue.pull_request &&
26-
github.event.comment.body == '/delete-review-app') ||
27-
(github.event_name == 'pull_request' &&
28-
github.event.action == 'closed')
40+
github.event_name == 'issue_comment' &&
41+
github.event.issue.pull_request &&
42+
github.event.comment.body == '/delete-review-app'
2943
runs-on: ubuntu-latest
3044

3145
steps:
@@ -41,91 +55,23 @@ jobs:
4155
done
4256
4357
if [ ${#missing_secrets[@]} -ne 0 ]; then
44-
echo "Required secrets are not set: ${missing_secrets[*]}"
58+
echo " Required secrets are not set: ${missing_secrets[*]}"
4559
exit 1
4660
fi
4761
4862
- name: Setup Environment
4963
uses: ./.github/actions/setup-environment
5064

51-
- name: Set shared functions
52-
id: shared-functions
53-
uses: actions/github-script@v7
54-
with:
55-
script: |
56-
core.exportVariable('GET_CONSOLE_LINK', `
57-
function getConsoleLink(prNumber) {
58-
return ' [Control Plane Console for Review App with PR #' + prNumber + '](' +
59-
'https://console.cpln.io/org/' + process.env.CPLN_ORG + '/workloads/' + process.env.APP_NAME + ')';
60-
}
61-
`);
62-
63-
- name: Initialize Delete
64-
id: init-delete
65-
uses: actions/github-script@v7
66-
with:
67-
script: |
68-
eval(process.env.GET_CONSOLE_LINK);
69-
70-
async function getWorkflowUrl(runId) {
71-
// Get the current job ID
72-
const jobs = await github.rest.actions.listJobsForWorkflowRun({
73-
owner: context.repo.owner,
74-
repo: context.repo.repo,
75-
run_id: runId
76-
});
77-
78-
const currentJob = jobs.data.jobs.find(job => job.status === 'in_progress');
79-
const jobId = currentJob?.id;
80-
81-
if (!jobId) {
82-
console.log('Warning: Could not find current job ID');
83-
return `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`;
84-
}
85-
86-
return `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}/job/${jobId}`;
87-
}
88-
89-
const workflowUrl = await getWorkflowUrl(context.runId);
90-
91-
const comment = await github.rest.issues.createComment({
92-
issue_number: process.env.PR_NUMBER,
93-
owner: context.repo.owner,
94-
repo: context.repo.repo,
95-
body: [
96-
' Starting app deletion...',
97-
'',
98-
' [View Delete Logs](' + workflowUrl + ')',
99-
'',
100-
getConsoleLink(process.env.PR_NUMBER)
101-
].join('\n')
102-
});
103-
104-
return {
105-
commentId: comment.data.id,
106-
workflowUrl
107-
};
108-
109-
- name: Set workflow URL
110-
run: |
111-
echo "WORKFLOW_URL=${{ fromJSON(steps.init-delete.outputs.result).workflowUrl }}" >> $GITHUB_ENV
112-
11365
- name: Create Initial Delete Comment
11466
id: init-delete
11567
uses: actions/github-script@v7
11668
with:
11769
script: |
118-
let message = '🗑️ Starting app deletion';
119-
if ('${{ github.event_name }}' === 'pull_request') {
120-
const merged = '${{ github.event.pull_request.merged }}' === 'true';
121-
message += merged ? ' (PR merged)' : ' (PR closed)';
122-
}
123-
12470
const comment = await github.rest.issues.createComment({
12571
issue_number: process.env.PR_NUMBER,
12672
owner: context.repo.owner,
12773
repo: context.repo.repo,
128-
body: message
74+
body: ' Starting app deletion...'
12975
});
13076
return { commentId: comment.data.id };
13177
@@ -143,28 +89,21 @@ jobs:
14389
uses: actions/github-script@v7
14490
with:
14591
script: |
146-
eval(process.env.GET_CONSOLE_LINK);
147-
14892
const success = '${{ job.status }}' === 'success';
14993
const prNumber = process.env.PR_NUMBER;
94+
const cpConsoleUrl = `https://console.cpln.io/org/${process.env.CPLN_ORG}/workloads/${process.env.APP_NAME}`;
15095
151-
const successMessage = [
152-
'✅ Review app for PR #' + prNumber + ' was successfully deleted',
153-
'',
154-
' [View Completed Delete Logs](' + process.env.WORKFLOW_URL + ')'
155-
].join('\n');
156-
157-
const failureMessage = [
158-
'❌ Review app for PR #' + prNumber + ' failed to be deleted',
159-
'',
160-
' [View Delete Logs with Errors](' + process.env.WORKFLOW_URL + ')',
161-
'',
162-
getConsoleLink(prNumber)
163-
].join('\n');
96+
const message = success
97+
? ' Review app for PR #' + prNumber + ' was successfully deleted'
98+
: [
99+
' Review app for PR #' + prNumber + ' failed to be deleted',
100+
'',
101+
'[Control Plane Console for Review App with PR #' + prNumber + '](' + cpConsoleUrl + ')'
102+
].join('\n');
164103
165104
await github.rest.issues.updateComment({
166105
owner: context.repo.owner,
167106
repo: context.repo.repo,
168107
comment_id: ${{ fromJSON(steps.init-delete.outputs.result).commentId }},
169-
body: success ? successMessage : failureMessage
108+
body: message
170109
});

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

+112-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
(github.event_name == 'pull_request') ||
2626
(github.event_name == 'issue_comment' &&
2727
github.event.issue.pull_request &&
28-
github.event.comment.body == '/deploy-review-app')
28+
github.event.comment.body == '/deploy')
2929
runs-on: ubuntu-latest
3030
permissions:
3131
contents: read
@@ -252,7 +252,25 @@ jobs:
252252
body: isSuccess ? successMessage : failureMessage
253253
});
254254
255+
debug-help:
256+
if: always()
257+
runs-on: ubuntu-latest
258+
steps:
259+
- name: Debug Trigger Conditions
260+
env:
261+
EVENT_NAME: ${{ github.event_name }}
262+
IS_PR: ${{ toJSON(github.event.issue.pull_request) }}
263+
COMMENT: ${{ github.event.comment.body }}
264+
run: |
265+
echo "Debug information for help command:"
266+
echo "Event name: $EVENT_NAME"
267+
echo "Is PR (raw): $IS_PR"
268+
echo "Comment body: $COMMENT"
269+
echo "Raw event payload:"
270+
echo '${{ toJSON(github.event) }}'
271+
255272
show-help:
273+
needs: debug-help
256274
if: |
257275
github.event_name == 'issue_comment' &&
258276
github.event.issue.pull_request &&
@@ -267,7 +285,7 @@ jobs:
267285
const helpMessage = [
268286
'## Available Commands',
269287
'',
270-
'### `/deploy-review-app`',
288+
'### `/deploy`',
271289
'Deploys your PR branch to a review environment on Control Plane.',
272290
'- Creates a new review app if one doesn\'t exist',
273291
'- Updates the existing review app if it already exists',
@@ -278,7 +296,7 @@ jobs:
278296
'Deletes the review app associated with this PR.',
279297
'- Removes all resources from Control Plane',
280298
'- Helpful for cleaning up when you\'re done testing',
281-
'- Can be re-deployed later using `/deploy-review-app`',
299+
'- Can be re-deployed later using `/deploy`',
282300
'',
283301
'### `/help`',
284302
'Shows this help message explaining available commands.',
@@ -292,4 +310,95 @@ jobs:
292310
repo: context.repo.repo,
293311
issue_number: context.payload.issue.number,
294312
body: helpMessage
313+
});
314+
315+
debug-delete:
316+
if: always()
317+
runs-on: ubuntu-latest
318+
steps:
319+
- name: Debug Trigger Conditions
320+
env:
321+
EVENT_NAME: ${{ github.event_name }}
322+
IS_PR: ${{ toJSON(github.event.issue.pull_request) }}
323+
COMMENT: ${{ github.event.comment.body }}
324+
run: |
325+
echo "Debug information for delete-review-app command:"
326+
echo "Event name: $EVENT_NAME"
327+
echo "Is PR (raw): $IS_PR"
328+
echo "Comment body: $COMMENT"
329+
echo "Raw event payload:"
330+
echo '${{ toJSON(github.event) }}'
331+
332+
Process-Delete-Command:
333+
needs: debug-delete
334+
if: |
335+
github.event_name == 'issue_comment' &&
336+
github.event.issue.pull_request &&
337+
github.event.comment.body == '/delete-review-app'
338+
runs-on: ubuntu-latest
339+
340+
steps:
341+
- uses: actions/checkout@v4
342+
343+
- name: Validate Required Secrets
344+
run: |
345+
missing_secrets=()
346+
for secret in "CPLN_TOKEN" "CPLN_ORG"; do
347+
if [ -z "${!secret}" ]; then
348+
missing_secrets+=("$secret")
349+
fi
350+
done
351+
352+
if [ ${#missing_secrets[@]} -ne 0 ]; then
353+
echo "Required secrets are not set: ${missing_secrets[*]}"
354+
exit 1
355+
fi
356+
357+
- name: Setup Environment
358+
uses: ./.github/actions/setup-environment
359+
360+
- name: Create Initial Delete Comment
361+
id: init-delete
362+
uses: actions/github-script@v7
363+
with:
364+
script: |
365+
const comment = await github.rest.issues.createComment({
366+
issue_number: process.env.PR_NUMBER,
367+
owner: context.repo.owner,
368+
repo: context.repo.repo,
369+
body: ' Starting app deletion...'
370+
});
371+
return { commentId: comment.data.id };
372+
373+
- name: Delete Review App
374+
uses: ./.github/actions/delete-control-plane-app
375+
with:
376+
app_name: ${{ env.APP_NAME }}
377+
org: ${{ env.CPLN_ORG }}
378+
github_token: ${{ secrets.GITHUB_TOKEN }}
379+
env:
380+
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN }}
381+
382+
- name: Update Delete Status
383+
if: always()
384+
uses: actions/github-script@v7
385+
with:
386+
script: |
387+
const success = '${{ job.status }}' === 'success';
388+
const prNumber = process.env.PR_NUMBER;
389+
const cpConsoleUrl = `https://console.cpln.io/org/${process.env.CPLN_ORG}/workloads/${process.env.APP_NAME}`;
390+
391+
const message = success
392+
? ' Review app for PR #' + prNumber + ' was successfully deleted'
393+
: [
394+
' Review app for PR #' + prNumber + ' failed to be deleted',
395+
'',
396+
' [Control Plane Console for Review App with PR #' + prNumber + '](' + cpConsoleUrl + ')'
397+
].join('\n');
398+
399+
await github.rest.issues.updateComment({
400+
owner: context.repo.owner,
401+
repo: context.repo.repo,
402+
comment_id: ${{ fromJSON(steps.init-delete.outputs.result).commentId }},
403+
body: message
295404
});

0 commit comments

Comments
 (0)