diff --git a/.github/ci.js b/.github/ci.js index 5270a12..3275a26 100755 --- a/.github/ci.js +++ b/.github/ci.js @@ -2,8 +2,6 @@ // Fork from https://github.com/ankane/setup-mysql/blob/v1/index.js#L50 -// TODO: this script failed on github now, see -// https://github.com/zigcc/zig-cookbook/issues/54 const execSync = require("child_process").execSync; const fs = require('fs'); const os = require('os'); @@ -22,9 +20,9 @@ function addToPath(newPath) { fs.appendFileSync(process.env.GITHUB_PATH, `${newPath}\n`); } -// install +// config const mysqlVersion = '8.0'; -const rootPass = '123'; +const rootPass = 'password'; const database = 'public'; // install @@ -41,8 +39,8 @@ run(`${bin}/mysql -e "GRANT ALL PRIVILEGES ON *.* TO '$USER'@'localhost'"`); run(`${bin}/mysql -e "FLUSH PRIVILEGES"`); // init -run(`${bin}/mysqladmin -proot password '${rootPass}'`); -run(`${bin}/mysqladmin create ${database}`); +run(`${bin}/mysql -uroot -e "CREATE DATABASE ${database}"`); +run(`${bin}/mysql -uroot -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY '${rootPass}'; FLUSH PRIVILEGES;"`) // set path addToPath(bin); diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3556f17..3627683 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,13 +7,13 @@ on: pull_request: paths: - "**.zig" - - ".github/workflows/**" + - ".github/**" push: branches: - main paths: - "**.zig" - - ".github/workflows/**" + - ".github/**" jobs: examples: @@ -22,10 +22,7 @@ jobs: strategy: fail-fast: false matrix: - # CI cannot run on macOS, see - # https://github.com/zigcc/zig-cookbook/issues/54 - # os: [ubuntu-latest, macos-latest] - os: [ubuntu-latest] + os: [ubuntu-latest, macos-latest] zig: [0.11.0, master] steps: - uses: actions/checkout@v4 @@ -47,7 +44,7 @@ jobs: collation server: 'utf8_general_ci' mysql version: '8.0' mysql database: 'public' - mysql root password: 123 + mysql root password: 'password' mysql user: 'developer' - name: mysql for macOS if: matrix.os == 'macos-latest' diff --git a/docker-compose.yml b/docker-compose.yml index 1e423ba..c903aac 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,7 +11,7 @@ services: mysql: image: mysql:8.0 environment: - MYSQL_ROOT_PASSWORD: "123" + MYSQL_ROOT_PASSWORD: "password" MYSQL_DATABASE: public ports: - "3306:3306" diff --git a/src/14-03.zig b/src/14-03.zig index 8e7fc37..e35da0d 100644 --- a/src/14-03.zig +++ b/src/14-03.zig @@ -49,7 +49,6 @@ pub const DB = struct { fn deinit(self: DB) void { c.mysql_close(self.conn); - return; } fn execute(self: DB, query: []const u8) !void { @@ -57,8 +56,6 @@ pub const DB = struct { print("Exec query failed: {s}\n", .{c.mysql_error(self.conn)}); return error.execError; } - - return; } fn queryTable(self: DB) !void { @@ -83,7 +80,6 @@ pub const DB = struct { while (c.mysql_fetch_row(result)) |row| { const cat_name = row[0]; const color_name = row[1]; - print("Cat: {s}, Color: {s}\n", .{ cat_name, color_name }); } } @@ -177,8 +173,6 @@ pub const DB = struct { _ = c.mysql_stmt_reset(insert_cat_stmt); } } - - return; } }; @@ -188,16 +182,14 @@ pub fn main() !void { const allocator = gpa.allocator(); const version = c.mysql_get_client_version(); - print("mysql version is {}\n", .{version}); + print("MySQL client version is {}\n", .{version}); - const info: DBInfo = .{ + const db = try DB.init(allocator, .{ .database = "public", .host = "127.0.0.1", .user = "root", - .password = "123", - }; - - const db = try DB.init(allocator, info); + .password = "password", + }); defer db.deinit(); try db.execute(