-
Notifications
You must be signed in to change notification settings - Fork 399
157 lines (139 loc) · 5.89 KB
/
database-schema.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
name: MySQL Schema Dumper
on: [push, pull_request]
jobs:
schema-dump:
runs-on: ubuntu-22.04
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:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: development
- name: Setup PHP 8.4
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
extensions: curl, dom, gd, libxml, mbstring, zip, mysql, xml, intl, bcmath, redis-phpredis/phpredis@6.0.1
tools: composer:v2
coverage: none
env:
REDIS_CONFIGURE_OPTS: --enable-redis
- name: Configure Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Install Composer Dependencies
env:
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
run: composer install --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist --optimize-autoloader
- name: Prepare The Laravel Environment
run: cp .env.example .env
- name: Generate Application Key
run: php artisan key:generate
- name: Get latest commit that modified migrations
id: find-commit
run: |
LATEST_COMMIT=$(git log --pretty=format:"%H %s" -n 100 | grep -E "migration|schema" | head -n 1 | cut -d' ' -f1)
COMMIT_MSG=$(git log --pretty=format:"%s" -n 1 $LATEST_COMMIT)
echo "commit_id=$LATEST_COMMIT" >> $GITHUB_OUTPUT
echo "commit_msg=$COMMIT_MSG" >> $GITHUB_OUTPUT
if [ -z "$LATEST_COMMIT" ]; then
echo "No relevant commit found, using latest commit"
echo "commit_id=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
echo "commit_msg=$(git log --pretty=format:"%s" -n 1 HEAD)" >> $GITHUB_OUTPUT
fi
- name: Run Migrations
run: php artisan migrate --force
env:
DB_CONNECTION: mysql
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
DB_USERNAME: root
DB_DATABASE: unit3d
DB_PASSWORD: null
- name: Generate Schema Dump
run: php artisan schema:dump --database=mysql --path=database/schema/mysql-schema-new.sql
env:
DB_CONNECTION: mysql
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
DB_USERNAME: root
DB_DATABASE: unit3d
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
# Copy the new schema file to the final location
cp database/schema/mysql-schema-new.sql database/schema/mysql-schema.sql
fi
- name: Check for existing PRs
id: check-pr
if: steps.diff.outputs.has_changes == 'true'
run: |
PR_EXISTS=$(gh pr list --base development --head "update-schema-dump*" --json number --jq 'length')
if [ "$PR_EXISTS" -gt "0" ]; then
echo "existing_pr=true" >> $GITHUB_OUTPUT
PR_NUMBER=$(gh pr list --base development --head "update-schema-dump*" --json number --jq '.[0].number')
BRANCH_NAME=$(gh pr view $PR_NUMBER --json headRefName --jq '.headRefName')
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
else
echo "existing_pr=false" >> $GITHUB_OUTPUT
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update existing PR branch
if: steps.diff.outputs.has_changes == 'true' && steps.check-pr.outputs.existing_pr == 'true'
run: |
git config --local user.email "hdinnovations@protonmail.com"
git config --local user.name "HDVinnie"
git fetch origin
git checkout ${{ steps.check-pr.outputs.branch_name }}
git add database/schema/mysql-schema.sql
git commit -m "update: MySQL schema dump from commit ${{ steps.find-commit.outputs.commit_id }}"
git push origin ${{ steps.check-pr.outputs.branch_name }}
env:
GH_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
- name: Create new PR with schema changes
if: steps.diff.outputs.has_changes == 'true' && steps.check-pr.outputs.existing_pr == 'false'
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
commit-message: "update: MySQL schema dump from commit ${{ steps.find-commit.outputs.commit_id }}"
title: "(Update) MySQL schema dump"
body: |
This PR updates the MySQL schema dump with the latest migration changes.
Related to commit: ${{ steps.find-commit.outputs.commit_id }}
Commit message: ${{ steps.find-commit.outputs.commit_msg }}
[View commit](https://github.com/HDInnovations/UNIT3D/commit/${{ steps.find-commit.outputs.commit_id }})
branch: update-schema-dump
branch-suffix: timestamp
delete-branch: true
base: development
path: .
add-paths: |
database/schema/mysql-schema.sql
author: HDVinnie <hdinnovations@protonmail.com>
committer: HDVinnie <hdinnovations@protonmail.com>
draft: false