Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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
  • Loading branch information
claude committed Feb 22, 2026
commit 822c758aa7f57423459b10f92c7f3a082c5eb081
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ jobs:

- name: test ./...
run: gotestsum --junitfile junit.xml -- --tags=examples -timeout 20m ./...
if: ${{ matrix.os }} != "windows-2022"
env:
CI_SQLC_PROJECT_ID: ${{ secrets.CI_SQLC_PROJECT_ID }}
CI_SQLC_AUTH_TOKEN: ${{ secrets.CI_SQLC_AUTH_TOKEN }}
Expand Down
17 changes: 12 additions & 5 deletions cmd/sqlc-test-setup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"log"
"os"
"os/exec"
"path/filepath"
"strings"
"time"
)
Expand Down Expand Up @@ -286,6 +285,12 @@ func startMySQL() error {
return verifyMySQL()
}

// Stop any existing MySQL service that might be running (e.g. pre-installed
// on GitHub Actions runners) to avoid port conflicts.
log.Println("stopping any existing mysql service")
_ = exec.Command("sudo", "service", "mysql", "stop").Run()
_ = exec.Command("sudo", "mysqladmin", "shutdown").Run()

// Check if data directory already exists and has been initialized
if mysqlInitialized() {
log.Println("mysql data directory already initialized, skipping initialization")
Expand Down Expand Up @@ -370,12 +375,14 @@ func verifyMySQL() error {
}

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