Skip to content

Commit 2e11004

Browse files
authored
fix: release init provides read-only full repository (#2370)
Fixes #2025 Fixes #2429 Related to #2218 Skips copy of repository for `release init`. We pass the entire repo (already as read-only) to the language container.
1 parent 88698b4 commit 2e11004

File tree

6 files changed

+21
-140
lines changed

6 files changed

+21
-140
lines changed

doc/language-onboarding.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ global files that reference the libraries being released.
249249
| Context | Type | Description |
250250
| :----------- | :------------------ | :------------------------------------------------------------------------------ |
251251
| `/librarian` | Mount (Read/Write) | Contains `release-init-request.json`. Container writes back a `release-init-response.json`. |
252-
| `/repo` | Mount (Read) | Parts of the language repo. This directory will contain all directories that make up a library, the .librarian folder, and any global file declared in the `config.yaml`. |
252+
| `/repo` | Mount (Read) | Read-only contents of the language repo including any global files declared in the `config.yaml`. |
253253
| `/output` | Mount (Write) | Any files updated during the release phase should be moved to this directory, preserving their original paths. |
254254
| `command` | Positional Argument | The value will always be `release-init`. |
255255
| flags. | Flags | Flags indicating the locations of the mounts: `--librarian`, `--repo`, `--output` |
@@ -307,10 +307,12 @@ global file edits. The libraries that are being released will be marked by the `
307307
"error": "An optional field to share error context back to Librarian."
308308
}
309309
```
310+
310311
[config-schema.md]:config-schema.md
311312
[state-schema.md]: state-schema.md
312313

313314
## Language repository settings
315+
314316
To correctly parse the commit message of a merge commit, only allow squash merging
315317
and set the default commit message to **Pull request title and description**.
316318
![Pull request settings](assets/setting-pull-requests.webp)

internal/docker/docker.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ type ReleaseInitRequest struct {
160160
// generate code.
161161
Output string
162162

163-
// PartialRepoDir is the local root directory of language repository contains
163+
// RepoDir is the local root directory of language repository contains
164164
// files that make up libraries and global files.
165165
// This is the directory that container can access.
166-
PartialRepoDir string
166+
RepoDir string
167167

168168
// Push determines whether to push changes to GitHub.
169169
Push bool
@@ -298,7 +298,7 @@ func (c *Docker) Configure(ctx context.Context, request *ConfigureRequest) (stri
298298

299299
// ReleaseInit initiates a release for a given language repository.
300300
func (c *Docker) ReleaseInit(ctx context.Context, request *ReleaseInitRequest) error {
301-
reqFilePath := filepath.Join(request.PartialRepoDir, config.LibrarianDir, config.ReleaseInitRequest)
301+
reqFilePath := filepath.Join(request.RepoDir, config.LibrarianDir, config.ReleaseInitRequest)
302302
if err := writeLibrarianState(request.State, reqFilePath); err != nil {
303303
return err
304304
}
@@ -317,10 +317,10 @@ func (c *Docker) ReleaseInit(ctx context.Context, request *ReleaseInitRequest) e
317317
"--output=/output",
318318
}
319319

320-
librarianDir := filepath.Join(request.PartialRepoDir, config.LibrarianDir)
320+
librarianDir := filepath.Join(request.RepoDir, config.LibrarianDir)
321321
mounts := []string{
322322
fmt.Sprintf("%s:/librarian", librarianDir),
323-
fmt.Sprintf("%s:/repo:ro", request.PartialRepoDir), // readonly volume
323+
fmt.Sprintf("%s:/repo:ro", request.RepoDir), // readonly volume
324324
fmt.Sprintf("%s:/output", request.Output),
325325
}
326326

internal/docker/docker_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ func TestDockerRun(t *testing.T) {
418418
State: state,
419419
Output: testOutput,
420420
LibrarianConfig: &config.LibrarianConfig{},
421-
PartialRepoDir: partialRepoDir,
421+
RepoDir: partialRepoDir,
422422
}
423423

424424
defer os.RemoveAll(partialRepoDir)
@@ -450,7 +450,7 @@ func TestDockerRun(t *testing.T) {
450450

451451
releaseInitRequest := &ReleaseInitRequest{
452452
State: state,
453-
PartialRepoDir: partialRepoDir,
453+
RepoDir: partialRepoDir,
454454
Output: testOutput,
455455
LibrarianConfig: &config.LibrarianConfig{},
456456
}
@@ -468,9 +468,9 @@ func TestDockerRun(t *testing.T) {
468468
},
469469
runCommand: func(ctx context.Context, d *Docker) error {
470470
releaseInitRequest := &ReleaseInitRequest{
471-
State: state,
472-
PartialRepoDir: "/non-exist-dir",
473-
Output: testOutput,
471+
State: state,
472+
RepoDir: "/non-exist-dir",
473+
Output: testOutput,
474474
}
475475

476476
return d.ReleaseInit(ctx, releaseInitRequest)
@@ -490,7 +490,7 @@ func TestDockerRun(t *testing.T) {
490490
}
491491
releaseInitRequest := &ReleaseInitRequest{
492492
State: state,
493-
PartialRepoDir: partialRepoDir,
493+
RepoDir: partialRepoDir,
494494
Output: testOutput,
495495
LibraryID: testLibraryID,
496496
LibrarianConfig: &config.LibrarianConfig{},
@@ -524,7 +524,7 @@ func TestDockerRun(t *testing.T) {
524524

525525
releaseInitRequest := &ReleaseInitRequest{
526526
State: state,
527-
PartialRepoDir: partialRepoDir,
527+
RepoDir: partialRepoDir,
528528
Output: testOutput,
529529
LibraryID: testLibraryID,
530530
LibraryVersion: "1.2.3",
@@ -901,7 +901,7 @@ func TestReleaseInitRequestContent(t *testing.T) {
901901

902902
req := &ReleaseInitRequest{
903903
State: stateWithChanges,
904-
PartialRepoDir: partialRepoDir,
904+
RepoDir: partialRepoDir,
905905
Output: filepath.Join(tmpDir, "output"),
906906
LibrarianConfig: &config.LibrarianConfig{},
907907
}

internal/librarian/mocks_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ func (m *mockContainerClient) ReleaseInit(ctx context.Context, request *docker.R
281281
return m.initErr
282282
}
283283
// Write a release-init-response.json unless we're configured not to.
284-
if err := os.MkdirAll(filepath.Join(request.PartialRepoDir, ".librarian"), 0755); err != nil {
284+
if err := os.MkdirAll(filepath.Join(request.RepoDir, ".librarian"), 0755); err != nil {
285285
return err
286286
}
287287

@@ -293,7 +293,7 @@ func (m *mockContainerClient) ReleaseInit(ctx context.Context, request *docker.R
293293
if err != nil {
294294
return err
295295
}
296-
if err := os.WriteFile(filepath.Join(request.PartialRepoDir, ".librarian", config.ReleaseInitResponse), b, 0755); err != nil {
296+
if err := os.WriteFile(filepath.Join(request.RepoDir, ".librarian", config.ReleaseInitResponse), b, 0755); err != nil {
297297
return err
298298
}
299299
return m.initErr

internal/librarian/release_init.go

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ type initRunner struct {
3838
librarianConfig *config.LibrarianConfig
3939
library string
4040
libraryVersion string
41-
partialRepo string
4241
push bool
4342
repo gitrepo.Repository
4443
sourceRepo gitrepo.Repository
@@ -60,7 +59,6 @@ func newInitRunner(cfg *config.Config) (*initRunner, error) {
6059
librarianConfig: runner.librarianConfig,
6160
library: cfg.Library,
6261
libraryVersion: cfg.LibraryVersion,
63-
partialRepo: filepath.Join(runner.workRoot, "release-init"),
6462
push: cfg.Push,
6563
repo: runner.repo,
6664
sourceRepo: runner.sourceRepo,
@@ -126,11 +124,6 @@ func hasLibrariesToRelease(libraryStates []*config.LibraryState) bool {
126124
}
127125

128126
func (r *initRunner) runInitCommand(ctx context.Context, outputDir string) error {
129-
dst := r.partialRepo
130-
if err := os.MkdirAll(dst, 0755); err != nil {
131-
return fmt.Errorf("failed to make directory: %w", err)
132-
}
133-
134127
src := r.repo.GetDir()
135128
librariesToRelease := r.state.Libraries
136129
if r.library != "" {
@@ -158,9 +151,6 @@ func (r *initRunner) runInitCommand(ctx context.Context, outputDir string) error
158151
// Copy the library files over if a release is needed
159152
if library.ReleaseTriggered {
160153
foundReleasableLibrary = true
161-
if err := copyLibraryFiles(r.state, dst, library.ID, src); err != nil {
162-
return err
163-
}
164154
}
165155
}
166156

@@ -169,22 +159,14 @@ func (r *initRunner) runInitCommand(ctx context.Context, outputDir string) error
169159
return nil
170160
}
171161

172-
if err := copyLibrarianDir(dst, src); err != nil {
173-
return fmt.Errorf("failed to copy librarian dir from %s to %s: %w", src, dst, err)
174-
}
175-
176-
if err := copyGlobalAllowlist(r.librarianConfig, dst, src, true); err != nil {
177-
return fmt.Errorf("failed to copy global allowlist from %s to %s: %w", src, dst, err)
178-
}
179-
180162
initRequest := &docker.ReleaseInitRequest{
181163
Branch: r.branch,
182164
Commit: r.commit,
183165
LibrarianConfig: r.librarianConfig,
184166
LibraryID: r.library,
185167
LibraryVersion: r.libraryVersion,
186168
Output: outputDir,
187-
PartialRepoDir: dst,
169+
RepoDir: src,
188170
Push: r.push,
189171
State: r.state,
190172
}
@@ -195,7 +177,7 @@ func (r *initRunner) runInitCommand(ctx context.Context, outputDir string) error
195177

196178
// Read the response file.
197179
if _, err := readLibraryState(
198-
filepath.Join(initRequest.PartialRepoDir, config.LibrarianDir, config.ReleaseInitResponse)); err != nil {
180+
filepath.Join(initRequest.RepoDir, config.LibrarianDir, config.ReleaseInitResponse)); err != nil {
199181
return err
200182
}
201183

@@ -327,9 +309,3 @@ func copyGlobalAllowlist(cfg *config.LibrarianConfig, dst, src string, copyReadO
327309
}
328310
return nil
329311
}
330-
331-
func copyLibrarianDir(dst, src string) error {
332-
return os.CopyFS(
333-
filepath.Join(dst, config.LibrarianDir),
334-
os.DirFS(filepath.Join(src, config.LibrarianDir)))
335-
}

0 commit comments

Comments
 (0)