Skip to content

Commit a5ff8e8

Browse files
committed
restore dev deploy (#10122)
<!-- Clearly explain the need for these changes: --> <!-- Concisely describe all of the changes made in this pull request: --> - [ ] I have clearly listed my changes in the PR description - [ ] I have made a test plan - [ ] I have tested my changes according to the test plan: <!-- Put your test plan here: --> - [ ] ... <details> <summary>Example test plan</summary> - [ ] Create from scratch and execute an agent with at least 3 blocks - [ ] Import an agent from file upload, and confirm it executes correctly - [ ] Upload agent to marketplace - [ ] Import an agent from marketplace and confirm it executes correctly - [ ] Edit an agent from monitor, and confirm it executes correctly </details> - [ ] `.env.example` is updated or already compatible with my changes - [ ] `docker-compose.yml` is updated or already compatible with my changes - [ ] I have included a list of my configuration changes in the PR description (under **Changes**) <details> <summary>Examples of configuration changes</summary> - Changing ports - Adding new services that need to communicate with each other - Secrets or environment variable changes - New or infrastructure changes such as databases </details>
1 parent f881570 commit a5ff8e8

File tree

1 file changed

+35
-266
lines changed

1 file changed

+35
-266
lines changed
Lines changed: 35 additions & 266 deletions
Original file line numberDiff line numberDiff line change
@@ -1,282 +1,51 @@
1-
name: AutoGPT Platform - Dev Deploy PR Event Dispatcher
1+
name: AutoGPT Platform - Deploy Dev Environment
22

33
on:
4-
pull_request:
5-
types: [closed]
6-
issue_comment:
7-
types: [created]
4+
push:
5+
branches: [ dev ]
6+
paths:
7+
- 'autogpt_platform/**'
88

99
permissions:
10-
issues: write
11-
pull-requests: write
10+
contents: 'read'
11+
id-token: 'write'
1212

1313
jobs:
14-
dispatch:
14+
migrate:
15+
environment: develop
16+
name: Run migrations for AutoGPT Platform
1517
runs-on: ubuntu-latest
16-
steps:
17-
- name: Check comment permissions and deployment status
18-
id: check_status
19-
if: github.event_name == 'issue_comment' && github.event.issue.pull_request
20-
uses: actions/github-script@v7
21-
with:
22-
script: |
23-
const commentBody = context.payload.comment.body.trim();
24-
const commentUser = context.payload.comment.user.login;
25-
const prAuthor = context.payload.issue.user.login;
26-
const authorAssociation = context.payload.comment.author_association;
27-
const triggeringCommentId = context.payload.comment.id;
28-
29-
// Check permissions
30-
const hasPermission = (
31-
authorAssociation === 'OWNER' ||
32-
authorAssociation === 'MEMBER' ||
33-
authorAssociation === 'COLLABORATOR'
34-
);
35-
36-
core.setOutput('comment_body', commentBody);
37-
core.setOutput('has_permission', hasPermission);
38-
39-
if (!hasPermission && (commentBody === '!deploy' || commentBody === '!undeploy')) {
40-
core.setOutput('permission_denied', 'true');
41-
return;
42-
}
43-
44-
if (commentBody !== '!deploy' && commentBody !== '!undeploy') {
45-
return;
46-
}
47-
48-
// Get all comments to check deployment status
49-
const commentsResponse = await github.rest.issues.listComments({
50-
owner: context.repo.owner,
51-
repo: context.repo.repo,
52-
issue_number: context.issue.number,
53-
per_page: 100
54-
});
55-
56-
// Filter out the triggering comment
57-
const commentsData = commentsResponse.data.filter(comment => comment.id !== triggeringCommentId);
58-
59-
// Find the last deploy and undeploy commands
60-
let lastDeployIndex = -2;
61-
let lastUndeployIndex = -1;
62-
63-
console.log(`Found ${commentsResponse.data.length} total comments, using ${commentsData.length} for status check after filtering`);
64-
65-
// Iterate through comments in reverse to find the most recent commands
66-
for (let i = commentsData.length - 1; i >= 0; i--) {
67-
const currentCommentBody = commentsData[i].body.trim();
68-
console.log(`Processing comment ${i}: ${currentCommentBody}`);
69-
70-
if (currentCommentBody === '!deploy' && lastDeployIndex === -2) {
71-
lastDeployIndex = i;
72-
} else if (currentCommentBody === '!undeploy' && lastUndeployIndex === -1) {
73-
lastUndeployIndex = i;
74-
}
75-
76-
// Break early if we found both
77-
if (lastDeployIndex !== -2 && lastUndeployIndex !== -1) {
78-
break;
79-
}
80-
}
81-
82-
console.log(`Last deploy index: ${lastDeployIndex}`);
83-
console.log(`Last undeploy index: ${lastUndeployIndex}`);
84-
85-
// Currently deployed if there's a deploy command after the last undeploy
86-
const isCurrentlyDeployed = lastDeployIndex > lastUndeployIndex;
87-
88-
// Determine actions based on current state and requested command
89-
if (commentBody === '!deploy') {
90-
if (isCurrentlyDeployed) {
91-
core.setOutput('deploy_blocked', 'already_deployed');
92-
} else {
93-
core.setOutput('should_deploy', 'true');
94-
}
95-
} else if (commentBody === '!undeploy') {
96-
if (!isCurrentlyDeployed) {
97-
// Check if there was ever a deploy
98-
const hasEverDeployed = lastDeployIndex !== -2;
99-
core.setOutput('undeploy_blocked', hasEverDeployed ? 'already_undeployed' : 'never_deployed');
100-
} else {
101-
core.setOutput('should_undeploy', 'true');
102-
}
103-
}
104-
105-
core.setOutput('has_active_deployment', isCurrentlyDeployed);
106-
107-
- name: Post permission denied comment
108-
if: steps.check_status.outputs.permission_denied == 'true'
109-
uses: actions/github-script@v7
110-
with:
111-
script: |
112-
await github.rest.issues.createComment({
113-
owner: context.repo.owner,
114-
repo: context.repo.repo,
115-
issue_number: context.issue.number,
116-
body: `❌ **Permission denied**: Only the repository owners, members, or collaborators can use deployment commands.`
117-
});
118-
119-
- name: Post deploy blocked comment
120-
if: steps.check_status.outputs.deploy_blocked == 'already_deployed'
121-
uses: actions/github-script@v7
122-
with:
123-
script: |
124-
await github.rest.issues.createComment({
125-
owner: context.repo.owner,
126-
repo: context.repo.repo,
127-
issue_number: context.issue.number,
128-
body: `⚠️ **Deploy skipped**: This PR already has an active deployment. Use \`!undeploy\` first if you want to redeploy.`
129-
});
13018

131-
- name: Post undeploy blocked comment
132-
if: steps.check_status.outputs.undeploy_blocked != ''
133-
uses: actions/github-script@v7
134-
with:
135-
script: |
136-
const reason = '${{ steps.check_status.outputs.undeploy_blocked }}';
137-
let message;
138-
139-
if (reason === 'never_deployed') {
140-
message = `⚠️ **Undeploy skipped**: This PR has never been deployed. Use \`!deploy\` first.`;
141-
} else if (reason === 'already_undeployed') {
142-
message = `⚠️ **Undeploy skipped**: This PR is already undeployed.`;
143-
}
144-
145-
await github.rest.issues.createComment({
146-
owner: context.repo.owner,
147-
repo: context.repo.repo,
148-
issue_number: context.issue.number,
149-
body: message
150-
});
151-
152-
- name: Get PR details for deployment
153-
id: pr_details
154-
if: steps.check_status.outputs.should_deploy == 'true' || steps.check_status.outputs.should_undeploy == 'true'
155-
uses: actions/github-script@v7
156-
with:
157-
script: |
158-
const pr = await github.rest.pulls.get({
159-
owner: context.repo.owner,
160-
repo: context.repo.repo,
161-
pull_number: context.issue.number
162-
});
163-
core.setOutput('pr_number', pr.data.number);
164-
core.setOutput('pr_title', pr.data.title);
165-
core.setOutput('pr_state', pr.data.state);
166-
167-
- name: Dispatch Deploy Event
168-
if: steps.check_status.outputs.should_deploy == 'true'
169-
uses: peter-evans/repository-dispatch@v3
170-
with:
171-
token: ${{ secrets.DISPATCH_TOKEN }}
172-
repository: Significant-Gravitas/AutoGPT_cloud_infrastructure
173-
event-type: pr-event
174-
client-payload: |
175-
{
176-
"action": "deploy",
177-
"pr_number": "${{ steps.pr_details.outputs.pr_number }}",
178-
"pr_title": "${{ steps.pr_details.outputs.pr_title }}",
179-
"pr_state": "${{ steps.pr_details.outputs.pr_state }}",
180-
"repo": "${{ github.repository }}"
181-
}
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
18222

183-
- name: Post deploy success comment
184-
if: steps.check_status.outputs.should_deploy == 'true'
185-
uses: actions/github-script@v7
23+
- name: Set up Python
24+
uses: actions/setup-python@v5
18625
with:
187-
script: |
188-
await github.rest.issues.createComment({
189-
owner: context.repo.owner,
190-
repo: context.repo.repo,
191-
issue_number: context.issue.number,
192-
body: `🚀 **Deploying PR #${{ steps.pr_details.outputs.pr_number }}** to development environment...`
193-
});
26+
python-version: '3.11'
19427

195-
- name: Dispatch Undeploy Event (from comment)
196-
if: steps.check_status.outputs.should_undeploy == 'true'
197-
uses: peter-evans/repository-dispatch@v3
198-
with:
199-
token: ${{ secrets.DISPATCH_TOKEN }}
200-
repository: Significant-Gravitas/AutoGPT_cloud_infrastructure
201-
event-type: pr-event
202-
client-payload: |
203-
{
204-
"action": "undeploy",
205-
"pr_number": "${{ steps.pr_details.outputs.pr_number }}",
206-
"pr_title": "${{ steps.pr_details.outputs.pr_title }}",
207-
"pr_state": "${{ steps.pr_details.outputs.pr_state }}",
208-
"repo": "${{ github.repository }}"
209-
}
28+
- name: Install Python dependencies
29+
run: |
30+
python -m pip install --upgrade pip
31+
pip install prisma
21032
211-
- name: Post undeploy success comment
212-
if: steps.check_status.outputs.should_undeploy == 'true'
213-
uses: actions/github-script@v7
214-
with:
215-
script: |
216-
await github.rest.issues.createComment({
217-
owner: context.repo.owner,
218-
repo: context.repo.repo,
219-
issue_number: context.issue.number,
220-
body: `🗑️ **Undeploying PR #${{ steps.pr_details.outputs.pr_number }}** from development environment...`
221-
});
33+
- name: Run Backend Migrations
34+
working-directory: ./autogpt_platform/backend
35+
run: |
36+
python -m prisma migrate deploy
37+
env:
38+
DATABASE_URL: ${{ secrets.BACKEND_DATABASE_URL }}
39+
DIRECT_URL: ${{ secrets.BACKEND_DATABASE_URL }}
22240

223-
- name: Check deployment status on PR close
224-
id: check_pr_close
225-
if: github.event_name == 'pull_request' && github.event.action == 'closed'
226-
uses: actions/github-script@v7
227-
with:
228-
script: |
229-
const comments = await github.rest.issues.listComments({
230-
owner: context.repo.owner,
231-
repo: context.repo.repo,
232-
issue_number: context.issue.number
233-
});
234-
235-
let lastDeployIndex = -1;
236-
let lastUndeployIndex = -1;
237-
238-
comments.data.forEach((comment, index) => {
239-
if (comment.body.trim() === '!deploy') {
240-
lastDeployIndex = index;
241-
} else if (comment.body.trim() === '!undeploy') {
242-
lastUndeployIndex = index;
243-
}
244-
});
245-
246-
// Should undeploy if there's a !deploy without a subsequent !undeploy
247-
const shouldUndeploy = lastDeployIndex !== -1 && lastDeployIndex > lastUndeployIndex;
248-
core.setOutput('should_undeploy', shouldUndeploy);
249-
250-
- name: Dispatch Undeploy Event (PR closed with active deployment)
251-
if: >-
252-
github.event_name == 'pull_request' &&
253-
github.event.action == 'closed' &&
254-
steps.check_pr_close.outputs.should_undeploy == 'true'
41+
trigger:
42+
needs: migrate
43+
runs-on: ubuntu-latest
44+
steps:
45+
- name: Trigger deploy workflow
25546
uses: peter-evans/repository-dispatch@v3
25647
with:
257-
token: ${{ secrets.DISPATCH_TOKEN }}
48+
token: ${{ secrets.DEPLOY_TOKEN }}
25849
repository: Significant-Gravitas/AutoGPT_cloud_infrastructure
259-
event-type: pr-event
260-
client-payload: |
261-
{
262-
"action": "undeploy",
263-
"pr_number": "${{ github.event.pull_request.number }}",
264-
"pr_title": "${{ github.event.pull_request.title }}",
265-
"pr_state": "${{ github.event.pull_request.state }}",
266-
"repo": "${{ github.repository }}"
267-
}
268-
269-
- name: Post PR close undeploy comment
270-
if: >-
271-
github.event_name == 'pull_request' &&
272-
github.event.action == 'closed' &&
273-
steps.check_pr_close.outputs.should_undeploy == 'true'
274-
uses: actions/github-script@v7
275-
with:
276-
script: |
277-
await github.rest.issues.createComment({
278-
owner: context.repo.owner,
279-
repo: context.repo.repo,
280-
issue_number: context.issue.number,
281-
body: `🧹 **Auto-undeploying**: PR closed with active deployment. Cleaning up development environment for PR #${{ github.event.pull_request.number }}.`
282-
});
50+
event-type: build_deploy_dev
51+
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}", "repository": "${{ github.repository }}"}'

0 commit comments

Comments
 (0)