greprag 5.85.6 → 5.85.7
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/dist/commands/deploy-verify.js +2 -0
- package/dist/deploy-verify.js +44 -17
- package/package.json +1 -1
|
@@ -22,6 +22,8 @@ Exit 0 when production is proven to serve the commit, 1 otherwise.
|
|
|
22
22
|
|
|
23
23
|
For a target with no HTTP stamp — a Discord bot, a worker process — use --heroku:
|
|
24
24
|
it reads the app's release list and confirms the running release names your commit.
|
|
25
|
+
The Heroku CLI is asked once for a login token (heroku auth:token); each check is then
|
|
26
|
+
one request to the Heroku API.
|
|
25
27
|
It refuses while the current release is pending or failed, which is the case most
|
|
26
28
|
worth catching, because the git push succeeded and looks fine. A config-var change
|
|
27
29
|
creates a release naming no commit, and the code running is still the last real
|
package/dist/deploy-verify.js
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
*/
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
23
|
exports.BUILD_STAMP_PATH = void 0;
|
|
24
|
+
exports.fetchHerokuToken = fetchHerokuToken;
|
|
24
25
|
exports.fetchHerokuReleases = fetchHerokuReleases;
|
|
25
26
|
exports.verifyHerokuRelease = verifyHerokuRelease;
|
|
26
27
|
exports.sameCommit = sameCommit;
|
|
@@ -32,36 +33,62 @@ exports.describeHerokuRelease = describeHerokuRelease;
|
|
|
32
33
|
exports.assertBuildStampUncacheable = assertBuildStampUncacheable;
|
|
33
34
|
const proc_1 = require("./proc");
|
|
34
35
|
exports.BUILD_STAMP_PATH = '/__build.json';
|
|
35
|
-
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
/** The Heroku CLI's login token, asked for ONCE per verify. The CLI is only a token
|
|
37
|
+
* source here: on Windows it takes 9-35s just to start, so polling releases through it
|
|
38
|
+
* under a 30s kill turned ordinary slowness into "not logged in" on every check, and
|
|
39
|
+
* two good PayBot deploys on 2026-10-23 were reported as failed. `~/_netrc` is no
|
|
40
|
+
* substitute — CLI 11 keeps the live login elsewhere and the netrc token there was
|
|
41
|
+
* stale. Honours HEROKU_API_KEY, because the CLI itself does. */
|
|
42
|
+
function fetchHerokuToken() {
|
|
41
43
|
// One command string through a shell: `heroku` is a `.cmd` shim on Windows, which
|
|
42
|
-
// Node refuses to spawn directly.
|
|
43
|
-
const result = (0, proc_1.safeSpawnSync)(
|
|
44
|
+
// Node refuses to spawn directly.
|
|
45
|
+
const result = (0, proc_1.safeSpawnSync)('heroku auth:token', [], {
|
|
44
46
|
encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'],
|
|
45
|
-
shell: true, windowsHide: true, timeout:
|
|
47
|
+
shell: true, windowsHide: true, timeout: 120_000,
|
|
46
48
|
});
|
|
47
49
|
if (result.status !== 0)
|
|
48
50
|
return null;
|
|
51
|
+
return String(result.stdout).trim() || null;
|
|
52
|
+
}
|
|
53
|
+
/** Read an app's releases from the Heroku Platform API, newest first. Returns why it
|
|
54
|
+
* could not when it cannot — the caller reports that as a failure to verify, never as
|
|
55
|
+
* a pass. */
|
|
56
|
+
async function fetchHerokuReleases(app, token, num = 10, fetchImpl = fetch) {
|
|
57
|
+
if (!/^[a-z0-9][a-z0-9-]*$/.test(app))
|
|
58
|
+
return `${app} is not a Heroku app name`;
|
|
49
59
|
try {
|
|
50
|
-
const
|
|
51
|
-
|
|
60
|
+
const response = await fetchImpl(`https://api.heroku.com/apps/${app}/releases`, {
|
|
61
|
+
headers: {
|
|
62
|
+
Accept: 'application/vnd.heroku+json; version=3',
|
|
63
|
+
Authorization: `Bearer ${token}`,
|
|
64
|
+
Range: `version ..; order=desc, max=${num}`,
|
|
65
|
+
},
|
|
66
|
+
signal: AbortSignal.timeout(20_000),
|
|
67
|
+
});
|
|
68
|
+
if (!response.ok)
|
|
69
|
+
return `Heroku answered ${response.status}`;
|
|
70
|
+
const parsed = await response.json();
|
|
71
|
+
return Array.isArray(parsed) ? parsed : 'Heroku did not return a release list';
|
|
52
72
|
}
|
|
53
|
-
catch {
|
|
54
|
-
return
|
|
73
|
+
catch (error) {
|
|
74
|
+
return `could not reach Heroku: ${error instanceof Error ? error.message : String(error)}`;
|
|
55
75
|
}
|
|
56
76
|
}
|
|
57
77
|
/** Poll Heroku until the app is running `sha`. A push returns as soon as the slug is
|
|
58
78
|
* received; the build and release follow, so the first look is usually too early. */
|
|
59
|
-
async function verifyHerokuRelease({ app, sha, attempts = 12, intervalMs = 5000, fetchReleases = fetchHerokuReleases, sleep = (ms) => new Promise(resolve => { setTimeout(resolve, ms); }), }) {
|
|
79
|
+
async function verifyHerokuRelease({ app, sha, attempts = 12, intervalMs = 5000, fetchToken = fetchHerokuToken, fetchReleases = fetchHerokuReleases, sleep = (ms) => new Promise(resolve => { setTimeout(resolve, ms); }), }) {
|
|
80
|
+
const token = fetchToken();
|
|
81
|
+
if (!token) {
|
|
82
|
+
return {
|
|
83
|
+
ok: false, attempts: 0,
|
|
84
|
+
reason: 'could not get a Heroku login token (heroku auth:token) — is the Heroku CLI installed and logged in?',
|
|
85
|
+
};
|
|
86
|
+
}
|
|
60
87
|
let last = 'Heroku was never reached';
|
|
61
88
|
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
|
62
|
-
const releases = fetchReleases(app);
|
|
63
|
-
if (releases ===
|
|
64
|
-
last = `could not read Heroku releases for ${app}
|
|
89
|
+
const releases = await fetchReleases(app, token);
|
|
90
|
+
if (typeof releases === 'string') {
|
|
91
|
+
last = `could not read Heroku releases for ${app}: ${releases}`;
|
|
65
92
|
}
|
|
66
93
|
else {
|
|
67
94
|
const drift = describeHerokuRelease(releases, sha);
|