@ozyman42/ozy-cli 0.4.9-linux-x64.0 → 0.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +8 -0
- package/bin/ozy +209 -0
- package/bin/ozy-signing-agent +209 -0
- package/bin/ozy-ssh-keygen +209 -0
- package/bin/ozy-virtual-security-key +209 -0
- package/dist/commands/git/hosts.js +18 -0
- package/dist/commands/git/hosts.js.map +1 -0
- package/dist/commands/git/index.js +8 -0
- package/dist/commands/git/index.js.map +1 -0
- package/dist/commands/git/setup.js +145 -0
- package/dist/commands/git/setup.js.map +1 -0
- package/dist/commands/index.js +13 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/npm/index.js +7 -0
- package/dist/commands/npm/index.js.map +1 -0
- package/dist/commands/npm/setup/git-remote.js +66 -0
- package/dist/commands/npm/setup/git-remote.js.map +1 -0
- package/dist/commands/npm/setup/index.js +168 -0
- package/dist/commands/npm/setup/index.js.map +1 -0
- package/dist/commands/npm/setup/npm-auth.js +62 -0
- package/dist/commands/npm/setup/npm-auth.js.map +1 -0
- package/dist/commands/npm/setup/package-json-validate.js +47 -0
- package/dist/commands/npm/setup/package-json-validate.js.map +1 -0
- package/dist/commands/npm/setup/package-registry.js +20 -0
- package/dist/commands/npm/setup/package-registry.js.map +1 -0
- package/dist/commands/npm/setup/setup.test.js +95 -0
- package/dist/commands/npm/setup/setup.test.js.map +1 -0
- package/dist/commands/npm/setup/trusted-publishing.js +84 -0
- package/dist/commands/npm/setup/trusted-publishing.js.map +1 -0
- package/dist/commands/npm/setup/workflow.js +19 -0
- package/dist/commands/npm/setup/workflow.js.map +1 -0
- package/dist/commands/ssh/get-sk-credential.js +104 -0
- package/dist/commands/ssh/get-sk-credential.js.map +1 -0
- package/dist/commands/ssh/index.js +7 -0
- package/dist/commands/ssh/index.js.map +1 -0
- package/dist/commands/upgrade.js +236 -0
- package/dist/commands/upgrade.js.map +1 -0
- package/dist/common/command.js +15 -0
- package/dist/common/command.js.map +1 -0
- package/dist/common/constants.js +25 -0
- package/dist/common/constants.js.map +1 -0
- package/dist/common/effective-modules-extensions.js +13 -0
- package/dist/common/effective-modules-extensions.js.map +1 -0
- package/dist/common/log.js +4 -0
- package/dist/common/log.js.map +1 -0
- package/dist/common/render-caller-tree.js +20 -0
- package/dist/common/render-caller-tree.js.map +1 -0
- package/dist/entrypoints/ozy-signing-agent.js +48 -0
- package/dist/entrypoints/ozy-signing-agent.js.map +1 -0
- package/dist/entrypoints/ozy-ssh-keygen.js +9 -0
- package/dist/entrypoints/ozy-ssh-keygen.js.map +1 -0
- package/dist/entrypoints/ozy-virtual-security-key.js +18 -0
- package/dist/entrypoints/ozy-virtual-security-key.js.map +1 -0
- package/dist/entrypoints/ozy.js +3 -0
- package/dist/entrypoints/ozy.js.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/thing.js +4 -0
- package/dist/internal/thing.js.map +1 -0
- package/dist/modules/cli/agent-client/impl.js +109 -0
- package/dist/modules/cli/agent-client/impl.js.map +1 -0
- package/dist/modules/cli/agent-client/interface.js +11 -0
- package/dist/modules/cli/agent-client/interface.js.map +1 -0
- package/dist/modules/cli/git/impl.js +124 -0
- package/dist/modules/cli/git/impl.js.map +1 -0
- package/dist/modules/cli/git/interface.js +3 -0
- package/dist/modules/cli/git/interface.js.map +1 -0
- package/dist/modules/cli/git/submodule/fix.js +257 -0
- package/dist/modules/cli/git/submodule/fix.js.map +1 -0
- package/dist/modules/cli/git/submodule/git-state.js +154 -0
- package/dist/modules/cli/git/submodule/git-state.js.map +1 -0
- package/dist/modules/cli/git/submodule/gitmodules.js +113 -0
- package/dist/modules/cli/git/submodule/gitmodules.js.map +1 -0
- package/dist/modules/cli/git/submodule/printer.js +232 -0
- package/dist/modules/cli/git/submodule/printer.js.map +1 -0
- package/dist/modules/cli/git/submodule/resolve-git-dir.js +16 -0
- package/dist/modules/cli/git/submodule/resolve-git-dir.js.map +1 -0
- package/dist/modules/cli/github/impl.js +137 -0
- package/dist/modules/cli/github/impl.js.map +1 -0
- package/dist/modules/cli/github/interface.js +2 -0
- package/dist/modules/cli/github/interface.js.map +1 -0
- package/dist/modules/cli/index.js +9 -0
- package/dist/modules/cli/index.js.map +1 -0
- package/dist/modules/common/crypto/impl.js +133 -0
- package/dist/modules/common/crypto/impl.js.map +1 -0
- package/dist/modules/common/crypto/interface.js +2 -0
- package/dist/modules/common/crypto/interface.js.map +1 -0
- package/dist/modules/common/index.js +10 -0
- package/dist/modules/common/index.js.map +1 -0
- package/dist/modules/common/kep-map-store/impl.js +42 -0
- package/dist/modules/common/kep-map-store/impl.js.map +1 -0
- package/dist/modules/common/kep-map-store/interface.js +2 -0
- package/dist/modules/common/kep-map-store/interface.js.map +1 -0
- package/dist/modules/common/os-platform/caller-info.js +132 -0
- package/dist/modules/common/os-platform/caller-info.js.map +1 -0
- package/dist/modules/common/os-platform/impl.js +95 -0
- package/dist/modules/common/os-platform/impl.js.map +1 -0
- package/dist/modules/common/os-platform/interface.js +2 -0
- package/dist/modules/common/os-platform/interface.js.map +1 -0
- package/dist/modules/common/os-platform/virtual-hid/index.js +12 -0
- package/dist/modules/common/os-platform/virtual-hid/index.js.map +1 -0
- package/dist/modules/common/os-platform/virtual-hid/linux.js +5 -0
- package/dist/modules/common/os-platform/virtual-hid/linux.js.map +1 -0
- package/dist/modules/common/os-platform/virtual-hid/mac.js +119 -0
- package/dist/modules/common/os-platform/virtual-hid/mac.js.map +1 -0
- package/dist/modules/common/os-platform/virtual-hid/windows.js +5 -0
- package/dist/modules/common/os-platform/virtual-hid/windows.js.map +1 -0
- package/dist/modules/common/ssh-config/impl.js +116 -0
- package/dist/modules/common/ssh-config/impl.js.map +1 -0
- package/dist/modules/common/ssh-config/interface.js +10 -0
- package/dist/modules/common/ssh-config/interface.js.map +1 -0
- package/dist/modules/ssh-agent/index.js +8 -0
- package/dist/modules/ssh-agent/index.js.map +1 -0
- package/dist/modules/ssh-agent/session/impl.js +265 -0
- package/dist/modules/ssh-agent/session/impl.js.map +1 -0
- package/dist/modules/ssh-agent/session/interface-rpc.js +20 -0
- package/dist/modules/ssh-agent/session/interface-rpc.js.map +1 -0
- package/dist/modules/ssh-agent/session/interface.js +32 -0
- package/dist/modules/ssh-agent/session/interface.js.map +1 -0
- package/dist/modules/ssh-agent/session/passkey-prf-page.js +204 -0
- package/dist/modules/ssh-agent/session/passkey-prf-page.js.map +1 -0
- package/dist/modules/ssh-agent/session/prf-flow.js +103 -0
- package/dist/modules/ssh-agent/session/prf-flow.js.map +1 -0
- package/dist/modules/ssh-agent/ssh-agent/impl.js +117 -0
- package/dist/modules/ssh-agent/ssh-agent/impl.js.map +1 -0
- package/dist/modules/ssh-agent/ssh-agent/interface.js +2 -0
- package/dist/modules/ssh-agent/ssh-agent/interface.js.map +1 -0
- package/dist/scripts/build.js +444 -0
- package/dist/scripts/build.js.map +1 -0
- package/dist/scripts/check-npm-version.js +8 -0
- package/dist/scripts/check-npm-version.js.map +1 -0
- package/dist/scripts/constants.js +12 -0
- package/dist/scripts/constants.js.map +1 -0
- package/dist/scripts/kill-existing-agent.js +21 -0
- package/dist/scripts/kill-existing-agent.js.map +1 -0
- package/dist/scripts/publish.js +83 -0
- package/dist/scripts/publish.js.map +1 -0
- package/install.js +209 -0
- package/package.json +58 -11
- package/src/commands/git/hosts.ts +20 -0
- package/src/commands/git/index.ts +9 -0
- package/src/commands/git/setup.ts +182 -0
- package/src/commands/index.ts +15 -0
- package/src/commands/npm/index.ts +8 -0
- package/src/commands/npm/setup/git-remote.ts +78 -0
- package/src/commands/npm/setup/index.ts +189 -0
- package/src/commands/npm/setup/npm-auth.ts +58 -0
- package/src/commands/npm/setup/package-json-validate.ts +68 -0
- package/src/commands/npm/setup/package-registry.ts +24 -0
- package/src/commands/npm/setup/publish-workflow.yml +35 -0
- package/src/commands/npm/setup/setup.test.ts +117 -0
- package/src/commands/npm/setup/trusted-publishing.ts +106 -0
- package/src/commands/npm/setup/workflow.ts +20 -0
- package/src/commands/ssh/get-sk-credential.ts +110 -0
- package/src/commands/ssh/index.ts +8 -0
- package/src/commands/upgrade.ts +261 -0
- package/src/common/command.ts +16 -0
- package/src/common/constants.ts +26 -0
- package/src/common/effective-modules-extensions.ts +24 -0
- package/src/common/log.ts +3 -0
- package/src/common/render-caller-tree.ts +22 -0
- package/src/entrypoints/ozy-signing-agent.ts +48 -0
- package/src/entrypoints/ozy-ssh-keygen.ts +10 -0
- package/src/entrypoints/ozy-virtual-security-key.ts +21 -0
- package/src/entrypoints/ozy.ts +2 -0
- package/src/index.ts +1 -0
- package/src/internal/thing.ts +3 -0
- package/src/modules/cli/agent-client/impl.ts +152 -0
- package/src/modules/cli/agent-client/interface.ts +17 -0
- package/src/modules/cli/git/impl.ts +133 -0
- package/src/modules/cli/git/interface.ts +23 -0
- package/src/modules/cli/git/submodule/fix.ts +298 -0
- package/src/modules/cli/git/submodule/git-state.ts +217 -0
- package/src/modules/cli/git/submodule/gitmodules.ts +126 -0
- package/src/modules/cli/git/submodule/printer.ts +256 -0
- package/src/modules/cli/git/submodule/resolve-git-dir.ts +14 -0
- package/src/modules/cli/github/impl.ts +169 -0
- package/src/modules/cli/github/interface.ts +29 -0
- package/src/modules/cli/index.ts +16 -0
- package/src/modules/common/crypto/impl.ts +173 -0
- package/src/modules/common/crypto/interface.ts +20 -0
- package/src/modules/common/index.ts +19 -0
- package/src/modules/common/kep-map-store/impl.ts +47 -0
- package/src/modules/common/kep-map-store/interface.ts +9 -0
- package/src/modules/common/os-platform/caller-info.ts +152 -0
- package/src/modules/common/os-platform/impl.ts +91 -0
- package/src/modules/common/os-platform/interface.ts +16 -0
- package/src/modules/common/os-platform/virtual-hid/index.ts +12 -0
- package/src/modules/common/os-platform/virtual-hid/linux.ts +7 -0
- package/src/modules/common/os-platform/virtual-hid/mac.ts +150 -0
- package/src/modules/common/os-platform/virtual-hid/windows.ts +7 -0
- package/src/modules/common/ssh-config/impl.ts +130 -0
- package/src/modules/common/ssh-config/interface.ts +33 -0
- package/src/modules/ssh-agent/index.ts +13 -0
- package/src/modules/ssh-agent/session/agent-notes.md +210 -0
- package/src/modules/ssh-agent/session/design.md +2 -0
- package/src/modules/ssh-agent/session/html-refactor.md +23 -0
- package/src/modules/ssh-agent/session/impl.ts +328 -0
- package/src/modules/ssh-agent/session/interface-rpc.ts +24 -0
- package/src/modules/ssh-agent/session/interface.ts +62 -0
- package/src/modules/ssh-agent/session/passkey-prf-page.ts +224 -0
- package/src/modules/ssh-agent/session/prf-flow.ts +152 -0
- package/src/modules/ssh-agent/ssh-agent/impl.ts +136 -0
- package/src/modules/ssh-agent/ssh-agent/interface.ts +9 -0
- package/src/scripts/build.ts +559 -0
- package/src/scripts/check-npm-version.ts +7 -0
- package/src/scripts/command-launcher.js.ejs +186 -0
- package/src/scripts/constants.ts +11 -0
- package/src/scripts/kill-existing-agent.ts +22 -0
- package/src/scripts/publish.ts +89 -0
- package/src/scripts/windows-bin-shims.md +1104 -0
- package/multi-call-binary +0 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import {
|
|
5
|
+
chmodSync,
|
|
6
|
+
copyFileSync,
|
|
7
|
+
existsSync,
|
|
8
|
+
linkSync,
|
|
9
|
+
mkdirSync,
|
|
10
|
+
readFileSync,
|
|
11
|
+
renameSync,
|
|
12
|
+
rmSync,
|
|
13
|
+
writeFileSync,
|
|
14
|
+
} from "node:fs";
|
|
15
|
+
import { basename, dirname, join } from "node:path";
|
|
16
|
+
import { fileURLToPath } from "node:url";
|
|
17
|
+
|
|
18
|
+
const PLATFORM_MAP = <%- json(platformMap) %>;
|
|
19
|
+
const PLATFORM_PACKAGES = <%- json(platformPackages) %>;
|
|
20
|
+
const PLATFORM_BINARIES = <%- json(platformBinaries) %>;
|
|
21
|
+
const COMMANDS = <%- json(commandNames) %>;
|
|
22
|
+
const BIN_DIR = <%- json(binDir) %>;
|
|
23
|
+
const INSTALL_SCRIPT = <%- json(installScript) %>;
|
|
24
|
+
// Root install.js repairs command targets; bin launchers repair and then execute.
|
|
25
|
+
const IS_INSTALL_SCRIPT = <%- json(isInstallScript) %>;
|
|
26
|
+
const WINDOWS_EXECUTABLE_SUFFIX = <%- json(windowsExecutableSuffix) %>;
|
|
27
|
+
const INSTALLED_JSON = "installed.json";
|
|
28
|
+
|
|
29
|
+
const require = createRequire(import.meta.url);
|
|
30
|
+
const launcherPath = fileURLToPath(import.meta.url);
|
|
31
|
+
const launcherDir = dirname(launcherPath);
|
|
32
|
+
const packageDir = IS_INSTALL_SCRIPT ? launcherDir : dirname(launcherDir);
|
|
33
|
+
const commandTargetDir = join(packageDir, BIN_DIR);
|
|
34
|
+
const rootInstallScriptPath = join(packageDir, INSTALL_SCRIPT);
|
|
35
|
+
|
|
36
|
+
function fail(message) {
|
|
37
|
+
console.error(message);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function currentPlatformKey() {
|
|
42
|
+
const platformKey = PLATFORM_MAP[`${process.platform}-${process.arch}`];
|
|
43
|
+
if (!platformKey) {
|
|
44
|
+
fail(`Unsupported platform: ${process.platform}-${process.arch}`);
|
|
45
|
+
}
|
|
46
|
+
return platformKey;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function currentPlatformPackageName() {
|
|
50
|
+
const platformKey = currentPlatformKey();
|
|
51
|
+
const packageName = PLATFORM_PACKAGES[platformKey];
|
|
52
|
+
if (!packageName) {
|
|
53
|
+
fail(`No platform package is configured for ${platformKey}`);
|
|
54
|
+
}
|
|
55
|
+
return packageName;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* When a Jive library contains any number of CLIs (entrypoints or agents), then the base package
|
|
60
|
+
* will have an optional dependency for each possible architecture, with those platform-specific
|
|
61
|
+
* packages containing a platform build of the CLI.
|
|
62
|
+
* @returns the path to the platform binary and the exact version of the platform package.
|
|
63
|
+
*/
|
|
64
|
+
function currentPlatformPackage() {
|
|
65
|
+
const platformKey = currentPlatformKey();
|
|
66
|
+
const binaryFile = PLATFORM_BINARIES[platformKey];
|
|
67
|
+
if (!binaryFile) {
|
|
68
|
+
fail(`No platform binary is configured for ${platformKey}`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const packageName = currentPlatformPackageName();
|
|
72
|
+
try {
|
|
73
|
+
const packageJsonPath = require.resolve(`${packageName}/package.json`);
|
|
74
|
+
const packageDir = dirname(packageJsonPath);
|
|
75
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
76
|
+
return {
|
|
77
|
+
binaryPath: join(packageDir, binaryFile),
|
|
78
|
+
version: packageJson.version,
|
|
79
|
+
};
|
|
80
|
+
} catch (error) {
|
|
81
|
+
fail(`Could not resolve optional platform package ${packageName}. Reinstall dependencies for ${process.platform}-${process.arch}.`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function commandTargetPath(command) {
|
|
86
|
+
const suffix = process.platform === "win32" ? WINDOWS_EXECUTABLE_SUFFIX : "";
|
|
87
|
+
return join(commandTargetDir, `${command}${suffix}`);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function installedJsonPath() {
|
|
91
|
+
return join(commandTargetDir, INSTALLED_JSON);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function windowsTargetsAreCurrent(version) {
|
|
95
|
+
if (process.platform !== "win32") return false;
|
|
96
|
+
if (!COMMANDS.every((command) => existsSync(commandTargetPath(command)))) return false;
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
const installed = JSON.parse(readFileSync(installedJsonPath(), "utf-8"));
|
|
100
|
+
return installed.version === version;
|
|
101
|
+
} catch {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function linkOrCopyFirstExecutable(sourcePath, targetPath) {
|
|
107
|
+
mkdirSync(dirname(targetPath), { recursive: true });
|
|
108
|
+
const tempPath = `${targetPath}.${process.pid}.${Date.now()}.tmp${process.platform === "win32" ? WINDOWS_EXECUTABLE_SUFFIX : ""}`;
|
|
109
|
+
rmSync(tempPath, { force: true });
|
|
110
|
+
|
|
111
|
+
try {
|
|
112
|
+
try {
|
|
113
|
+
linkSync(sourcePath, tempPath);
|
|
114
|
+
} catch {
|
|
115
|
+
copyFileSync(sourcePath, tempPath);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
chmodSync(tempPath, 0o755);
|
|
119
|
+
rmSync(targetPath, { force: true });
|
|
120
|
+
renameSync(tempPath, targetPath);
|
|
121
|
+
} finally {
|
|
122
|
+
rmSync(tempPath, { force: true });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function hardLinkCommandTarget(sourcePath, targetPath) {
|
|
127
|
+
if (sourcePath === targetPath) return;
|
|
128
|
+
|
|
129
|
+
const tempPath = `${targetPath}.${process.pid}.${Date.now()}.tmp${process.platform === "win32" ? WINDOWS_EXECUTABLE_SUFFIX : ""}`;
|
|
130
|
+
rmSync(tempPath, { force: true });
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
linkSync(sourcePath, tempPath);
|
|
134
|
+
chmodSync(tempPath, 0o755);
|
|
135
|
+
rmSync(targetPath, { force: true });
|
|
136
|
+
renameSync(tempPath, targetPath);
|
|
137
|
+
} finally {
|
|
138
|
+
rmSync(tempPath, { force: true });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function repairCommandTargets() {
|
|
143
|
+
const platformPackage = currentPlatformPackage();
|
|
144
|
+
|
|
145
|
+
if (windowsTargetsAreCurrent(platformPackage.version)) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const firstTargetPath = commandTargetPath(COMMANDS[0]);
|
|
150
|
+
linkOrCopyFirstExecutable(platformPackage.binaryPath, firstTargetPath);
|
|
151
|
+
|
|
152
|
+
for (const command of COMMANDS.slice(1)) {
|
|
153
|
+
hardLinkCommandTarget(firstTargetPath, commandTargetPath(command));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (process.platform === "win32") {
|
|
157
|
+
writeFileSync(installedJsonPath(), `${JSON.stringify({ version: platformPackage.version }, null, 2)}\n`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function runExecutable(executablePath) {
|
|
162
|
+
const result = spawnSync(executablePath, process.argv.slice(2), { stdio: "inherit" });
|
|
163
|
+
|
|
164
|
+
if (result.error) {
|
|
165
|
+
fail(result.error.message);
|
|
166
|
+
}
|
|
167
|
+
if (result.status !== 0) {
|
|
168
|
+
process.exit(result.status ?? 1);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function removeInstallScript() {
|
|
173
|
+
try {
|
|
174
|
+
rmSync(rootInstallScriptPath, { force: true });
|
|
175
|
+
// TODO: should we also remove the postinstall script line from package.json?
|
|
176
|
+
} catch {
|
|
177
|
+
// Cleanup is best-effort; failing to remove install.js should not fail package installation.
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
repairCommandTargets();
|
|
182
|
+
removeInstallScript();
|
|
183
|
+
if (!IS_INSTALL_SCRIPT) {
|
|
184
|
+
const commandName = basename(launcherPath);
|
|
185
|
+
runExecutable(commandTargetPath(commandName));
|
|
186
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const BIN_DIR = "bin";
|
|
2
|
+
export const INSTALL_SCRIPT = "install.js";
|
|
3
|
+
export const LICENSE_FILE = "LICENSE";
|
|
4
|
+
export const MULTI_CALL_BINARY = "multi-call-binary";
|
|
5
|
+
export const NPM_PACKAGE_SPEC = "npm@^11.5.1";
|
|
6
|
+
export const OUTDIR = "dist";
|
|
7
|
+
export const PUBLISH_ORDER_FILE = "publish-order.json";
|
|
8
|
+
export const README_FILE = "README.md";
|
|
9
|
+
export const TARBALL_EXTENSION = ".tgz";
|
|
10
|
+
export const WINDOWS_EXECUTABLE_SUFFIX = ".exe";
|
|
11
|
+
export const WORKDIR = "build-temp";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
|
|
4
|
+
const pidFile = path.resolve(import.meta.dir, "../../dist/ozy-signing-agent.pid");
|
|
5
|
+
|
|
6
|
+
function isProcessRunning(pid: number): boolean {
|
|
7
|
+
try {
|
|
8
|
+
// signal 0 sends nothing; it only checks whether the PID exists
|
|
9
|
+
process.kill(pid, 0);
|
|
10
|
+
return true;
|
|
11
|
+
} catch {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (existsSync(pidFile)) {
|
|
17
|
+
const pid = parseInt(readFileSync(pidFile, "utf-8"));
|
|
18
|
+
if (isProcessRunning(pid)) {
|
|
19
|
+
console.log(`Killing agent on PID ${pid}`);
|
|
20
|
+
process.kill(pid, "SIGTERM");
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import * as path from "path";
|
|
2
|
+
import * as fs from "fs/promises";
|
|
3
|
+
import { NPM_PACKAGE_SPEC, OUTDIR, PUBLISH_ORDER_FILE, TARBALL_EXTENSION } from "./constants";
|
|
4
|
+
|
|
5
|
+
// only publish on workflow dispatch on push to default branch (config can change this later)
|
|
6
|
+
const event = process.argv[2];
|
|
7
|
+
if (event !== "push") {
|
|
8
|
+
console.log("Skipping publish. Only publishing to NPM on push events. Current event is", event);
|
|
9
|
+
process.exit(0);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const buildFolderName = OUTDIR;
|
|
13
|
+
const expectedFileType = TARBALL_EXTENSION;
|
|
14
|
+
const publishOrderFileName = PUBLISH_ORDER_FILE;
|
|
15
|
+
const distFolder = path.resolve(__dirname, `../../${buildFolderName}`);
|
|
16
|
+
const children = await fs.readdir(distFolder);
|
|
17
|
+
const badChildren = new Set<string>();
|
|
18
|
+
for (const child of children) {
|
|
19
|
+
if (!child.endsWith(expectedFileType) && child !== publishOrderFileName) {
|
|
20
|
+
badChildren.add(child);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (badChildren.size > 0) {
|
|
24
|
+
console.log(`Only expected ${expectedFileType} files or ${publishOrderFileName} in ${buildFolderName} folder. Instead got following:`);
|
|
25
|
+
for (const child of children) {
|
|
26
|
+
const isBad = badChildren.has(child);
|
|
27
|
+
const prefix = isBad ? "::error::" : "";
|
|
28
|
+
console.log(`${prefix}- ${child}`);
|
|
29
|
+
}
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
const tarballs = await orderedTarballs(children);
|
|
33
|
+
for (const child of tarballs) {
|
|
34
|
+
const fullPath = path.resolve(distFolder, child).toLocaleLowerCase();
|
|
35
|
+
const tarball = `./${buildFolderName}/${child}`;
|
|
36
|
+
const tag = path.basename(fullPath, expectedFileType);
|
|
37
|
+
const command = ["bunx", NPM_PACKAGE_SPEC, "publish", tarball, "--tag", tag, "--loglevel", "silly"];
|
|
38
|
+
console.log(command.join(" "));
|
|
39
|
+
const exitCode = await Bun.spawn(command, {
|
|
40
|
+
stdin: "inherit",
|
|
41
|
+
stdout: "inherit",
|
|
42
|
+
stderr: "inherit",
|
|
43
|
+
env: process.env
|
|
44
|
+
}).exited;
|
|
45
|
+
if (exitCode !== 0) {
|
|
46
|
+
process.exit(exitCode);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function orderedTarballs(children: string[]): Promise<string[]> {
|
|
51
|
+
const tarballs = children.filter((child) => child.endsWith(expectedFileType));
|
|
52
|
+
if (!children.includes(publishOrderFileName)) {
|
|
53
|
+
return tarballs;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const orderPath = path.resolve(distFolder, publishOrderFileName);
|
|
57
|
+
const parsed = JSON.parse(await fs.readFile(orderPath, "utf-8"));
|
|
58
|
+
if (!Array.isArray(parsed) || !parsed.every((value) => typeof value === "string")) {
|
|
59
|
+
console.error(`${publishOrderFileName} must be a JSON array of tarball file names`);
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const ordered = parsed as string[];
|
|
64
|
+
const expected = new Set(tarballs);
|
|
65
|
+
const seen = new Set<string>();
|
|
66
|
+
for (const child of ordered) {
|
|
67
|
+
if (!child.endsWith(expectedFileType)) {
|
|
68
|
+
console.error(`${publishOrderFileName} includes a non-${expectedFileType} entry: ${child}`);
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
if (!expected.has(child)) {
|
|
72
|
+
console.error(`${publishOrderFileName} includes ${child}, but it is not present in ${buildFolderName}`);
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
if (seen.has(child)) {
|
|
76
|
+
console.error(`${publishOrderFileName} includes ${child} more than once`);
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
seen.add(child);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const missing = tarballs.filter((child) => !seen.has(child));
|
|
83
|
+
if (missing.length > 0) {
|
|
84
|
+
console.error(`${publishOrderFileName} is missing tarballs: ${missing.join(", ")}`);
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return ordered;
|
|
89
|
+
}
|