forked from supabase/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-scoop.ts
More file actions
143 lines (128 loc) · 4.69 KB
/
Copy pathupdate-scoop.ts
File metadata and controls
143 lines (128 loc) · 4.69 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import { $ } from "bun";
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
import process from "node:process";
import { parseArgs } from "node:util";
const { values } = parseArgs({
options: {
version: { type: "string" },
repo: { type: "string", default: "supabase/cli" },
bucket: { type: "string", default: "supabase/scoop-bucket" },
name: { type: "string", default: "supabase" },
local: { type: "boolean", default: false },
"dry-run": { type: "boolean", default: false },
},
});
const version = values.version;
if (!version) {
console.error(
"Usage: bun run scripts/update-scoop.ts --version <version> [--repo <owner/repo>] [--bucket <owner/repo>] [--name <manifest-name>] [--local] [--dry-run]",
);
process.exit(1);
}
const repo = values.repo!;
const bucket = values.bucket!;
const name = values.name!;
const local = values.local!;
const dryRun = values["dry-run"]!;
// The shipped binary is always `supabase.exe`, regardless of channel — only
// the manifest filename differs (e.g. `supabase-beta.json`) so stable and
// beta can coexist in the same bucket. Matches the Go CLI's historical
// scoop-bucket layout (`supabase.json` and `supabase-beta.json` both shim
// `supabase.exe`).
const binEntry = "supabase.exe";
const root = path.resolve(import.meta.dir, "../../..");
const distDir = path.join(root, "dist");
// Parse checksums
const checksums = new Map<string, string>();
const checksumsText = await readFile(path.join(distDir, "checksums.txt"), "utf-8");
for (const line of checksumsText.trim().split("\n")) {
const [hash, file] = line.split(/\s+/) as [string, string];
checksums.set(file, hash);
}
function sha(file: string): string {
const hash = checksums.get(file);
if (!hash) throw new Error(`Checksum not found for ${file}`);
return hash;
}
// Scoop supports file:// URLs for local testing
const baseUrl = local
? `file:///${distDir.replace(/\\/g, "/")}`
: `https://github.com/${repo}/releases/download/v${version}`;
// Main-bucket layout uses unversioned Windows tarballs on GitHub Releases
// (release-shared.yml copies versioned builds to supabase_windows_*.tar.gz).
// Local builds only emit versioned archives, so --local keeps those names.
const amd64Tar = local
? `supabase_${version}_windows_amd64.tar.gz`
: "supabase_windows_amd64.tar.gz";
const arm64Tar = local
? `supabase_${version}_windows_arm64.tar.gz`
: "supabase_windows_arm64.tar.gz";
const manifest = {
version,
description: "Supabase CLI",
homepage: "https://supabase.com/",
license: "MIT",
architecture: {
"64bit": {
url: `${baseUrl}/${amd64Tar}`,
hash: sha(`supabase_${version}_windows_amd64.tar.gz`),
},
arm64: {
url: `${baseUrl}/${arm64Tar}`,
hash: sha(`supabase_${version}_windows_arm64.tar.gz`),
},
},
bin: binEntry,
checkver: {
github: `https://github.com/${repo}`,
},
autoupdate: {
architecture: {
"64bit": {
url: `https://github.com/${repo}/releases/download/v$version/supabase_windows_amd64.tar.gz`,
},
arm64: {
url: `https://github.com/${repo}/releases/download/v$version/supabase_windows_arm64.tar.gz`,
},
},
hash: {
url: "$baseurl/supabase_$version_checksums.txt",
},
},
};
const manifestFileName = `${name}.json`;
const manifestJson = `${JSON.stringify(manifest, null, 4)}\n`;
const manifestOut = path.join(distDir, manifestFileName);
await writeFile(manifestOut, manifestJson);
console.log(`Manifest written to ${manifestOut}`);
if (local || dryRun) {
console.log(manifestJson);
process.exit(0);
}
async function hasStagedChanges(repoDir: string, repoPath: string): Promise<boolean> {
const diff =
await $`git -C ${repoDir} diff --cached --quiet --exit-code -- ${repoPath}`.nothrow();
if (diff.exitCode === 0) return false;
if (diff.exitCode === 1) return true;
throw new Error(`Failed to inspect staged changes for ${repoPath}`);
}
// Clone bucket repo, update manifest, commit, push
const tmpDir = await mkdtemp(path.join(tmpdir(), "scoop-bucket-"));
try {
const bucketUrl = `https://github.com/${bucket}.git`;
await $`git clone ${bucketUrl} ${tmpDir}`;
const bucketManifestPath = path.join(tmpDir, manifestFileName);
await writeFile(bucketManifestPath, manifestJson);
await $`git -C ${tmpDir} add ${manifestFileName}`;
if (await hasStagedChanges(tmpDir, manifestFileName)) {
await $`git -C ${tmpDir} commit -m ${name + " " + version}`;
await $`git -C ${tmpDir} push`;
console.log(`Pushed manifest update to ${bucket}`);
} else {
console.log(`Manifest ${manifestFileName} is already up to date in ${bucket}`);
}
} finally {
await rm(tmpDir, { recursive: true });
}