CI: Using an action for mysql setup instead of a docker image

This commit is contained in:
Griatch 2025-12-22 09:25:32 +01:00
parent 706fb4cd46
commit f369081270
3 changed files with 22 additions and 42 deletions

View file

@ -35,40 +35,36 @@ runs:
- name: Wait for MySQL to be ready
if: ${{ inputs.database == 'mysql' }}
run: |
# Wait for MySQL service container to be healthy
until mysqladmin ping -h 127.0.0.1 -u root -proot_password --silent; do
# Wait for MySQL server to be ready
until mysqladmin ping -u root -proot_password --silent; do
sleep 1
echo -n .
done
echo "MySQL is ready"
shell: bash
- name: Set up MySQL Privileges
- name: Set up MySQL Database and Privileges
if: ${{ inputs.database == 'mysql' }}
run: |
# Note: MySQL server configuration (character set, collation, row format) is set
# at container startup via custom entrypoint script that passes command-line arguments
# to mysqld, similar to how mirromutth/mysql-action works.
# Ensure user exists and has proper privileges
mysql -u root -proot_password -h 127.0.0.1 mysql <<EOF
CREATE USER IF NOT EXISTS 'evennia'@'%' IDENTIFIED BY 'password';
# via my-cnf in the shogo82148/actions-setup-mysql action.
# The user 'evennia' is already created by the action, but we need to create the database
# and grant privileges.
mysql -u root -proot_password mysql <<EOF
CREATE DATABASE IF NOT EXISTS evennia CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
GRANT ALL PRIVILEGES ON \`evennia%\`.* TO 'evennia'@'%';
GRANT PROCESS ON *.* TO 'evennia'@'%';
GRANT SESSION_VARIABLES_ADMIN ON *.* TO 'evennia'@'%';
FLUSH PRIVILEGES;
EOF
# Set database character set and collation
mysql -u root -proot_password -h 127.0.0.1 evennia <<EOF
ALTER DATABASE evennia CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
EOF
shell: bash
# get logs from db start
- name: Database container logs
if: ${{ inputs.database == 'postgresql' || inputs.database == 'mysql' }}
if: ${{ inputs.database == 'postgresql'}}
uses: jwalton/gh-docker-logs@v2
- name: Check running containers
if: ${{ inputs.database == 'postgresql' || inputs.database == 'mysql' }}
if: ${{ inputs.database == 'postgresql'}}
run: docker ps -a
shell: bash

View file

@ -56,32 +56,21 @@ jobs:
timeout-minutes: 35
services:
mysql:
image: mysql:8.0
env:
MYSQL_DATABASE: evennia
MYSQL_USER: evennia
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: root_password
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping -h localhost"
--health-interval=10s
--health-timeout=5s
--health-retries=3
--entrypoint="/bin/bash"
-c
"printf '#!/bin/bash\nexec /usr/local/bin/docker-entrypoint.sh mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --innodb-default-row-format=DYNAMIC \"\$@\"\n' > /tmp/mysql-entrypoint.sh && chmod +x /tmp/mysql-entrypoint.sh && exec /tmp/mysql-entrypoint.sh"
steps:
- uses: actions/checkout@v4
- name: Install MySQL client
run: |
sudo apt-get update
sudo apt-get install -y default-mysql-client
timeout-minutes: 2
- name: Set up MySQL
uses: shogo82148/actions-setup-mysql@v1
with:
mysql-version: "8.0"
root-password: root_password
user: evennia
password: password
my-cnf: |
[mysqld]
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
innodb-default-row-format=DYNAMIC
- name: Set up database (mysql)
uses: ./.github/actions/setup-database

View file

@ -1,5 +0,0 @@
[mysqld]
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
innodb-default-row-format=DYNAMIC