Skip to content

refactor(authentication): パッケージを再設計し、DB認証情報管理・開発CLI・テスト基盤を追加 #147

refactor(authentication): パッケージを再設計し、DB認証情報管理・開発CLI・テスト基盤を追加

refactor(authentication): パッケージを再設計し、DB認証情報管理・開発CLI・テスト基盤を追加 #147

Workflow file for this run

name: Cleanup Preview
on:
pull_request:
types: [closed]
jobs:
cleanup:
name: Cleanup Preview Environment
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
- name: Delete Preview Database
env:
TURSO_API_TOKEN: ${{ secrets.TURSO_PLATFORM_API_TOKEN }}
TURSO_ORG_SLUG: ${{ secrets.TURSO_ORG_SLUG }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
DB_NAME="next-lift-preview-pr${PR_NUMBER}-auth"
# データベースを削除
DELETE_RESPONSE=$(curl -X DELETE \
-H "Authorization: Bearer ${TURSO_API_TOKEN}" \
"https://api.turso.tech/v1/organizations/${TURSO_ORG_SLUG}/databases/${DB_NAME}")
echo "Database deletion response: ${DELETE_RESPONSE}"
# エラーチェック(404は既に削除済みと判断)
if echo "${DELETE_RESPONSE}" | jq -e '.error' > /dev/null; then
ERROR_MSG=$(echo "${DELETE_RESPONSE}" | jq -r '.error')
if [[ "${ERROR_MSG}" == *"not found"* ]]; then
echo "Database ${DB_NAME} was already deleted or does not exist."
exit 0
else
echo "Error deleting database: ${ERROR_MSG}"
exit 1
fi
fi
echo "Successfully deleted database: ${DB_NAME}"
- name: Comment PR with Cleanup Info
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
with:
script: |
const prNumber = process.env.PR_NUMBER;
const body = [
'## 🗑️ Preview Environment Cleaned Up',
'',
'✅ プレビュー環境をクリーンアップしました!',
'',
`**Database Name**: next-lift-preview-pr${prNumber}-auth`,
'',
'> PRがクローズされたため、関連するデータベースとVercel環境変数を自動的に削除しました。'
].join('\n');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});