-
Notifications
You must be signed in to change notification settings - Fork 64
feat(tool): install nub from GitHub release binaries #7463
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
jpenilla
wants to merge
7
commits into
containerbase:main
Choose a base branch
from
jpenilla:feat/nub-release-binaries
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
7 commits
Select commit
Hold shift + click to select a range
4c49fa3
feat(tool): install nub from GitHub release binaries
jpenilla 6eba5ea
docs: document nub release download URLs
jpenilla a5aaa52
chore(nub): update release examples and tests to v0.9.3
jpenilla 9994070
chore(nub): include tool in test metadata
jpenilla 2009b01
test(nub): cover release installation and checksum validation
jpenilla fdd542a
Merge remote-tracking branch 'upstream/main' into feat/nub-release-bi…
jpenilla 237f07a
refactor(nub): use shared checksum helper
jpenilla 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 |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ export const NoPrepareTools = [ | |
| 'maven', | ||
| 'mise', | ||
| 'nix', | ||
| 'nub', | ||
| 'nuget', | ||
| 'npm', | ||
| 'paket', | ||
|
|
||
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,75 @@ | ||
| import { arch } from 'node:os'; | ||
| import { join } from 'node:path'; | ||
| import { beforeAll, beforeEach, describe, expect, test, vi } from 'vitest'; | ||
| import { CompressionService, LinkToolService } from '../services/index.ts'; | ||
| import { NubInstallService } from './nub.ts'; | ||
| import { scope } from '~test/http-mock.ts'; | ||
| import { ensurePaths } from '~test/path.ts'; | ||
| import { checksum, toolContext } from '~test/tool.ts'; | ||
|
|
||
| const { execaMock } = vi.hoisted(() => ({ execaMock: vi.fn() })); | ||
| vi.mock('execa', () => ({ execa: execaMock })); | ||
| vi.mock('node:os', async (importOriginal) => ({ | ||
| ...(await importOriginal<typeof import('node:os')>()), | ||
| arch: vi.fn(() => 'x64'), | ||
| })); | ||
|
|
||
| const baseUrl = 'https://github.com'; | ||
| const archive = 'nub archive'; | ||
|
|
||
| describe('cli/tools/nub', () => { | ||
| beforeAll(async () => { | ||
| await ensurePaths(['tmp', 'opt/containerbase/bin']); | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| vi.mocked(arch).mockReturnValue('x64'); | ||
| execaMock.mockResolvedValue({ failed: false }); | ||
| }); | ||
|
|
||
| test.each([ | ||
| { hostArch: 'x64', ghArch: 'x64', version: '0.9.3' }, | ||
| { hostArch: 'arm64', ghArch: 'arm64', version: '0.9.2' }, | ||
| ] as const)('install on $ghArch', async ({ hostArch, ghArch, version }) => { | ||
| vi.mocked(arch).mockReturnValue(hostArch); | ||
| const { svc, pathSvc } = await toolContext(NubInstallService); | ||
| const filename = `nub-linux-${ghArch}.tar.gz`; | ||
| const releaseUrl = `/nubjs/nub/releases/download/v${version}`; | ||
| scope(baseUrl) | ||
| .get(`${releaseUrl}/${filename}.sha256`) | ||
| .reply(200, `${checksum(archive)} ${filename}\n`) | ||
| .get(`${releaseUrl}/${filename}`) | ||
| .reply(200, archive); | ||
| const extract = vi.spyOn(CompressionService.prototype, 'extract'); | ||
|
|
||
| await expect(svc.install(version)).resolves.toBeUndefined(); | ||
|
|
||
| expect(extract).toHaveBeenCalledExactlyOnceWith({ | ||
| file: expect.stringContaining(filename), | ||
| cwd: pathSvc.versionedToolPath('nub', version), | ||
| }); | ||
| }); | ||
|
|
||
| test('link', async () => { | ||
| const { svc, pathSvc } = await toolContext(NubInstallService); | ||
| const spy = vi.spyOn(LinkToolService.prototype, 'shellwrapper'); | ||
|
|
||
| await expect(svc.link('0.9.3')).resolves.toBeUndefined(); | ||
|
|
||
| expect(spy).toHaveBeenCalledExactlyOnceWith('nub', { | ||
| srcDir: join(pathSvc.versionedToolPath('nub', '0.9.3'), 'bin'), | ||
| }); | ||
| }); | ||
|
|
||
| test('runs the tool test', async () => { | ||
| const { svc } = await toolContext(NubInstallService); | ||
|
|
||
| await expect(svc.test('0.9.3')).resolves.toBeUndefined(); | ||
|
|
||
| expect(execaMock).toHaveBeenCalledWith( | ||
| 'nub', | ||
| ['--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,46 @@ | ||
| import { join } from 'node:path'; | ||
| import { injectFromHierarchy, injectable } from 'inversify'; | ||
| import { BaseInstallService } from '../install-tool/base-install.service.ts'; | ||
|
|
||
| @injectable() | ||
| @injectFromHierarchy() | ||
| export class NubInstallService extends BaseInstallService { | ||
| readonly name = 'nub'; | ||
|
|
||
| private get ghArch(): string { | ||
| switch (this.envSvc.arch) { | ||
| case 'arm64': | ||
| return 'arm64'; | ||
| case 'amd64': | ||
| return 'x64'; | ||
| } | ||
| } | ||
|
|
||
| override async install(version: string): Promise<void> { | ||
| const baseUrl = `https://github.com/nubjs/nub/releases/download/v${version}/`; | ||
| const filename = `nub-linux-${this.ghArch}.tar.gz`; | ||
| const url = `${baseUrl}${filename}`; | ||
|
|
||
| const expectedChecksum = await this.getChecksum(`${url}.sha256`); | ||
|
|
||
| const file = await this.http.download({ | ||
| url, | ||
| checksumType: 'sha256', | ||
| expectedChecksum, | ||
| }); | ||
|
|
||
| await this.pathSvc.ensureToolPath(this.name); | ||
| const path = await this.pathSvc.createVersionedToolPath(this.name, version); | ||
| // Preserve the release layout: bin/ and runtime/ are siblings. | ||
| 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 }); | ||
| } | ||
|
|
||
| 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
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.