Some checks failed
Deploy analytics worker / Deploy analytics worker to ${{ (github.ref == 'refs/heads/production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Failing after 1s
i18n upload strings / Upload latest strings (push) Failing after 1s
Deploy bemo / Deploy bemo to ${{ (github.ref == 'refs/heads/bemo-production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Failing after 1s
Deploy grafana resources / ${{ github.event_name == 'push' && 'Deploy grafana resources' || 'Validate grafana resources (dry run)' }} (push) Failing after 0s
End to end tests (dotcom) / Check for relevant changes (push) Failing after 0s
End to end tests (examples) / Check for relevant changes (push) Failing after 0s
End to end tests (mermaid readability) / Check for relevant changes (push) Failing after 1s
End to end tests (perf) / Check for relevant changes (push) Failing after 0s
Publish editor extensions / Publish editor extensions (push) Failing after 1s
Publish SDK packages / Remove the publish-packages label (push) Has been skipped
Checks / Tests & checks (push) Has been cancelled
Checks / Build all projects (push) Has been cancelled
Deploy templates / Deploy templates (push) Has been cancelled
End to end tests (dotcom) / End to end tests (dotcom) (push) Has been cancelled
End to end tests (mermaid readability) / End to end tests (mermaid readability) (push) Has been cancelled
End to end tests (perf) / End to end tests (perf) (push) Has been cancelled
Deploy .com / Deploy dotcom to ${{ (github.ref == 'refs/heads/production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Has been cancelled
End to end tests (examples) / End to end tests (examples) (push) Has been cancelled
Publish SDK packages / Publish SDK packages (push) Has been cancelled
Publish SDK packages / Tell user released version (push) Has been cancelled
Publish SDK packages / Publishes code templates to separate repositories (push) Has been cancelled
Publish SDK packages / Deploys the template demos with the new SDK version (push) Has been cancelled
73 lines
1.9 KiB
TypeScript
73 lines
1.9 KiB
TypeScript
import { DeleteObjectCommand, S3Client } from '@aws-sdk/client-s3'
|
|
import { Client } from 'pg'
|
|
import { makeEnv } from '../lib/makeEnv'
|
|
|
|
const env = makeEnv([
|
|
'CLOUDFLARE_ACCOUNT_ID',
|
|
'R2_ACCESS_KEY_ID',
|
|
'R2_ACCESS_KEY_SECRET',
|
|
'SUPABASE_STAGING_DB_URL',
|
|
'STAGING_OWNER_ID',
|
|
])
|
|
|
|
const R2_URL = `https://${env.CLOUDFLARE_ACCOUNT_ID}.r2.cloudflarestorage.com`
|
|
const R2_STAGING_BUCKET = 'rooms-preview'
|
|
|
|
const R2 = new S3Client({
|
|
region: 'auto',
|
|
endpoint: R2_URL,
|
|
credentials: {
|
|
accessKeyId: env.R2_ACCESS_KEY_ID,
|
|
secretAccessKey: env.R2_ACCESS_KEY_SECRET,
|
|
},
|
|
})
|
|
|
|
async function cleanupTestFiles() {
|
|
const stagingClient = new Client({
|
|
connectionString: env.SUPABASE_STAGING_DB_URL,
|
|
})
|
|
await stagingClient.connect()
|
|
|
|
try {
|
|
const selectQuery = `SELECT id FROM file WHERE file."owningGroupId" = $1 AND id LIKE 'test_%'`
|
|
const selectResult = await stagingClient.query(selectQuery, [env.STAGING_OWNER_ID])
|
|
|
|
const fileIds = selectResult.rows.map((row: any) => row.id)
|
|
|
|
for (const fileId of fileIds) {
|
|
try {
|
|
const deleteParams = {
|
|
Bucket: R2_STAGING_BUCKET,
|
|
Key: `app_rooms/${fileId}`,
|
|
}
|
|
|
|
const deleteResponse = await R2.send(new DeleteObjectCommand(deleteParams))
|
|
if (
|
|
!deleteResponse.$metadata.httpStatusCode ||
|
|
(deleteResponse.$metadata.httpStatusCode !== 200 &&
|
|
deleteResponse.$metadata.httpStatusCode !== 204)
|
|
) {
|
|
console.error('Failed to delete file from R2 staging bucket')
|
|
continue
|
|
}
|
|
|
|
const deleteFileQuery = `DELETE FROM file WHERE id = $1`
|
|
const deleteResult = await stagingClient.query(deleteFileQuery, [fileId])
|
|
|
|
if (deleteResult.rowCount === 0) {
|
|
console.error('Failed to delete file from Supabase database - no rows affected')
|
|
continue
|
|
}
|
|
} catch (error) {
|
|
console.error('Failed to delete file', error)
|
|
}
|
|
}
|
|
|
|
console.log(`Successfully cleaned up ${fileIds.length} test files`)
|
|
} finally {
|
|
await stagingClient.end()
|
|
}
|
|
}
|
|
|
|
cleanupTestFiles().catch(console.error)
|