@deployfoundation/foundation-deploy 0.2.41 → 0.2.42
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/bin/app.js +35 -14
- package/package.json +1 -1
- package/src/deploy/repo-path.ts +54 -0
package/dist/bin/app.js
CHANGED
|
@@ -18,9 +18,43 @@ import {
|
|
|
18
18
|
import"../chunk-dz91avrb.js";
|
|
19
19
|
|
|
20
20
|
// bin/app.ts
|
|
21
|
+
import * as cdk from "aws-cdk-lib";
|
|
22
|
+
|
|
23
|
+
// src/deploy/repo-path.ts
|
|
21
24
|
import { execFileSync } from "node:child_process";
|
|
22
25
|
import { basename, dirname, relative, resolve, sep } from "node:path";
|
|
23
|
-
|
|
26
|
+
function inside(root, absolute) {
|
|
27
|
+
const rel = relative(root, absolute);
|
|
28
|
+
return rel !== "" && !rel.startsWith("..") ? rel.split(sep).join("/") : undefined;
|
|
29
|
+
}
|
|
30
|
+
function gitTopLevel(directory) {
|
|
31
|
+
try {
|
|
32
|
+
return execFileSync("git", ["rev-parse", "--show-toplevel"], {
|
|
33
|
+
cwd: directory,
|
|
34
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
35
|
+
}).toString().trim();
|
|
36
|
+
} catch {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function repoRelativePath(filePath, env = process.env, topLevel = gitTopLevel) {
|
|
41
|
+
const absolute = resolve(filePath);
|
|
42
|
+
const codebuildRoot = env.CODEBUILD_SRC_DIR;
|
|
43
|
+
if (codebuildRoot !== undefined && codebuildRoot !== "") {
|
|
44
|
+
const rel = inside(resolve(codebuildRoot), absolute);
|
|
45
|
+
if (rel !== undefined)
|
|
46
|
+
return rel;
|
|
47
|
+
}
|
|
48
|
+
const top = topLevel(dirname(absolute));
|
|
49
|
+
if (top !== undefined) {
|
|
50
|
+
const rel = inside(top, absolute);
|
|
51
|
+
if (rel !== undefined)
|
|
52
|
+
return rel;
|
|
53
|
+
}
|
|
54
|
+
return basename(absolute);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// bin/app.ts
|
|
24
58
|
var app = new cdk.App;
|
|
25
59
|
var instanceFilePath = app.node.tryGetContext("instanceFile");
|
|
26
60
|
if (instanceFilePath === undefined || instanceFilePath === "")
|
|
@@ -109,19 +143,6 @@ if (instance.newsletter.enabled)
|
|
|
109
143
|
});
|
|
110
144
|
cdk.Tags.of(app).add("project", instance.naming.secretPrefix);
|
|
111
145
|
app.synth();
|
|
112
|
-
function repoRelativePath(filePath) {
|
|
113
|
-
const absolute = resolve(filePath);
|
|
114
|
-
try {
|
|
115
|
-
const top = execFileSync("git", ["rev-parse", "--show-toplevel"], {
|
|
116
|
-
cwd: dirname(absolute),
|
|
117
|
-
stdio: ["ignore", "pipe", "ignore"]
|
|
118
|
-
}).toString().trim();
|
|
119
|
-
const rel = relative(top, absolute);
|
|
120
|
-
if (rel !== "" && !rel.startsWith(".."))
|
|
121
|
-
return rel.split(sep).join("/");
|
|
122
|
-
} catch {}
|
|
123
|
-
return basename(absolute);
|
|
124
|
-
}
|
|
125
146
|
export {
|
|
126
147
|
env
|
|
127
148
|
};
|
package/package.json
CHANGED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The instance file's path INSIDE the instance repository, which is what the
|
|
3
|
+
* pipeline's CodeBuild project is told to deploy from.
|
|
4
|
+
*
|
|
5
|
+
* Two places run a deploy, and they find the repository root differently:
|
|
6
|
+
*
|
|
7
|
+
* - A person's checkout is a git work tree, so `git rev-parse` names the root.
|
|
8
|
+
* - CodeBuild unpacks CodePipeline's source artifact into `CODEBUILD_SRC_DIR`.
|
|
9
|
+
* That is a zip of the repository, not a git work tree, so `git rev-parse`
|
|
10
|
+
* fails there. Falling back to the bare file name made every pipeline deploy
|
|
11
|
+
* rewrite its own `FOUNDATION_INSTANCE_FILE` to `instance.yaml`, and the
|
|
12
|
+
* next run failed with "no instance file" (Sky and Olivia, 2026-10-11).
|
|
13
|
+
*/
|
|
14
|
+
import { execFileSync } from "node:child_process";
|
|
15
|
+
import { basename, dirname, relative, resolve, sep } from "node:path";
|
|
16
|
+
|
|
17
|
+
/** `rel` when it names a file under the root, else undefined. */
|
|
18
|
+
function inside(root: string, absolute: string): string | undefined {
|
|
19
|
+
const rel = relative(root, absolute);
|
|
20
|
+
return rel !== "" && !rel.startsWith("..") ? rel.split(sep).join("/") : undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function gitTopLevel(directory: string): string | undefined {
|
|
24
|
+
try {
|
|
25
|
+
return execFileSync("git", ["rev-parse", "--show-toplevel"], {
|
|
26
|
+
cwd: directory,
|
|
27
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
28
|
+
})
|
|
29
|
+
.toString()
|
|
30
|
+
.trim();
|
|
31
|
+
} catch {
|
|
32
|
+
// Not inside a git work tree.
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function repoRelativePath(
|
|
38
|
+
filePath: string,
|
|
39
|
+
env: Record<string, string | undefined> = process.env,
|
|
40
|
+
topLevel: (directory: string) => string | undefined = gitTopLevel,
|
|
41
|
+
): string {
|
|
42
|
+
const absolute = resolve(filePath);
|
|
43
|
+
const codebuildRoot = env.CODEBUILD_SRC_DIR;
|
|
44
|
+
if (codebuildRoot !== undefined && codebuildRoot !== "") {
|
|
45
|
+
const rel = inside(resolve(codebuildRoot), absolute);
|
|
46
|
+
if (rel !== undefined) return rel;
|
|
47
|
+
}
|
|
48
|
+
const top = topLevel(dirname(absolute));
|
|
49
|
+
if (top !== undefined) {
|
|
50
|
+
const rel = inside(top, absolute);
|
|
51
|
+
if (rel !== undefined) return rel;
|
|
52
|
+
}
|
|
53
|
+
return basename(absolute);
|
|
54
|
+
}
|