Skip to content

Commit 6c0cd11

Browse files
committed
add latest gh official cli
1 parent 1c3048e commit 6c0cd11

5 files changed

Lines changed: 50 additions & 5 deletions

File tree

install.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,14 @@ ensure_os() {
5656
ensure_bootstrap_deps() {
5757
export DEBIAN_FRONTEND=noninteractive
5858
apt-get -o DPkg::Lock::Timeout=900 update -y
59-
apt-get -o DPkg::Lock::Timeout=900 install -y ca-certificates curl gh unzip python3
59+
apt-get -o DPkg::Lock::Timeout=900 install -y ca-certificates curl
60+
install -d -m 0755 /etc/apt/keyrings
61+
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg -o /etc/apt/keyrings/githubcli-archive-keyring.gpg
62+
chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg
63+
printf 'deb [arch=%s signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main\n' "$(dpkg --print-architecture)" > /etc/apt/sources.list.d/github-cli.list
64+
apt-get -o DPkg::Lock::Timeout=900 update -y
65+
apt-get -o DPkg::Lock::Timeout=900 install -y gh unzip python3
66+
gh attestation verify --help >/dev/null || die "GitHub CLI does not support attestation verification after installing from the official apt repository"
6067
}
6168

6269
ensure_git() {

scripts/ctl/update.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
import { createHash } from "node:crypto";
2-
import { chmodSync, copyFileSync, cpSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readlinkSync, renameSync, rmSync, symlinkSync } from "node:fs";
2+
import {
3+
chmodSync,
4+
copyFileSync,
5+
cpSync,
6+
existsSync,
7+
lstatSync,
8+
mkdirSync,
9+
mkdtempSync,
10+
readFileSync,
11+
readlinkSync,
12+
renameSync,
13+
rmSync,
14+
symlinkSync,
15+
writeFileSync
16+
} from "node:fs";
317
import { tmpdir } from "node:os";
418
import { join, resolve } from "node:path";
519
import { runText } from "../lib/common";
@@ -14,6 +28,9 @@ const ANSIBLE_GALAXY_ATTEMPTS = 4;
1428
const INSTALLED_CLI = "/usr/local/bin/terrariumctl";
1529
const TRM_ALIAS = "/usr/local/bin/trm";
1630
const RELEASE_SIGNER_WORKFLOW = `${GITHUB_REPO}/.github/workflows/release.yml`;
31+
const GITHUB_CLI_APT_KEYRING = "/etc/apt/keyrings/githubcli-archive-keyring.gpg";
32+
const GITHUB_CLI_APT_SOURCE = "/etc/apt/sources.list.d/github-cli.list";
33+
const GITHUB_CLI_APT_REPO = "https://cli.github.com/packages";
1734

1835
export type UpdateOptions = {
1936
ref?: string;
@@ -198,7 +215,15 @@ async function installAnsibleCollections(): Promise<void> {
198215

199216
async function ensureUpdateDependencies(): Promise<void> {
200217
await runText(["apt-get", "-o", "DPkg::Lock::Timeout=900", "update", "-y"], PREFIX);
201-
await runText(["apt-get", "-o", "DPkg::Lock::Timeout=900", "install", "-y", "ca-certificates", "curl", "git", "gh", "ansible", "python3", "jq", "unzip"], PREFIX);
218+
await runText(["apt-get", "-o", "DPkg::Lock::Timeout=900", "install", "-y", "ca-certificates", "curl"], PREFIX);
219+
await runText(["install", "-d", "-m", "0755", "/etc/apt/keyrings"], PREFIX);
220+
await runText(["curl", "-fsSL", `${GITHUB_CLI_APT_REPO}/githubcli-archive-keyring.gpg`, "-o", GITHUB_CLI_APT_KEYRING], PREFIX);
221+
chmodSync(GITHUB_CLI_APT_KEYRING, 0o644);
222+
const arch = (await runText(["dpkg", "--print-architecture"], PREFIX)).trim();
223+
writeFileSync(GITHUB_CLI_APT_SOURCE, `deb [arch=${arch} signed-by=${GITHUB_CLI_APT_KEYRING}] ${GITHUB_CLI_APT_REPO} stable main\n`);
224+
await runText(["apt-get", "-o", "DPkg::Lock::Timeout=900", "update", "-y"], PREFIX);
225+
await runText(["apt-get", "-o", "DPkg::Lock::Timeout=900", "install", "-y", "git", "gh", "ansible", "python3", "jq", "unzip"], PREFIX);
226+
await runText(["gh", "attestation", "verify", "--help"], PREFIX);
202227
}
203228

204229
function trmAliasIsManaged(): boolean {

tests/install-bootstrap.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ describe("install.sh bootstrap", () => {
4646
const source = readFileSync(join(repoRoot, "install.sh"), "utf8");
4747

4848
expect(source).toContain("DPkg::Lock::Timeout=900");
49-
expect(source).toContain("apt-get -o DPkg::Lock::Timeout=900 install -y ca-certificates curl gh unzip python3");
49+
expect(source).toContain("apt-get -o DPkg::Lock::Timeout=900 install -y ca-certificates curl");
50+
expect(source).toContain("https://cli.github.com/packages/githubcli-archive-keyring.gpg");
51+
expect(source).toContain("/etc/apt/sources.list.d/github-cli.list");
52+
expect(source).toContain("https://cli.github.com/packages stable main");
53+
expect(source).toContain("apt-get -o DPkg::Lock::Timeout=900 install -y gh unzip python3");
54+
expect(source).toContain("gh attestation verify --help >/dev/null || die");
5055
expect(source).toContain("apt-get -o DPkg::Lock::Timeout=900 install -y git");
5156
});
5257

tests/release-workflow.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ describe("release workflow", () => {
132132
const installer = readFileSync(join(repoRoot, "install.sh"), "utf8");
133133

134134
expect(installer).toContain("ensure_git()");
135-
expect(installer).toContain("apt-get -o DPkg::Lock::Timeout=900 install -y ca-certificates curl gh unzip python3");
135+
expect(installer).toContain("apt-get -o DPkg::Lock::Timeout=900 install -y ca-certificates curl");
136+
expect(installer).toContain("https://cli.github.com/packages/githubcli-archive-keyring.gpg");
137+
expect(installer).toContain("https://cli.github.com/packages stable main");
138+
expect(installer).toContain("apt-get -o DPkg::Lock::Timeout=900 install -y gh unzip python3");
136139
expect(installer).toContain("apt-get -o DPkg::Lock::Timeout=900 install -y git");
137140
expect(installer).not.toContain("apt-get install -y ca-certificates curl unzip git python3");
138141
expect(installer).toContain('ensure_git\n git clone --depth 1 --branch "${source_ref}"');

tests/terrarium-update.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ describe("terrarium update command", () => {
1616
expect(ctl).toContain('option("--non-interactive"');
1717
expect(update).toContain("TERRARIUM_BUNDLE_DIR");
1818
expect(update).toContain("syncTree(BUNDLE_DIR, REPO_DIR)");
19+
expect(update).toContain("GITHUB_CLI_APT_KEYRING");
20+
expect(update).toContain("https://cli.github.com/packages");
21+
expect(update).toContain("githubcli-archive-keyring.gpg");
22+
expect(update).toContain('"dpkg", "--print-architecture"');
1923
expect(update).toContain('"git", "gh", "ansible", "python3", "jq", "unzip"');
24+
expect(update).toContain('"gh", "attestation", "verify", "--help"');
2025
expect(update).toContain("SHA256SUMS");
2126
expect(update).toContain("verifyReleaseChecksum");
2227
expect(update).toContain("gh");

0 commit comments

Comments
 (0)