Skip to content

Commit

Permalink
Update sql_syntax_check.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
wrongecho authored Mar 17, 2024
1 parent 16aaf24 commit fb91602
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions .github/workflows/sql_syntax_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,45 @@ jobs:

- name: Generate init.sql
run: |
mkdir -p init
echo "DELETE FROM mysql.proxies_priv WHERE Host != 'localhost';" > init/init.sql
mkdir -p ${{ github.workspace }}/init
echo "DELETE FROM mysql.proxies_priv WHERE Host != 'localhost';" > ${{ github.workspace }}/init/init.sql
echo "Generated init.sql at: ${{ github.workspace }}/init/init.sql" # Output file path
- name: Upload init.sql artifact
uses: actions/upload-artifact@v2
with:
name: init-sql
path: init/init.sql
path: ${{ github.workspace }}/init

syntax_check:
name: Check SQL Syntax
runs-on: ubuntu-latest
needs: generate_init_sql

services:
mariadb:
image: mariadb:latest
env:
MYSQL_RANDOM_ROOT_PASSWORD: "yes" # Generate a random root password
MYSQL_DATABASE: test # optional, create a test database if needed
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
ports:
- 3306:3306
volumes:
- ${{ github.workspace }}/init:/docker-entrypoint-initdb.d

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Download init.sql artifact
uses: actions/download-artifact@v2
with:
name: init-sql
path: init

- name: Wait for MariaDB to Start
run: dockerize -wait tcp://127.0.0.1:3306 -timeout 1m

- name: Run SQL Linting
run: |
password="${{ secrets.MYSQL_ROOT_PASSWORD }}"
docker run --rm -v ${{ github.workspace }}/init:/docker-entrypoint-initdb.d -e MYSQL_ROOT_PASSWORD=$password mariadb:latest mysql -h localhost -u root -p$MYSQL_ROOT_PASSWORD < /docker-entrypoint-initdb.d/init.sql
docker exec -i ${{ job.services.mariadb.name }} mysql -h localhost -u root -p"$password" < db.sql

0 comments on commit fb91602

Please sign in to comment.