-
Notifications
You must be signed in to change notification settings - Fork 65
feat(tools): install Vite+ releases #7338
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
afonsojramos
wants to merge
11
commits into
containerbase:main
Choose a base branch
from
afonsojramos:feat/vite-plus-tool
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.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5873710
feat(tools): add Vite+ installer
afonsojramos f34cf95
test(vp): validate released planner in Docker
afonsojramos 6d5d561
refactor(vp): align installer and tests with Node tooling
afonsojramos b808d01
Merge branch 'main' into feat/vite-plus-tool
afonsojramos 80a118d
test(vp): use async I/O for planner checks
afonsojramos 0eb2445
chore: undo rolldown change
afonsojramos c9bdbe5
fix(vp): run unbundled planner tests with Vite+ 1.0
afonsojramos 19c714b
test(vp): run planner check with node:child_process
afonsojramos f2b16f0
chore(renovate): drop Vite+ test fixture rule
afonsojramos 6319ffe
test(vp): report vp failures when it exits before reading stdin
afonsojramos 0136977
Merge branch 'main' into feat/vite-plus-tool
afonsojramos 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
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 |
|---|---|---|
|
|
@@ -51,6 +51,7 @@ export const NoPrepareTools = [ | |
| 'tofu', | ||
| 'uv', | ||
| 'vendir', | ||
| 'vp', | ||
| 'wally', | ||
| 'yarn', | ||
| 'yarn-slim', | ||
|
|
||
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,149 @@ | ||
| import fs from 'node:fs/promises'; | ||
| import { arch } from 'node:os'; | ||
| import { join } from 'node:path'; | ||
| import { execa } from 'execa'; | ||
| import type { Container } from 'inversify'; | ||
| import { beforeAll, beforeEach, describe, expect, test, vi } from 'vitest'; | ||
|
|
||
| import { | ||
| CompressionService, | ||
| HttpService, | ||
| LinkToolService, | ||
| } from '../../services/index.ts'; | ||
| import { | ||
| VP_SYNC_VERSIONS_UNAVAILABLE, | ||
| VpInstallService, | ||
| parseVitePlusChecksum, | ||
| vitePlusAssetName, | ||
| } from './vp.ts'; | ||
| import { testContainer } from '~test/di.ts'; | ||
| import { ensurePaths } from '~test/path.ts'; | ||
|
|
||
| vi.mock('execa'); | ||
|
|
||
| describe('cli/tools/node/vp', () => { | ||
| describe('release assets', () => { | ||
| test.each([ | ||
| ['amd64', 'vp-x86_64-unknown-linux-gnu.tar.gz'], | ||
| ['arm64', 'vp-aarch64-unknown-linux-gnu.tar.gz'], | ||
| ] as const)('maps %s to the official release asset', (arch, expected) => { | ||
| expect(vitePlusAssetName(arch)).toBe(expected); | ||
| }); | ||
|
|
||
| test('selects an exact release asset checksum', () => { | ||
| expect( | ||
| parseVitePlusChecksum( | ||
| [ | ||
| 'a'.repeat(64) + ' vp-aarch64-unknown-linux-gnu.tar.gz', | ||
| 'b'.repeat(64) + ' vp-x86_64-unknown-linux-gnu.tar.gz', | ||
| '', | ||
| ].join('\n'), | ||
| 'vp-x86_64-unknown-linux-gnu.tar.gz', | ||
| ), | ||
| ).toBe('b'.repeat(64)); | ||
| }); | ||
|
|
||
| test('rejects missing or malformed checksums', () => { | ||
| expect(() => | ||
| parseVitePlusChecksum('', 'vp-x86_64-unknown-linux-gnu.tar.gz'), | ||
| ).toThrow('Cannot find checksum'); | ||
| expect(() => | ||
| parseVitePlusChecksum( | ||
| 'not-a-checksum vp-x86_64-unknown-linux-gnu.tar.gz', | ||
| 'vp-x86_64-unknown-linux-gnu.tar.gz', | ||
| ), | ||
| ).toThrow('Cannot find checksum'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('VpInstallService', () => { | ||
| let child: Container; | ||
| let service: VpInstallService; | ||
|
|
||
| beforeAll(async () => { | ||
| await ensurePaths([ | ||
| 'opt/containerbase/bin', | ||
| 'opt/containerbase/tools', | ||
| 'tmp/containerbase', | ||
| 'var/lib/containerbase', | ||
| ]); | ||
| }); | ||
|
|
||
| beforeEach(async () => { | ||
| child = await testContainer(); | ||
| child.bind(HttpService).toSelf(); | ||
| child.bind(CompressionService).toSelf(); | ||
| child.bind(LinkToolService).toSelf(); | ||
| child.bind(VpInstallService).toSelf(); | ||
| service = await child.getAsync(VpInstallService); | ||
| }); | ||
|
|
||
| test('downloads, verifies, and extracts the exact prebuilt release', async () => { | ||
| const filename = vitePlusAssetName( | ||
| arch() === 'arm64' ? 'arm64' : 'amd64', | ||
| ); | ||
| const checksum = 'c'.repeat(64); | ||
| const checksumFile = join(globalThis.cacheDir, 'vp-checksums.txt'); | ||
| const archiveFile = join(globalThis.cacheDir, filename); | ||
| await fs.writeFile(checksumFile, `${checksum} ${filename}\n`); | ||
| await fs.writeFile(archiveFile, 'archive'); | ||
|
|
||
| const download = vi | ||
| .spyOn(HttpService.prototype, 'download') | ||
| .mockResolvedValueOnce(checksumFile) | ||
| .mockResolvedValueOnce(archiveFile); | ||
| vi.spyOn(HttpService.prototype, 'exists').mockResolvedValueOnce(true); | ||
| const extract = vi | ||
| .spyOn(CompressionService.prototype, 'extract') | ||
| .mockResolvedValueOnce(); | ||
|
|
||
| await service.install('0.4.0'); | ||
|
|
||
| expect(download).toHaveBeenNthCalledWith(1, { | ||
| url: 'https://github.com/voidzero-dev/vite-plus/releases/download/v0.4.0/vp-checksums.txt', | ||
| }); | ||
| expect(download).toHaveBeenNthCalledWith(2, { | ||
| url: `https://github.com/voidzero-dev/vite-plus/releases/download/v0.4.0/${filename}`, | ||
| checksumType: 'sha256', | ||
| expectedChecksum: checksum, | ||
| }); | ||
| expect(extract).toHaveBeenCalledWith({ | ||
| file: archiveFile, | ||
| cwd: expect.stringMatching(/\/vp\/0\.4\.0\/bin$/), | ||
| }); | ||
| }); | ||
|
|
||
| test('rejects releases that predate the bundled planner', async () => { | ||
| vi.spyOn(HttpService.prototype, 'exists').mockResolvedValueOnce(false); | ||
| const download = vi.spyOn(HttpService.prototype, 'download'); | ||
|
|
||
| await expect(service.install('0.3.0')).rejects.toThrow( | ||
| `${VP_SYNC_VERSIONS_UNAVAILABLE}:0.3.0`, | ||
| ); | ||
| expect(download).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| test('links vp with the Node runtime needed by the bundled planner', async () => { | ||
| const shellwrapper = vi | ||
| .spyOn(LinkToolService.prototype, 'shellwrapper') | ||
| .mockResolvedValueOnce(); | ||
|
|
||
| await service.link('0.4.0'); | ||
|
|
||
| expect(shellwrapper).toHaveBeenCalledWith('vp', { | ||
| srcDir: expect.stringMatching(/\/vp\/0\.4\.0\/bin$/), | ||
| extraToolEnvs: ['node'], | ||
| }); | ||
| }); | ||
|
|
||
| test('checks the installed vp version', async () => { | ||
| await service.test('0.4.0'); | ||
|
|
||
| expect(execa).toHaveBeenCalledExactlyOnceWith( | ||
| 'vp', | ||
| ['--version'], | ||
| expect.any(Object), | ||
| ); | ||
| }); | ||
| }); | ||
| }); |
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,77 @@ | ||
| import fs from 'node:fs/promises'; | ||
| import { join } from 'node:path'; | ||
| import { injectFromHierarchy, injectable } from 'inversify'; | ||
| import { BaseInstallService } from '../../install-tool/base-install.service.ts'; | ||
| import type { Arch } from '../../utils/index.ts'; | ||
|
|
||
| // Stable machine-readable marker consumed by Renovate. Do not reword it. | ||
| export const VP_SYNC_VERSIONS_UNAVAILABLE = | ||
| 'CONTAINERBASE_VP_SYNC_VERSIONS_UNAVAILABLE'; | ||
|
|
||
| export function vitePlusAssetName(arch: Arch): string { | ||
| const target = arch === 'arm64' ? 'aarch64' : 'x86_64'; | ||
| return `vp-${target}-unknown-linux-gnu.tar.gz`; | ||
| } | ||
|
|
||
| export function parseVitePlusChecksum( | ||
| checksums: string, | ||
| filename: string, | ||
| ): string { | ||
| for (const line of checksums.split('\n')) { | ||
| const match = /^([a-f\d]{64})\s+\*?(.+)$/i.exec(line.trim()); | ||
| const checksum = match?.[1]; | ||
| if (checksum && match?.[2] === filename) { | ||
| return checksum.toLowerCase(); | ||
| } | ||
| } | ||
| throw new Error(`Cannot find checksum for '${filename}' in vp-checksums.txt`); | ||
| } | ||
|
|
||
| @injectable() | ||
| @injectFromHierarchy() | ||
| export class VpInstallService extends BaseInstallService { | ||
| readonly name = 'vp'; | ||
| override readonly parent = 'node'; | ||
|
|
||
| override async install(version: string): Promise<void> { | ||
| const baseUrl = `https://github.com/voidzero-dev/vite-plus/releases/download/v${version}/`; | ||
| const filename = vitePlusAssetName(this.envSvc.arch); | ||
| const checksumUrl = `${baseUrl}vp-checksums.txt`; | ||
|
|
||
| if (!(await this.http.exists(checksumUrl))) { | ||
| throw new Error( | ||
| `${VP_SYNC_VERSIONS_UNAVAILABLE}:${version}: Vite+ release does not provide the sync-versions planner`, | ||
| ); | ||
| } | ||
|
|
||
| const checksumFile = await this.http.download({ | ||
| url: checksumUrl, | ||
| }); | ||
| const expectedChecksum = parseVitePlusChecksum( | ||
| await fs.readFile(checksumFile, 'utf8'), | ||
| filename, | ||
| ); | ||
| const file = await this.http.download({ | ||
| url: `${baseUrl}${filename}`, | ||
| checksumType: 'sha256', | ||
| expectedChecksum, | ||
| }); | ||
|
|
||
| await this.pathSvc.ensureToolPath(this.name); | ||
| const path = join( | ||
| await this.pathSvc.createVersionedToolPath(this.name, version), | ||
| 'bin', | ||
| ); | ||
| await fs.mkdir(path); | ||
| await this.compress.extract({ file, cwd: path }); | ||
| } | ||
|
|
||
| override async link(version: string): Promise<void> { | ||
| const src = join(this.pathSvc.versionedToolPath(this.name, version), 'bin'); | ||
| await this.shellwrapper({ srcDir: src, extraToolEnvs: ['node'] }); | ||
| } | ||
|
|
||
| override async test(_version: string): Promise<void> { | ||
| await this._spawn(this.name, ['--version']); | ||
| } | ||
| } |
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
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
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.