Update sql-test.yml #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Run SQL script | |
| on: | |
| push: | |
| branches: [ main, master ] | |
| pull_request: | |
| workflow_dispatch: {} | |
| jobs: | |
| run-sql: | |
| runs-on: ubuntu-latest | |
| services: | |
| mysql: | |
| image: mysql:8.0 | |
| ports: [ "3306:3306" ] | |
| env: | |
| MYSQL_DATABASE: testdb | |
| MYSQL_USER: gha | |
| MYSQL_PASSWORD: gha_pw | |
| MYSQL_ROOT_PASSWORD: ${{ secrets.MYSQL_ROOT_PASSWORD }} | |
| options: >- | |
| --health-cmd="mysqladmin ping -h 127.0.0.1 -uroot -p${MYSQL_ROOT_PASSWORD}" | |
| --health-interval=10s | |
| --health-timeout=5s | |
| --health-retries=10 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Show repo files | |
| run: | | |
| pwd | |
| ls -la | |
| ls -la Vorlesungen || true | |
| - name: Wait for MySQL | |
| run: | | |
| for i in {1..30}; do | |
| if mysqladmin ping -h 127.0.0.1 -uroot -p"${{ secrets.MYSQL_ROOT_PASSWORD }}" --silent; then | |
| exit 0 | |
| fi | |
| sleep 2 | |
| done | |
| echo "MySQL did not become healthy in time" | |
| exit 1 | |
| - name: Run SQL file | |
| run: | | |
| mysql -h 127.0.0.1 -P 3306 -uroot -p"${{ secrets.MYSQL_ROOT_PASSWORD }}" testdb < Vorlesung/Übungen/16_10_2025.sql | |
| - name: Verify table 'vorlesung' is populated | |
| run: | | |
| set -e | |
| # existiert die Tabelle? | |
| exists=$(mysql -h 127.0.0.1 -P 3306 -uroot -p"${{ secrets.MYSQL_ROOT_PASSWORD }}" -N -e "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='testdb' AND table_name='Vorlesung';") | |
| if [ "$exists" -eq 0 ]; then | |
| echo "❌ Tabelle 'vorlesung' existiert nicht in Schema 'testdb'." | |
| exit 1 | |
| fi | |
| # Anzahl Zeilen | |
| rows=$(mysql -h 127.0.0.1 -P 3306 -uroot -p"${{ secrets.MYSQL_ROOT_PASSWORD }}" -N -e "USE testdb; SELECT COUNT(*) FROM Vorlesung;") | |
| echo "vorlesung rows: $rows" | |
| if [ "$rows" -eq 0 ]; then | |
| echo "❌ Tabelle 'vorlesung' ist leer." | |
| exit 1 | |
| fi | |
| # ein paar Datensätze zeigen | |
| mysql -h 127.0.0.1 -P 3306 -uroot -p"${{ secrets.MYSQL_ROOT_PASSWORD }}" -e "USE testdb; SELECT * FROM Vorlesung ORDER BY 1 LIMIT 10;" | |
| - name: Smoke test (products, optional) | |
| run: | | |
| set +e | |
| mysql -h 127.0.0.1 -P 3306 -uroot -p"${{ secrets.MYSQL_ROOT_PASSWORD }}" -e "USE testdb; SELECT COUNT(*) AS cnt FROM products;" || echo "Hinweis: Tabelle 'products' nicht vorhanden." | |
| mysql -h 127.0.0.1 -P 3306 -uroot -p"${{ secrets.MYSQL_ROOT_PASSWORD }}" -e "USE testdb; SHOW TABLES;" |