From acd184bf56cf9444b6e20438e684e683a1af8bbf Mon Sep 17 00:00:00 2001 From: furusax0621 Date: Sat, 24 Dec 2022 13:58:39 +0900 Subject: [PATCH 1/8] introduce reviewdog --- .github/workflows/reviewdog.yml | 39 +++++++++++++++------------------ 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml index bad8149..1a69a9c 100644 --- a/.github/workflows/reviewdog.yml +++ b/.github/workflows/reviewdog.yml @@ -1,27 +1,24 @@ -# This is a basic workflow to help you get started with Actions +name: reviewdog -name: CI +on: pull_request -# Controls when the action will run. Triggers the workflow on push or pull request -# events but only for the master branch -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on + actionlint: + name: golangci-lint runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + - uses: reviewdog/action-actionlint@v1 + with: + reporter: github-pr-review + level: warning - # Runs a single command using the runners shell - - name: Run golangci-lint with reviewdog - uses: reviewdog/action-golangci-lint@v1.1.3 + golangci-lint: + name: golangci-lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: reviewdog/action-golangci-lint@v2 + with: + reporter: github-pr-review + level: warning From cca5f6f70b89368df1bd17bac7495942f9a6a22d Mon Sep 17 00:00:00 2001 From: furusax0621 Date: Sat, 24 Dec 2022 14:08:54 +0900 Subject: [PATCH 2/8] add test workflow --- .github/workflows/test.yaml | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..83b32b4 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,40 @@ +name: test + +on: + push: + pull_request: + branches: main + +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + mysql: ["5.6", "5.7", "8.0"] + services: + db: + image: mysql:${{ matrix.mysql }} + ports: + - 3306:3306 + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: sakila + MYSQL_USER: user + MYSQL_PASSWORD: password + options: >- + --health-cmd "mysqladmin ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: + - uses: actions/checkout@v3 + - name: setup go 1.19 + uses: actions/setup-go@v3 + with: + go-version: "1.19" + cache: true + - name: test with MySQL ${{ matrix.mysql }} + run: go test -v -race ./... + env: + TEST_DSN: "root:root@tcp(127.0.0.1:3306)/sakila?parseTime=true" From 75ec7d809c1c304f3b40d2a421b6c27af1bb560f Mon Sep 17 00:00:00 2001 From: furusax0621 Date: Sat, 24 Dec 2022 14:09:55 +0900 Subject: [PATCH 3/8] modify trigger --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 83b32b4..5d60350 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -2,8 +2,8 @@ name: test on: push: - pull_request: branches: main + pull_request: jobs: test: From 11e3ac9c184b40ea3dd6f3bac291ac86dc4c037e Mon Sep 17 00:00:00 2001 From: furusax0621 Date: Sat, 24 Dec 2022 14:12:10 +0900 Subject: [PATCH 4/8] initialize database --- .github/workflows/test.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 5d60350..b625384 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -34,6 +34,8 @@ jobs: with: go-version: "1.19" cache: true + - name: prepare test + run: mysql -uroot -proot -h127.0.0.1 -P3306 sakila < ./testdata/schema/sakila.sql - name: test with MySQL ${{ matrix.mysql }} run: go test -v -race ./... env: From 25980c50cde68d3bd876221fa311ab4e799ec4e0 Mon Sep 17 00:00:00 2001 From: furusax0621 Date: Sat, 24 Dec 2022 18:42:32 +0900 Subject: [PATCH 5/8] fix testdata for mysql8.0 --- tableparser/testdata/table003.json | 32 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tableparser/testdata/table003.json b/tableparser/testdata/table003.json index a0fe07a..3f444e7 100755 --- a/tableparser/testdata/table003.json +++ b/tableparser/testdata/table003.json @@ -42,7 +42,7 @@ "String": "", "Valid": false }, - "ColumnType": "smallint(5) unsigned", + "ColumnType": "smallint unsigned", "ColumnKey": "PRI", "Extra": "auto_increment", "Privileges": "select,insert,update,references", @@ -88,11 +88,11 @@ "Valid": false }, "CharacterSetName": { - "String": "utf8", + "String": "utf8mb3", "Valid": true }, "CollationName": { - "String": "utf8_general_ci", + "String": "utf8mb3_general_ci", "Valid": true }, "ColumnType": "varchar(255)", @@ -141,11 +141,11 @@ "Valid": false }, "CharacterSetName": { - "String": "utf8", + "String": "utf8mb3", "Valid": true }, "CollationName": { - "String": "utf8_general_ci", + "String": "utf8mb3_general_ci", "Valid": true }, "ColumnType": "text", @@ -201,7 +201,7 @@ "String": "", "Valid": false }, - "ColumnType": "year(4)", + "ColumnType": "year", "ColumnKey": "", "Extra": "", "Privileges": "select,insert,update,references", @@ -254,7 +254,7 @@ "String": "", "Valid": false }, - "ColumnType": "tinyint(3) unsigned", + "ColumnType": "tinyint unsigned", "ColumnKey": "MUL", "Extra": "", "Privileges": "select,insert,update,references", @@ -313,7 +313,7 @@ "String": "", "Valid": false }, - "ColumnType": "tinyint(3) unsigned", + "ColumnType": "tinyint unsigned", "ColumnKey": "MUL", "Extra": "", "Privileges": "select,insert,update,references", @@ -372,7 +372,7 @@ "String": "", "Valid": false }, - "ColumnType": "tinyint(3) unsigned", + "ColumnType": "tinyint unsigned", "ColumnKey": "", "Extra": "", "Privileges": "select,insert,update,references", @@ -478,7 +478,7 @@ "String": "", "Valid": false }, - "ColumnType": "smallint(5) unsigned", + "ColumnType": "smallint unsigned", "ColumnKey": "", "Extra": "", "Privileges": "select,insert,update,references", @@ -577,11 +577,11 @@ "Valid": false }, "CharacterSetName": { - "String": "utf8", + "String": "utf8mb3", "Valid": true }, "CollationName": { - "String": "utf8_general_ci", + "String": "utf8mb3_general_ci", "Valid": true }, "ColumnType": "enum('G','PG','PG-13','R','NC-17')", @@ -636,11 +636,11 @@ "Valid": false }, "CharacterSetName": { - "String": "utf8", + "String": "utf8mb3", "Valid": true }, "CollationName": { - "String": "utf8_general_ci", + "String": "utf8mb3_general_ci", "Valid": true }, "ColumnType": "set('Trailers','Commentaries','Deleted Scenes','Behind the Scenes')", @@ -703,7 +703,7 @@ }, "ColumnType": "timestamp", "ColumnKey": "", - "Extra": "on update CURRENT_TIMESTAMP", + "Extra": "DEFAULT_GENERATED on update CURRENT_TIMESTAMP", "Privileges": "select,insert,update,references", "ColumnComment": "", "GenerationExpression": "", @@ -766,4 +766,4 @@ } ], "Triggers": [] -} \ No newline at end of file +} From cf3336ce266fa7f169e467e5cd42e760ff26b29c Mon Sep 17 00:00:00 2001 From: furusax0621 Date: Sat, 24 Dec 2022 18:42:45 +0900 Subject: [PATCH 6/8] fix test utilities usage --- tableparser/tableparser_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tableparser/tableparser_test.go b/tableparser/tableparser_test.go index f2ddece..841b312 100644 --- a/tableparser/tableparser_test.go +++ b/tableparser/tableparser_test.go @@ -36,7 +36,7 @@ func TestParse(t *testing.T) { } tu.LoadJson(t, sampleFile, &want) - tu.Equals(t, table, want) + tu.Equals(t, want, table) } func TestGetIndexes(t *testing.T) { @@ -49,7 +49,7 @@ func TestGetIndexes(t *testing.T) { tu.WriteJson(t, "indexes.json", idx) } tu.Ok(t, err) - tu.Equals(t, idx, want) + tu.Equals(t, want, idx) } func TestGetTriggers(t *testing.T) { @@ -77,5 +77,5 @@ func TestGetTriggers(t *testing.T) { tu.WriteJson(t, sampleFile, triggers) } tu.Ok(t, err) - tu.Equals(t, triggers, want) + tu.Equals(t, want, triggers) } From 197a5a9d3ddc6109a92a1dad170f01c48e5c0f04 Mon Sep 17 00:00:00 2001 From: furusax0621 Date: Sat, 24 Dec 2022 18:44:06 +0900 Subject: [PATCH 7/8] update local test env --- docker-compose.yml | 21 ++++++++++++--------- runtests.sh | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index a8c9294..83b2335 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,33 +1,36 @@ version: '3' services: mysql5.6: - image: ${MYSQL_IMAGE:-mysql:5.6} + image: mysql:5.6 + platform: linux/amd64 ports: - - ${MYSQL_HOST:-127.0.0.1}:${MYSQL_PORT:-3306}:3306 + - 3306:3306 environment: - - MYSQL_ALLOW_EMPTY_PASSWORD=yes + - MYSQL_ROOT_PASSWORD=root # MariaDB >= 10.0.12 doesn't enable Performance Schema by default so we need to do it manually # https://mariadb.com/kb/en/mariadb/performance-schema-overview/#activating-the-performance-schema command: --performance-schema --secure-file-priv="" volumes: - ./testdata/schema/:/docker-entrypoint-initdb.d/:rw mysql5.7: - image: ${MYSQL_IMAGE:-mysql:5.7} + image: mysql:5.7 + platform: linux/amd64 ports: - - ${MYSQL_HOST:-127.0.0.1}:${MYSQL_PORT:-3307}:3306 + - 3307:3306 environment: - - MYSQL_ALLOW_EMPTY_PASSWORD=yes + - MYSQL_ROOT_PASSWORD=root # MariaDB >= 10.0.12 doesn't enable Performance Schema by default so we need to do it manually # https://mariadb.com/kb/en/mariadb/performance-schema-overview/#activating-the-performance-schema command: --performance-schema --secure-file-priv="" volumes: - ./testdata/schema/:/docker-entrypoint-initdb.d/:rw mysql8.0: - image: ${MYSQL_IMAGE:-mysql:8.0.3} + image: mysql:8.0 + platform: linux/amd64 ports: - - ${MYSQL_HOST:-127.0.0.1}:${MYSQL_PORT:-3308}:3306 + - 3308:3306 environment: - - MYSQL_ALLOW_EMPTY_PASSWORD=yes + - MYSQL_ROOT_PASSWORD=root # MariaDB >= 10.0.12 doesn't enable Performance Schema by default so we need to do it manually # https://mariadb.com/kb/en/mariadb/performance-schema-overview/#activating-the-performance-schema command: --performance-schema --secure-file-priv="" diff --git a/runtests.sh b/runtests.sh index fddfdf8..6f57352 100755 --- a/runtests.sh +++ b/runtests.sh @@ -16,7 +16,7 @@ for PORT in 3306 3307 3308; do echo "### MySQL at port ${PORT}" echo "##########################" wait_mysql $PORT - export TEST_DSN="root:@tcp(127.1:${PORT})/sakila?parseTime=true" + export TEST_DSN="root:root@tcp(127.1:${PORT})/sakila?parseTime=true" go test -v ./... done From 5b10de4ab6f21fcc0990f547d38caa80e03a26f8 Mon Sep 17 00:00:00 2001 From: furusax0621 Date: Sat, 24 Dec 2022 18:45:46 +0900 Subject: [PATCH 8/8] remove travis ci config --- .travis.yml | 47 ------------------------------------------- .travis/docker.cnf | 4 ---- .travis/wait_mysql.sh | 8 -------- 3 files changed, 59 deletions(-) delete mode 100644 .travis.yml delete mode 100644 .travis/docker.cnf delete mode 100755 .travis/wait_mysql.sh diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 849897f..0000000 --- a/.travis.yml +++ /dev/null @@ -1,47 +0,0 @@ -sudo: false -language: go - -matrix: - include: - - env: DB=MYSQL5.7 - sudo: required - dist: trusty - go: 1.14.x - services: - - docker - before_install: - - go get golang.org/x/tools/cmd/cover - - go get -u github.com/golang/dep/cmd/dep - - dep ensure - - docker pull mysql:5.7 - - docker run -d -p 127.0.0.1:3307:3306 --name mysqld -e MYSQL_ALLOW_EMPTY_PASSWORD=yes mysql:5.7 --innodb_log_file_size=256MB - --innodb_buffer_pool_size=512MB --max_allowed_packet=16MB - - sleep 30 - - cp .travis/docker.cnf ~/.my.cnf - - .travis/wait_mysql.sh - - mysql < testdata/schema/sakila.sql - before_script: - - export TEST_DSN="root:@tcp(127.0.0.1:3307)/sakila?parseTime=true" - - - env: DB=MYSQL5.6 - sudo: required - dist: trusty - go: 1.14.x - services: - - docker - before_install: - - go get golang.org/x/tools/cmd/cover - - go get -u github.com/golang/dep/cmd/dep - - dep ensure - - docker pull mysql:5.6 - - docker run -d -p 127.0.0.1:3307:3306 --name mysqld -e MYSQL_ALLOW_EMPTY_PASSWORD=yes mysql:5.6 - --innodb_log_file_size=256MB --innodb_buffer_pool_size=512MB --max_allowed_packet=16MB - - sleep 30 - - cp .travis/docker.cnf ~/.my.cnf - - .travis/wait_mysql.sh - - mysql < testdata/schema/sakila.sql - before_script: - - export TEST_DSN="root@tcp(127.0.0.1:3307)/sakila?parseTime=true" - -script: - - go test -v -race ./... diff --git a/.travis/docker.cnf b/.travis/docker.cnf deleted file mode 100644 index 40226a3..0000000 --- a/.travis/docker.cnf +++ /dev/null @@ -1,4 +0,0 @@ -[client] -user = root -host = 127.0.0.1 -port = 3307 diff --git a/.travis/wait_mysql.sh b/.travis/wait_mysql.sh deleted file mode 100755 index abcf5f0..0000000 --- a/.travis/wait_mysql.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -while : -do - sleep 3 - if mysql -e 'select version()'; then - break - fi -done