Skip to content

Commit 182ec7c

Browse files
committed
fix: race condition
1 parent 5a1fa3d commit 182ec7c

File tree

1 file changed

+94
-99
lines changed

1 file changed

+94
-99
lines changed

.github/workflows/database-schema.yml

+94-99
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,110 @@
1-
name: MySQL Schema Dump
1+
name: MySQL Schema Dumper
22

33
on: [push, pull_request]
44

55
jobs:
6-
schema-dump:
7-
runs-on: ubuntu-22.04
6+
schema-dump:
7+
runs-on: ubuntu-22.04
88

9-
services:
10-
mysql:
11-
image: mysql:8.0
12-
env:
13-
MYSQL_ALLOW_EMPTY_PASSWORD: yes
14-
MYSQL_DATABASE: unit3d
15-
ports:
16-
- 3306:3306
17-
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
18-
redis:
19-
image: redis:7.2.1
20-
ports:
21-
- 6379:6379
22-
options: >-
23-
--health-cmd "redis-cli ping"
24-
--health-interval 10s
25-
--health-timeout 5s
26-
--health-retries 5
9+
services:
10+
mysql:
11+
image: mysql:8.0
12+
env:
13+
MYSQL_ALLOW_EMPTY_PASSWORD: yes
14+
MYSQL_DATABASE: unit3d
15+
ports:
16+
- 3306:3306
17+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
18+
redis:
19+
image: redis:7.2.1
20+
ports:
21+
- 6379:6379
22+
options: >-
23+
--health-cmd "redis-cli ping"
24+
--health-interval 10s
25+
--health-timeout 5s
26+
--health-retries 5
2727
28-
steps:
29-
- name: Checkout code
30-
uses: actions/checkout@v4
31-
with:
32-
fetch-depth: 0
28+
steps:
29+
- name: Checkout code
30+
uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 0
3333

34-
- name: Setup PHP 8.4
35-
uses: shivammathur/setup-php@v2
36-
with:
37-
php-version: '8.4'
38-
extensions: curl, dom, gd, libxml, mbstring, zip, mysql, xml, intl, bcmath, redis-phpredis/phpredis@6.0.1
39-
tools: composer:v2
40-
coverage: none
41-
env:
42-
REDIS_CONFIGURE_OPTS: --enable-redis
34+
- name: Setup PHP 8.4
35+
uses: shivammathur/setup-php@v2
36+
with:
37+
php-version: '8.4'
38+
extensions: curl, dom, gd, libxml, mbstring, zip, mysql, xml, intl, bcmath, redis-phpredis/phpredis@6.0.1
39+
tools: composer:v2
40+
coverage: none
41+
env:
42+
REDIS_CONFIGURE_OPTS: --enable-redis
4343

44-
- name: Configure Bun
45-
uses: oven-sh/setup-bun@v1
46-
with:
47-
bun-version: latest
44+
- name: Configure Bun
45+
uses: oven-sh/setup-bun@v1
46+
with:
47+
bun-version: latest
4848

49-
- name: Install Composer Dependencies
50-
env:
51-
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
52-
run: composer install --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist --optimize-autoloader
49+
- name: Install Composer Dependencies
50+
env:
51+
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
52+
run: composer install --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist --optimize-autoloader
5353

54-
- name: Prepare The Laravel Environment
55-
run: cp .env.example .env
54+
- name: Prepare The Laravel Environment
55+
run: cp .env.example .env
5656

57-
- name: Generate Application Key
58-
run: php artisan key:generate
57+
- name: Generate Application Key
58+
run: php artisan key:generate
5959

60-
- name: Run Migrations
61-
run: php artisan migrate --force
62-
env:
63-
DB_CONNECTION: mysql
64-
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
65-
DB_USERNAME: root
66-
DB_DATABASE: unit3d
67-
DB_PASSWORD: null
60+
- name: Run Migrations
61+
run: php artisan migrate --force
62+
env:
63+
DB_CONNECTION: mysql
64+
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
65+
DB_USERNAME: root
66+
DB_DATABASE: unit3d
67+
DB_PASSWORD: null
6868

