Merge pull request #5288 from Roardom/composite-action #2348
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: MySQL Schema Dump (Laravel) | |
| on: [ push, pull_request ] | |
| jobs: | |
| schema-dump: | |
| strategy: | |
| matrix: | |
| operating-system: | |
| - ubuntu-24.04 | |
| php-version: | |
| - '8.5' | |
| name: php ${{ matrix.php-version }} on ${{ matrix.operating-system }} | |
| runs-on: ${{ matrix.operating-system }} | |
| services: | |
| mysql: | |
| image: mysql:8.0 | |
| env: | |
| MYSQL_ALLOW_EMPTY_PASSWORD: yes | |
| MYSQL_DATABASE: unit3d | |
| ports: | |
| - 3306:3306 | |
| options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 | |
| redis: | |
| image: redis:7.2.1 | |
| ports: | |
| - 6379:6379 | |
| options: >- | |
| --health-cmd "redis-cli ping" | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| steps: | |
| # 1. Checkout | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| # 2. Setup | |
| - uses: ./.github/actions/setup | |
| with: | |
| php-version: ${{ matrix.php-version }} | |
| operating-system: ${{ matrix.operating-system }} | |
| # 3. Generate Schema Dump | |
| - name: Run Migrations | |
| run: php artisan migrate --force --schema-path=database/schema/mysql-schema-new.sql | |
| env: | |
| DB_CONNECTION: mysql | |
| DB_HOST: 127.0.0.1 | |
| DB_PORT: ${{ job.services.mysql.ports['3306'] }} | |
| DB_DATABASE: unit3d | |
| DB_USERNAME: root | |
| DB_PASSWORD: null | |
| - name: Run Schema Dump | |
| run: php artisan schema:dump --path=database/schema/mysql-schema-new.sql | |
| env: | |
| DB_CONNECTION: mysql | |
| DB_HOST: 127.0.0.1 | |
| DB_PORT: ${{ job.services.mysql.ports['3306'] }} | |
| DB_DATABASE: unit3d | |
| DB_USERNAME: root | |
| DB_PASSWORD: null | |
| - name: Check if schema has changed | |
| id: diff | |
| run: | | |
| if [ -f database/schema/mysql-schema.sql ] && diff -q database/schema/mysql-schema.sql database/schema/mysql-schema-new.sql > /dev/null; then | |
| echo "No changes detected in schema" | |
| echo "has_changes=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "Changes detected in schema" | |
| echo "has_changes=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Update Schema | |
| if: steps.diff.outputs.has_changes == 'true' | |
| run: | | |
| cp database/schema/mysql-schema-new.sql database/schema/mysql-schema.sql | |
| rm database/schema/mysql-schema-new.sql | |
| - name: Commit Schema Changes | |
| if: steps.diff.outputs.has_changes == 'true' | |
| uses: stefanzweifel/git-auto-commit-action@v7 | |
| with: | |
| commit_message: "automation: update schema dump" | |
| commit_user_name: unit3d-bot | |
| commit_user_email: unit3d_gh_bot@protonmail.com | |
| commit_author: unit3d-bot <unit3d_gh_bot@protonmail.com> |