Skip to content

Commit 85a230d

Browse files
committed
.
1 parent 29c00f2 commit 85a230d

File tree

7 files changed

+208
-44
lines changed

7 files changed

+208
-44
lines changed

action.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,20 @@ inputs:
5252
The URL of the Supabase deployment service. See
5353
https://github.com/pawtograder/supabase-coolify-deployment
5454
required: true
55+
cleanup_service_uuid:
56+
description:
57+
The UUID of the service to clean up. This is used to clean up the
58+
deployment after the deployment is complete.
59+
required: false
60+
default: ''
61+
type: string
62+
cleanup_app_uuid:
63+
description:
64+
The UUID of the app to clean up. This is used to clean up the deployment
65+
after the deployment is complete.
66+
required: false
67+
default: ''
68+
type: string
5569

5670
# Define your outputs here.
5771
outputs:

dist/index.js

Lines changed: 87 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 30 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"@types/ws": "^8.18.1",
5757
"@typescript-eslint/eslint-plugin": "^8.33.1",
5858
"@typescript-eslint/parser": "^8.32.1",
59+
"dotenv": "^17.0.1",
5960
"eslint": "^9.28.0",
6061
"eslint-config-prettier": "^10.1.5",
6162
"eslint-import-resolver-typescript": "^4.4.3",

src/coolify.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
createEnvByServiceUuid,
1313
createPrivateGithubAppApplication,
1414
createService,
15+
deleteServiceByUuid,
16+
deleteApplicationByUuid,
1517
getApplicationByUuid,
1618
getServiceByUuid,
1719
listApplications,
@@ -26,7 +28,7 @@ import {
2628
import { TCPTunnelClient } from './tcp-tunnel.js'
2729

2830
export default class Coolify {
29-
private readonly client: Client
31+
readonly client: Client
3032
private readonly project_uuid: string
3133
private readonly environment_uuid: string
3234
private readonly environment_name: string
@@ -370,6 +372,44 @@ export default class Coolify {
370372
deploymentKey
371373
}
372374
}
375+
async cleanup({
376+
cleanup_service_uuid,
377+
cleanup_app_uuid
378+
}: {
379+
cleanup_service_uuid: string
380+
cleanup_app_uuid: string
381+
}) {
382+
const existingServices = await listServices({ client: this.client })
383+
const existingSupabaseService = existingServices.data?.find(
384+
(service) => service.uuid === cleanup_service_uuid
385+
)
386+
if (existingSupabaseService && existingSupabaseService.uuid) {
387+
await deleteServiceByUuid({
388+
client: this.client,
389+
path: {
390+
uuid: existingSupabaseService.uuid
391+
}
392+
})
393+
} else {
394+
console.log(`Supabase service ${cleanup_service_uuid} not found`)
395+
}
396+
const existingApplications = await listApplications({
397+
client: this.client
398+
})
399+
const frontendApp = existingApplications.data?.find(
400+
(app) => app.uuid === cleanup_app_uuid
401+
)
402+
if (frontendApp && frontendApp.uuid) {
403+
await deleteApplicationByUuid({
404+
client: this.client,
405+
path: {
406+
uuid: frontendApp.uuid
407+
}
408+
})
409+
} else {
410+
console.log(`Frontend app ${cleanup_app_uuid} not found`)
411+
}
412+
}
373413
async createDeployment({
374414
ephemeral,
375415
checkedOutProjectDir,

src/main.ts

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export async function run() {
1313
const ephemeral = getInput('ephemeral')
1414
const base_deployment_url = getInput('base_deployment_url')
1515
const deployment_app_uuid = getInput('deployment_app_uuid')
16+
const cleanup_service_uuid = getInput('cleanup_service_uuid')
17+
const cleanup_app_uuid = getInput('cleanup_app_uuid')
1618

1719
const coolify = new Coolify({
1820
baseUrl: coolify_api_url,
@@ -31,29 +33,37 @@ export async function run() {
3133
throw new Error('GITHUB_REF_NAME and GITHUB_REPOSITORY must be set')
3234
}
3335

34-
const deploymentName = ephemeral
35-
? `${branchOrPR}-${randomUUID()}`
36-
: branchOrPR
36+
const deploymentName =
37+
ephemeral.toLowerCase() === 'true'
38+
? `${branchOrPR}-${randomUUID()}`
39+
: branchOrPR
3740

38-
const {
39-
serviceUUID,
40-
appUUID,
41-
appURL,
42-
supabase_url,
43-
supabase_service_role_key,
44-
supabase_anon_key
45-
} = await coolify.createDeployment({
46-
ephemeral: ephemeral === 'true',
47-
checkedOutProjectDir: './',
48-
deploymentName,
49-
repository: repositoryName,
50-
gitBranch: branchOrPR,
51-
gitCommitSha: process.env.GITHUB_SHA
52-
})
53-
setOutput('supabase_url', supabase_url)
54-
setOutput('supabase_service_role_key', supabase_service_role_key)
55-
setOutput('supabase_anon_key', supabase_anon_key)
56-
setOutput('app_url', appURL)
57-
setOutput('service_uuid', serviceUUID)
58-
setOutput('app_uuid', appUUID)
41+
if (cleanup_service_uuid || cleanup_app_uuid) {
42+
await coolify.cleanup({
43+
cleanup_service_uuid,
44+
cleanup_app_uuid
45+
})
46+
} else {
47+
const {
48+
serviceUUID,
49+
appUUID,
50+
appURL,
51+
supabase_url,
52+
supabase_service_role_key,
53+
supabase_anon_key
54+
} = await coolify.createDeployment({
55+
ephemeral: ephemeral === 'true',
56+
checkedOutProjectDir: './',
57+
deploymentName,
58+
repository: repositoryName,
59+
gitBranch: branchOrPR,
60+
gitCommitSha: process.env.GITHUB_SHA
61+
})
62+
setOutput('supabase_url', supabase_url)
63+
setOutput('supabase_service_role_key', supabase_service_role_key)
64+
setOutput('supabase_anon_key', supabase_anon_key)
65+
setOutput('app_url', appURL)
66+
setOutput('service_uuid', serviceUUID)
67+
setOutput('app_uuid', appUUID)
68+
}
5969
}

0 commit comments

Comments
 (0)