69-
- name: Generate Schema Dump
70-
run: php artisan schema:dump --database=mysql --path=database/schema/mysql-schema-new.sql
71-
env:
72-
DB_CONNECTION: mysql
73-
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
74-
DB_USERNAME: root
75-
DB_DATABASE: unit3d
76-
DB_PASSWORD: null
69+
- name: Generate Schema Dump
70+
run: php artisan schema:dump --database=mysql --path=database/schema/mysql-schema-new.sql
71+
env:
72+
DB_CONNECTION: mysql
73+
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
74+
DB_USERNAME: root
75+
DB_DATABASE: unit3d
76+
DB_PASSWORD: null
7777

78-
- name: Check if schema has changed
79-
id: diff
80-
run: |
81-
if [ -f database/schema/mysql-schema.sql ] && diff -q database/schema/mysql-schema.sql database/schema/mysql-schema-new.sql > /dev/null; then
82-
echo "No changes detected in schema"
83-
echo "has_changes=false" >> $GITHUB_OUTPUT
84-
else
85-
echo "Changes detected in schema"
86-
echo "has_changes=true" >> $GITHUB_OUTPUT
87-
fi
78+
- name: Check if schema has changed
79+
id: diff
80+
run: |
81+
if [ -f database/schema/mysql-schema.sql ] && diff -q database/schema/mysql-schema.sql database/schema/mysql-schema-new.sql > /dev/null; then
82+
echo "No changes detected in schema"
83+
echo "has_changes=false" >> $GITHUB_OUTPUT
84+
else
85+
echo "Changes detected in schema"
86+
echo "has_changes=true" >> $GITHUB_OUTPUT
87+
# Copy the new schema file to the final location
88+
cp database/schema/mysql-schema-new.sql database/schema/mysql-schema.sql
89+
fi
8890
89-
- name: Create Pull Request branch
90-
if: steps.diff.outputs.has_changes == 'true'
91-
run: |
92-
git config --local user.email "hdinnovations@protonmail.com"
93-
git config --local user.name "HDVinnie"
94-
BRANCH_NAME="update-schema-dump-$(date +%Y-%m-%d-%H-%M-%S)"
95-
git checkout -b $BRANCH_NAME
96-
mv database/schema/mysql-schema-new.sql database/schema/mysql-schema.sql
97-
git add database/schema/mysql-schema.sql
98-
git commit -m "update: MySQL schema dump"
99-
git push --set-upstream origin $BRANCH_NAME
100-
echo "branch_name=$BRANCH_NAME" >> $GITHUB_ENV
91+
- name: Create PR with schema changes
92+
if: steps.diff.outputs.has_changes == 'true'
93+
uses: peter-evans/create-pull-request@v5
94+
with:
95+
token: ${{ secrets.GITHUB_TOKEN }}
96+
commit-message: "update: MySQL schema dump"
97+
title: "(Update) MySQL schema dump"
98+
body: |
99+
This PR updates the MySQL schema dump with the latest migration changes.
101100
102-
- name: Create Pull Request
103-
if: steps.diff.outputs.has_changes == 'true'
104-
uses: peter-evans/create-pull-request@v5
105-
with:
106-
token: ${{ secrets.GITHUB_TOKEN }}
107-
branch: ${{ env.branch_name }}
108-
delete-branch: true
109-
title: "(Update) MySQL schema dump"
110-
body: |
111-
This PR updates the MySQL schema dump with the latest migration changes.
112-
113-
**Automated PR generated by GitHub Actions**
114-
base: development
115-
draft: false
101+
**Automated PR generated by GitHub Actions**
102+
branch: update-schema-dump
103+
branch-suffix: timestamp
104+
delete-branch: true
105+
base: development
106+
path: .
107+
add-paths: |
108+
database/schema/mysql-schema.sql
109+
commit-author: HDVinnie <hdinnovations@protonmail.com>
110+
draft: false

0 commit comments

Comments
 (0)