Repository navigation
Expand file tree
/
Copy pathtofu.ts
More file actions
64 lines (53 loc) · 1.8 KB
/
Copy pathtofu.ts
File metadata and controls
64 lines (53 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { join } from 'node:path';
import { injectFromHierarchy, injectable } from 'inversify';
import { BaseInstallService } from '../install-tool/base-install.service.ts';
@injectable()
@injectFromHierarchy()
export class TofuInstallService extends BaseInstallService {
readonly name = 'tofu';
/** The architecture name used by the tofu release assets. */
private get ghArch(): string {
return this.envSvc.arch;
}
/**
* Downloads the tofu archive from GitHub, verified against the release's
* `SHA256SUMS`, and extracts it into the versioned `bin` folder.
*/
override async install(version: string): Promise<void> {
/**
* @example
* @see {@href https://github.com/opentofu/opentofu/releases/tag/v1.10.6}
*/
const baseUrl = `https://github.com/opentofu/opentofu/releases/download/v${version}/`;
const filename = `tofu_${version}_linux_${this.ghArch}.tar.gz`;
const url = `${baseUrl}${filename}`;
const expectedChecksum = await this.findChecksum(
`${baseUrl}tofu_${version}_SHA256SUMS`,
filename,
);
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,
'bin',
);
await this.compress.extract({
file,
cwd: path,
});
}
/** Links the `tofu` binary into the global bin folder. */
override async link(version: string): Promise<void> {
const src = join(this.pathSvc.versionedToolPath(this.name, version), 'bin');
await this.shellwrapper({ srcDir: src });
}
/** Checks that `tofu --version` runs. */
override async test(_version: string): Promise<void> {
await this._spawn(this.name, ['--version']);
}
}