Skip to content

Merge pull request #299 from Moonlark-Dev/This-is-XiaoDeng-patch-2 #208

Merge pull request #299 from Moonlark-Dev/This-is-XiaoDeng-patch-2

Merge pull request #299 from Moonlark-Dev/This-is-XiaoDeng-patch-2 #208

name: Check Database Upgrade
on:
push:
branches:
- main
workflow_dispatch:
jobs:
check-database:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.12
- name: Setup Poetry
uses: snok/install-poetry@v1.2.1
- name: Install dependencies
run: poetry install
- name: Write .env file
run: echo "$MOONLARK_ENV" > .env
env:
MOONLARK_ENV: ${{ secrets.ENV }}
- name: Check database upgrade
run: |
poetry run nb orm upgrade
poetry run nb orm check 2>error.log
if (grep "Error" error.log) ; then
echo "Database check failed"
echo "failed=1" >> $GITHUB_ENV
else
echo "Database check succeeded"
echo "failed=0" >> $GITHUB_ENV
fi || true
- name: Install github CLI
if: env.failed == 1
uses: cresta/action-setup-github-cli@v1
- name: Create Pull Request
if: env.failed == 1
run: |
git checkout -b database-auto-fix
poetry run nb orm revision
git add -A
git config --global user.email "chun-awa@itcdt.top"
git config --global user.name "chun-awa"
git commit -a -m "Update database versions."
git push origin database-auto-fix
gh pr create --head database-auto-fix --base main --title "更新数据库迁移文件" --body "此 Pull Requests 由 GitHub Actions 发起,请仔细检查数据库迁移文件的内容。"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Return failed
if: env.failed == 1
run: exit 1