Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
2 changes: 2 additions & 0 deletions tool/cmd/migrate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ func run(ctx context.Context, args []string) error {
switch base {
case "google-cloud-dotnet":
return runDotnetMigration(ctx, abs)
case "google-cloud-php":
return runPHPMigration(ctx, abs)
default:
return fmt.Errorf("invalid path: %q", repoPath)
}
Expand Down
45 changes: 45 additions & 0 deletions tool/cmd/migrate/php.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"context"
"fmt"
"log"

"github.com/googleapis/librarian/internal/config"
"github.com/googleapis/librarian/internal/librarian"
)

func runPHPMigration(ctx context.Context, repoPath string) error {
src, err := fetchSource(ctx)
if err != nil {
return errFetchSource
}
cfg := &config.Config{
Language: config.LanguagePhp,
Sources: &config.Sources{
Googleapis: src,
},
}
// The directory name in Googleapis is present for migration code to look
// up API details. It shouldn't be persisted.
cfg.Sources.Googleapis.Dir = ""
if err := librarian.RunTidyOnConfig(ctx, repoPath, cfg); err != nil {
return fmt.Errorf("%w: %w", errTidyFailed, err)
}
log.Println("Successfully migrated PHP libraries configuration skeleton")
return nil
}
64 changes: 64 additions & 0 deletions tool/cmd/migrate/php_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"context"
"os"
"path/filepath"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/googleapis/librarian/internal/config"
"github.com/googleapis/librarian/internal/yaml"
)

func TestRunPHPMigration(t *testing.T) {
wd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
// Override fetchSource.
fetchSource = func(ctx context.Context) (*config.Source, error) {
return &config.Source{
Commit: "abcd123",
SHA256: "sha123",
Dir: filepath.Join(wd, "../../internal/testdata/googleapis"),
}, nil
}
Comment thread
zhumin8 marked this conversation as resolved.
Resolved
dir := t.TempDir()
err = runPHPMigration(t.Context(), dir)
if err != nil {
t.Fatal(err)
}
// Verify librarian.yaml is written and contains the expected content.
cfgPath := filepath.Join(dir, config.LibrarianYAML)
got, err := yaml.Read[config.Config](cfgPath)
if err != nil {
t.Fatalf("reading generated librarian.yaml: %v", err)
}
want := &config.Config{
Language: config.LanguagePhp,
Sources: &config.Sources{
Googleapis: &config.Source{
Commit: "abcd123",
SHA256: "sha123",
},
},
}
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("mismatch (-want +got):\n%s", diff)
}
}
Loading