-
Notifications
You must be signed in to change notification settings - Fork 11.9k
feat(@angular/build): share persistent build cache across git worktrees #33519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
clydin
wants to merge
1
commit into
angular:main
Choose a base branch
from
clydin:feat-cache-share-git-worktrees
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+281
−6
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /** | ||
| * @license | ||
| * Copyright Google LLC All Rights Reserved. | ||
| * | ||
| * Use of this source code is governed by an MIT-style license that can be | ||
| * found in the LICENSE file at https://angular.dev/license | ||
| */ | ||
|
|
||
| import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'; | ||
| import { tmpdir } from 'node:os'; | ||
| import { join, resolve } from 'node:path'; | ||
| import { normalizeCacheOptions } from './normalize-cache'; | ||
|
|
||
| describe('normalizeCacheOptions', () => { | ||
| let tempDir: string; | ||
|
|
||
| beforeEach(async () => { | ||
| tempDir = await mkdtemp(join(tmpdir(), 'angular-cache-spec-')); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| await rm(tempDir, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| it('should resolve cache path relative to workspace root in a standard repository', async () => { | ||
| const workspaceRoot = join(tempDir, 'project'); | ||
| await mkdir(join(workspaceRoot, '.git'), { recursive: true }); | ||
|
|
||
| const options = normalizeCacheOptions({}, workspaceRoot); | ||
|
|
||
| expect(options.basePath).toBe(resolve(workspaceRoot, '.angular/cache')); | ||
| }); | ||
|
|
||
| it('should resolve cache path relative to main repository root in a git worktree', async () => { | ||
| const mainRepoRoot = join(tempDir, 'main-repo'); | ||
| const mainGitDir = join(mainRepoRoot, '.git'); | ||
| const worktreeRoot = join(tempDir, 'worktree'); | ||
|
|
||
| // Create main repo structure | ||
| await mkdir(mainGitDir, { recursive: true }); | ||
|
|
||
| // Create worktree folder and .git file pointing to the main repo's worktree metadata folder | ||
| const worktreeMetadataDir = join(mainGitDir, 'worktrees/wt-1'); | ||
| await mkdir(worktreeMetadataDir, { recursive: true }); | ||
| await mkdir(worktreeRoot, { recursive: true }); | ||
| await writeFile(join(worktreeRoot, '.git'), `gitdir: ${worktreeMetadataDir}`); | ||
|
|
||
| // Create the commondir file in the worktree metadata folder pointing back to the main .git dir | ||
| await writeFile(join(worktreeMetadataDir, 'commondir'), '../..'); | ||
|
|
||
| const options = normalizeCacheOptions({}, worktreeRoot); | ||
|
|
||
| expect(options.basePath).toBe(resolve(mainRepoRoot, '.angular/cache')); | ||
| }); | ||
|
|
||
| it('should resolve cache path relative to workspace root in a git submodule', async () => { | ||
| const mainRepoRoot = join(tempDir, 'main-repo'); | ||
| const submoduleRoot = join(mainRepoRoot, 'submodule'); | ||
|
|
||
| // Create main repo structure and submodule metadata folder | ||
| const submoduleGitDir = join(mainRepoRoot, '.git/modules/sub'); | ||
| await mkdir(submoduleGitDir, { recursive: true }); | ||
| await mkdir(submoduleRoot, { recursive: true }); | ||
|
|
||
| // Create .git file in submodule pointing to the metadata folder | ||
| await writeFile(join(submoduleRoot, '.git'), `gitdir: ../.git/modules/sub`); | ||
|
|
||
| // Submodules do NOT have a 'commondir' file. | ||
| const options = normalizeCacheOptions({}, submoduleRoot); | ||
|
|
||
| expect(options.basePath).toBe(resolve(submoduleRoot, '.angular/cache')); | ||
| }); | ||
|
|
||
| it('should resolve cache path relative to workspace root when there is no git repository', async () => { | ||
| const workspaceRoot = join(tempDir, 'project'); | ||
| await mkdir(workspaceRoot, { recursive: true }); | ||
|
|
||
| const options = normalizeCacheOptions({}, workspaceRoot); | ||
|
|
||
| expect(options.basePath).toBe(resolve(workspaceRoot, '.angular/cache')); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
packages/angular/cli/src/commands/cache/utilities_spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| /** | ||
| * @license | ||
| * Copyright Google LLC All Rights Reserved. | ||
| * | ||
| * Use of this source code is governed by an MIT-style license that can be | ||
| * found in the LICENSE file at https://angular.dev/license | ||
| */ | ||
|
|
||
| import { workspaces } from '@angular-devkit/core'; | ||
| import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'; | ||
| import { tmpdir } from 'node:os'; | ||
| import { join, resolve } from 'node:path'; | ||
| import { AngularWorkspace } from '../../utilities/config'; | ||
| import { getCacheConfig } from './utilities'; | ||
|
|
||
| describe('CLI cache config utilities', () => { | ||
| let tempDir: string; | ||
|
|
||
| beforeEach(async () => { | ||
| tempDir = await mkdtemp(join(tmpdir(), 'angular-cli-cache-spec-')); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| await rm(tempDir, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| function mockWorkspace(basePath: string, cliExtension?: unknown): AngularWorkspace { | ||
| return { | ||
| basePath, | ||
| extensions: cliExtension ? { cli: cliExtension } : {}, | ||
| projects: {} as unknown as workspaces.ProjectDefinitionCollection, | ||
| filePath: join(basePath, 'angular.json'), | ||
| getCli: () => cliExtension, | ||
| getProjectCli: () => undefined, | ||
| save: () => Promise.resolve(), | ||
| } as unknown as AngularWorkspace; | ||
| } | ||
|
|
||
| it('should resolve default cache path relative to workspace basePath in a standard repository', async () => { | ||
| const workspaceRoot = join(tempDir, 'project'); | ||
| await mkdir(join(workspaceRoot, '.git'), { recursive: true }); | ||
|
|
||
| const config = getCacheConfig(mockWorkspace(workspaceRoot)); | ||
|
|
||
| expect(config.path).toBe(resolve(workspaceRoot, '.angular/cache')); | ||
| }); | ||
|
|
||
| it('should resolve default cache path relative to main repository root in a git worktree', async () => { | ||
| const mainRepoRoot = join(tempDir, 'main-repo'); | ||
| const mainGitDir = join(mainRepoRoot, '.git'); | ||
| const worktreeRoot = join(tempDir, 'worktree'); | ||
|
|
||
| // Create main repo structure | ||
| await mkdir(mainGitDir, { recursive: true }); | ||
|
|
||
| // Create worktree folder and .git file pointing to the main repo's worktree metadata folder | ||
| const worktreeMetadataDir = join(mainGitDir, 'worktrees/wt-1'); | ||
| await mkdir(worktreeMetadataDir, { recursive: true }); | ||
| await mkdir(worktreeRoot, { recursive: true }); | ||
| await writeFile(join(worktreeRoot, '.git'), `gitdir: ${worktreeMetadataDir}`); | ||
|
|
||
| // Create the commondir file in the worktree metadata folder pointing back to the main .git dir | ||
| await writeFile(join(worktreeMetadataDir, 'commondir'), '../..'); | ||
|
|
||
| const config = getCacheConfig(mockWorkspace(worktreeRoot)); | ||
|
|
||
| expect(config.path).toBe(resolve(mainRepoRoot, '.angular/cache')); | ||
| }); | ||
|
|
||
| it('should resolve custom relative cache path relative to main repository root in a git worktree', async () => { | ||
| const mainRepoRoot = join(tempDir, 'main-repo'); | ||
| const mainGitDir = join(mainRepoRoot, '.git'); | ||
| const worktreeRoot = join(tempDir, 'worktree'); | ||
|
|
||
| // Create main repo structure | ||
| await mkdir(mainGitDir, { recursive: true }); | ||
|
|
||
| // Create worktree folder and .git file pointing to the main repo's worktree metadata folder | ||
| const worktreeMetadataDir = join(mainGitDir, 'worktrees/wt-1'); | ||
| await mkdir(worktreeMetadataDir, { recursive: true }); | ||
| await mkdir(worktreeRoot, { recursive: true }); | ||
| await writeFile(join(worktreeRoot, '.git'), `gitdir: ${worktreeMetadataDir}`); | ||
|
|
||
| // Create the commondir file in the worktree metadata folder pointing back to the main .git dir | ||
| await writeFile(join(worktreeMetadataDir, 'commondir'), '../..'); | ||
|
|
||
| const config = getCacheConfig( | ||
| mockWorkspace(worktreeRoot, { cache: { path: 'custom/cache-dir' } }), | ||
| ); | ||
|
|
||
| expect(config.path).toBe(resolve(mainRepoRoot, 'custom/cache-dir')); | ||
| }); | ||
|
|
||
| it('should resolve cache path relative to workspace basePath in a git submodule', async () => { | ||
| const mainRepoRoot = join(tempDir, 'main-repo'); | ||
| const submoduleRoot = join(mainRepoRoot, 'submodule'); | ||
|
|
||
| // Create main repo structure and submodule metadata folder | ||
| const submoduleGitDir = join(mainRepoRoot, '.git/modules/sub'); | ||
| await mkdir(submoduleGitDir, { recursive: true }); | ||
| await mkdir(submoduleRoot, { recursive: true }); | ||
|
|
||
| // Create .git file in submodule pointing to the metadata folder | ||
| await writeFile(join(submoduleRoot, '.git'), `gitdir: ../.git/modules/sub`); | ||
|
|
||
| // Submodules do NOT have a 'commondir' file. | ||
| const config = getCacheConfig(mockWorkspace(submoduleRoot)); | ||
|
|
||
| expect(config.path).toBe(resolve(submoduleRoot, '.angular/cache')); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.