LoginSignup
9
6

More than 3 years have passed since last update.

【Github Actions】CIのstepでmysqlにSQLを実行する

Last updated at Posted at 2020-07-26

自分用メモ:
github actionsのstepにmysqlを使ったテストを組み込みたかった。
そのテストは初期データが必要なため、stepの途中で予め用意したsqlを実行させる

github actions yml

.github/workflows/hoge.yml

  test:
    name: Test
    runs-on: ubuntu-latest
    services:
      mysql:
        image: mysql:5.7
        ports:
          - 3306:3306
        env:
          MYSQL_ROOT_PASSWORD: hoge_password
        options: --health-cmd "mysqladmin ping -h localhost" --health-interval 20s --health-timeout 10s --health-retries 10
    steps:
      - name: exec hoge.sql
        run: |
          mysql -h 127.0.0.1 --port 3306 -u root -phoge_password -e "$(cat $(find ./ -name hoge.sql))"

hoge.sql

このファイルに予め実行したいsqlを書いておく。
今回は適当に以下のようにする

このファイルの配置場所はどこでも良いが、 ./sqls/hoge.sqlとかがいいかも

hoge.sql

USE hoge_test;

CREATE TABLE users(
id int,
name varchar
)
9
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
6