Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"docker",
"dotnet",
"flutter",
"gh",
"git",
"git-lfs",
"gleam",
Expand Down Expand Up @@ -129,6 +130,7 @@
"docker",
"dotnet",
"flutter",
"gh",
"git",
"git-lfs",
"gleam",
Expand Down
14 changes: 14 additions & 0 deletions docs/custom-registries.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,20 @@ https://github.com/fluxcd/flux2/releases/download/v0.19.0/flux_0.19.0_linux_amd6
https://github.com/fluxcd/flux2/releases/download/v2.1.0/flux_2.1.0_linux_arm64.tar.gz
```

## `gh`

GitHub CLI releases are downloaded from:

- `https://github.com/cli/cli/releases`

Samples:

```txt
https://github.com/cli/cli/releases/download/v2.97.0/gh_2.97.0_linux_amd64.tar.gz
https://github.com/cli/cli/releases/download/v2.97.0/gh_2.97.0_linux_arm64.tar.gz
https://github.com/cli/cli/releases/download/v2.97.0/gh_2.97.0_checksums.txt
```

## `git`

Git is downloaded from:
Expand Down
2 changes: 2 additions & 0 deletions src/cli/install-tool/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { ElixirInstallService } from '../tools/erlang/elixir.ts';
import { ErlangInstallService } from '../tools/erlang/index.ts';
import { FlutterInstallService } from '../tools/flutter.ts';
import { FluxInstallService } from '../tools/flux.ts';
import { GhInstallService } from '../tools/gh.ts';
import { GitLfsInstallService } from '../tools/git/lfs.ts';
import { GleamInstallService } from '../tools/gleam.ts';
import { GolangInstallService } from '../tools/golang.ts';
Expand Down Expand Up @@ -154,6 +155,7 @@ async function prepareInstallContainer(): Promise<Container> {
container.bind(INSTALL_TOOL_TOKEN).to(ErlangInstallService);
container.bind(INSTALL_TOOL_TOKEN).to(FlutterInstallService);
container.bind(INSTALL_TOOL_TOKEN).to(FluxInstallService);
container.bind(INSTALL_TOOL_TOKEN).to(GhInstallService);
container.bind(INSTALL_TOOL_TOKEN).to(GitLfsInstallService);
container.bind(INSTALL_TOOL_TOKEN).to(GhcInstallService);
container.bind(INSTALL_TOOL_TOKEN).to(GleamInstallService);
Expand Down
63 changes: 63 additions & 0 deletions src/cli/tools/gh.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
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 { semverSatisfies } from '../utils/index.ts';

@injectable()
@injectFromHierarchy()
export class GhInstallService extends BaseInstallService {
readonly name = 'gh';

override async install(version: string): Promise<void> {
/**
* The GitHub CLI ships self-contained Go binaries as `gh_<version>_linux_<arch>.tar.gz` release assets, alongside a single `gh_<version>_checksums.txt` covering every asset of that release.
* @see {@link https://github.com/cli/cli/releases}
*/
const baseUrl = `https://github.com/cli/cli/releases/download/v${version}/`;
const dirname = `gh_${version}_linux_${this.envSvc.arch}`;
const filename = `${dirname}.tar.gz`;

const checksumFile = await this.http.download({
url: `${baseUrl}gh_${version}_checksums.txt`,
});
const expectedChecksum = (await fs.readFile(checksumFile, 'utf-8'))
.split('\n')
.find((l) => l.endsWith(filename))
?.split(/\s+/)[0];

const file = await this.http.download({
url: `${baseUrl}${filename}`,
checksumType: 'sha256',
expectedChecksum,
});

await this.pathSvc.ensureToolPath(this.name);

const path = await this.pathSvc.createVersionedToolPath(this.name, version);
// the archive also ships man pages and completions under `share/`, which
// aren't needed at runtime, so only extract `bin/gh`.
await this.compress.extract({
file,
cwd: path,
strip: 1,
files: [`${dirname}/bin/gh`],
});
}

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']);
}

override async validate(version: string): Promise<boolean> {
// only the `v2` line ships the release assets we consume
return (
(await super.validate(version)) && semverSatisfies(version, '^2.0.0')
);
}
}
1 change: 1 addition & 0 deletions src/cli/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const NoPrepareTools = [
'devbox',
'docker-compose',
'flux',
'gh',
'git-lfs',
'gleam',
'gradle',
Expand Down
11 changes: 10 additions & 1 deletion test/latest/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ RUN prepare-tool all
RUN set -ex; [ -d /usr/local/erlang ] && echo "works" || exit 1;

#--------------------------------------
# test: apm, bazelisk, buf, bun, deno, devbox, helmfile, kustomize, skopeo, tofu, vendir
# test: apm, bazelisk, buf, bun, deno, devbox, gh, helmfile, kustomize, skopeo, tofu, vendir
#--------------------------------------
FROM base AS teste

Expand All @@ -237,6 +237,11 @@ RUN install-tool apm 0.28.0
# renovate: datasource=github-releases packageName=jetify-com/devbox
RUN install-tool devbox 0.17.5

# renovate: datasource=github-releases depName=gh-dash packageName=dlvhdr/gh-dash
ENV GH_DASH_EXTENSION_VERSION=v4.25.2
# renovate: datasource=github-releases packageName=cli/cli
RUN install-tool gh v2.97.0

# renovate: datasource=github-releases packageName=gleam-lang/gleam
RUN install-tool gleam 1.18.1

Expand Down Expand Up @@ -291,6 +296,10 @@ USER 12021

RUN bazel --version

RUN gh --version
Comment thread
jamietanna marked this conversation as resolved.
RUN gh extension install dlvhdr/gh-dash --pin $GH_DASH_EXTENSION_VERSION
RUN gh dash --version

RUN vendir --version | grep "${VENDIR_VERSION#v}"

RUN helmfile version | grep "${HELMFILE_VERSION#v}"
Expand Down
9 changes: 9 additions & 0 deletions test/latest/Dockerfile.arm64
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ FROM base AS test-devbox
# renovate: datasource=github-releases packageName=jetify-com/devbox
RUN install-tool devbox 0.17.5

#--------------------------------------
# Image: gh
#--------------------------------------
FROM base AS test-gh

# renovate: datasource=github-releases packageName=cli/cli
RUN install-tool gh v2.97.0

#--------------------------------------
# Image: gleam
#--------------------------------------
Expand Down Expand Up @@ -217,6 +225,7 @@ COPY --from=test-apko /.dummy /.dummy
COPY --from=test-apm /.dummy /.dummy
COPY --from=test-devbox /.dummy /.dummy
COPY --from=test-docker /.dummy /.dummy
COPY --from=test-gh /.dummy /.dummy
COPY --from=test-git /.dummy /.dummy
COPY --from=test-git-lfs /.dummy /.dummy
COPY --from=test-gleam /.dummy /.dummy
Expand Down