fix(ioscompanion): resolve signing key path to absolute

xcodebuild's -authenticationKeyPath requires an absolute path, but .env
files commonly carry a repo-relative one. Resolve it against the working
directory before the stat so a relative ASC_API_KEY_PATH still signs.
This commit is contained in:
pj committed 2026-06-08 23:29:52 +05:30
1 parent 0e76e2e474
commit 1357a2b1cc
2 files changed
+27 -4

No files matched your search

+8 -4
View File
@@ -67,10 +67,14 @@ func readSigningCredentials() (signingCredentials, error) {
if len(missing) > 0 { if len(missing) > 0 {
return creds, fmt.Errorf("device signing requires environment variables: %s", strings.Join(missing, ", ")) return creds, fmt.Errorf("device signing requires environment variables: %s", strings.Join(missing, ", "))
} }
if creds.authKeyPath != "" { // xcodebuild's -authenticationKeyPath demands an absolute path, but .env
if _, err := os.Stat(creds.authKeyPath); err != nil { // files commonly carry a repo-relative one. Resolve it against the working
return creds, fmt.Errorf("App Store Connect key not found at %s: %w", creds.authKeyPath, err) // directory before the stat so a relative key still works.
} if absolute, err := filepath.Abs(creds.authKeyPath); err == nil {
creds.authKeyPath = absolute
}
if _, err := os.Stat(creds.authKeyPath); err != nil {
return creds, fmt.Errorf("App Store Connect key not found at %s: %w", creds.authKeyPath, err)
} }
return creds, nil return creds, nil
} }
@@ -147,6 +147,25 @@ func TestReadSigningCredentialsAcceptsPresentKey(t *testing.T) {
} }
} }
func TestReadSigningCredentialsResolvesRelativeKeyPath(t *testing.T) {
dir := t.TempDir()
t.Chdir(dir)
if err := os.WriteFile("AuthKey.p8", []byte("key"), 0o600); err != nil {
t.Fatal(err)
}
t.Setenv(envTeam, "TEAM1")
t.Setenv(envAuthKeyID, "KID")
t.Setenv(envAuthIssuer, "ISS")
t.Setenv(envAuthKeyPath, "AuthKey.p8")
creds, err := readSigningCredentials()
if err != nil {
t.Fatal(err)
}
if !filepath.IsAbs(creds.authKeyPath) {
t.Fatalf("authKeyPath = %q, want an absolute path for xcodebuild", creds.authKeyPath)
}
}
func TestSourceHashChangesWithSources(t *testing.T) { func TestSourceHashChangesWithSources(t *testing.T) {
dir := t.TempDir() dir := t.TempDir()
if err := os.MkdirAll(filepath.Join(dir, "Sources"), 0o755); err != nil { if err := os.MkdirAll(filepath.Join(dir, "Sources"), 0o755); err != nil {