Skip to content

Commit 822c758

Browse files
committed
Fix sqlc-test-setup for GitHub Actions pre-installed MySQL
Three fixes for CI failures: 1. mysqlInitialized() now uses `sudo ls` instead of filepath.Glob. The /var/lib/mysql directory is owned by mysql:mysql with restricted permissions, so filepath.Glob silently failed, causing the tool to attempt --initialize-insecure on a non-empty directory. 2. Stop any existing MySQL service before starting our own to avoid port conflicts with pre-installed MySQL on GitHub Actions runners. 3. Remove vestigial `if: matrix.os` condition from the test step in ci.yml — the test job has no matrix and the condition was always truthy, producing a GitHub Actions warning. https://claude.ai/code/session_01CsyRwSkRxBcQoaQFVkMQsJ
1 parent 10cbc2a commit 822c758

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ jobs:
5858

5959
- name: test ./...
6060
run: gotestsum --junitfile junit.xml -- --tags=examples -timeout 20m ./...
61-
if: ${{ matrix.os }} != "windows-2022"
6261
env:
6362
CI_SQLC_PROJECT_ID: ${{ secrets.CI_SQLC_PROJECT_ID }}
6463
CI_SQLC_AUTH_TOKEN: ${{ secrets.CI_SQLC_AUTH_TOKEN }}

cmd/sqlc-test-setup/main.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"log"
66
"os"
77
"os/exec"
8-
"path/filepath"
98
"strings"
109
"time"
1110
)
@@ -286,6 +285,12 @@ func startMySQL() error {
286285
return verifyMySQL()
287286
}
288287

288+
// Stop any existing MySQL service that might be running (e.g. pre-installed
289+
// on GitHub Actions runners) to avoid port conflicts.
290+
log.Println("stopping any existing mysql service")
291+
_ = exec.Command("sudo", "service", "mysql", "stop").Run()
292+
_ = exec.Command("sudo", "mysqladmin", "shutdown").Run()
293+
289294
// Check if data directory already exists and has been initialized
290295
if mysqlInitialized() {
291296
log.Println("mysql data directory already initialized, skipping initialization")
@@ -370,12 +375,14 @@ func verifyMySQL() error {
370375
}
371376

372377
// mysqlInitialized checks if the MySQL data directory has been initialized.
378+
// We use sudo ls because /var/lib/mysql is typically only readable by the
379+
// mysql user, so filepath.Glob from a non-root process would silently fail.
373380
func mysqlInitialized() bool {
374-
dataDir := "/var/lib/mysql"
375-
entries, err := filepath.Glob(filepath.Join(dataDir, "*.pem"))
381+
out, err := exec.Command("sudo", "ls", "/var/lib/mysql").CombinedOutput()
376382
if err != nil {
377383
return false
378384
}
379-
// MySQL creates TLS certificate files during initialization
380-
return len(entries) > 0
385+
// If the directory has any contents, consider it initialized.
386+
// mysqld --initialize-insecure requires an empty directory.
387+
return strings.TrimSpace(string(out)) != ""
381388
}

0 commit comments

Comments
 (0)