Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/docker-git/tests/core/templates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,15 @@ describe("planFiles", () => {
const dockerfileSpec = specs.find(
(spec) => spec._tag === "File" && spec.relativePath === "Dockerfile"
)
const entrypointSpec = specs.find(
(spec) => spec._tag === "File" && spec.relativePath === "entrypoint.sh"
)

expect(composeSpec !== undefined && composeSpec._tag === "File").toBe(true)
expect(ignoreSpec !== undefined && ignoreSpec._tag === "File").toBe(true)
expect(configSpec !== undefined && configSpec._tag === "File").toBe(true)
expect(dockerfileSpec !== undefined && dockerfileSpec._tag === "File").toBe(true)
expect(entrypointSpec !== undefined && entrypointSpec._tag === "File").toBe(true)

if (configSpec && configSpec._tag === "File") {
expect(configSpec.contents).toContain(config.repoUrl)
Expand All @@ -61,6 +65,11 @@ describe("planFiles", () => {
expect(dockerfileSpec.contents).toContain("ncurses-term")
expect(dockerfileSpec.contents).toContain("tag-order builtins commands")
}

if (entrypointSpec && entrypointSpec._tag === "File") {
expect(entrypointSpec.contents).toContain("gh auth setup-git --hostname github.com --force")
expect(entrypointSpec.contents).toContain("GIT_USER_EMAIL=\"${GH_ID}+${GH_LOGIN}@users.noreply.github.com\"")
}
}))

it.effect("includes Playwright sidecar files when enabled", () =>
Expand Down
16 changes: 16 additions & 0 deletions packages/lib/src/core/templates-entrypoint/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ if [[ -n "$GH_TOKEN" ]]; then
fi
chmod 600 "$SSH_ENV_PATH"
chown 1000:1000 "$SSH_ENV_PATH" || true

SAFE_GH_TOKEN="$(printf "%q" "$GH_TOKEN")"
# Keep git+https auth in sync with gh auth so push/pull works without manual setup.
su - ${config.sshUser} -c "GH_TOKEN=$SAFE_GH_TOKEN gh auth setup-git --hostname github.com --force" || true

GH_LOGIN="$(su - ${config.sshUser} -c "GH_TOKEN=$SAFE_GH_TOKEN gh api user --jq .login" 2>/dev/null || true)"
GH_ID="$(su - ${config.sshUser} -c "GH_TOKEN=$SAFE_GH_TOKEN gh api user --jq .id" 2>/dev/null || true)"
GH_LOGIN="$(printf "%s" "$GH_LOGIN" | tr -d '\r\n')"
GH_ID="$(printf "%s" "$GH_ID" | tr -d '\r\n')"

if [[ -z "$GIT_USER_NAME" && -n "$GH_LOGIN" ]]; then
GIT_USER_NAME="$GH_LOGIN"
fi
if [[ -z "$GIT_USER_EMAIL" && -n "$GH_LOGIN" && -n "$GH_ID" ]]; then
GIT_USER_EMAIL="${"${"}GH_ID}+${"${"}GH_LOGIN}@users.noreply.github.com"
fi
fi

# 3) Configure git identity for the dev user if provided
Expand Down