@effected/github-actions 0.35.0 → 0.36.0
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/Action.js +7 -7
- package/ActionCache.js +4 -4
- package/ActionEnvironment.js +1 -1
- package/ActionInput.js +1 -1
- package/ActionLogger.js +197 -64
- package/ActionManifest.js +2 -2
- package/ActionOutputs.js +2 -2
- package/ActionState.js +1 -1
- package/ActionsIdentityToken.js +2 -2
- package/ActionsProvenance.js +2 -2
- package/ActionsRegistryCredential.js +2 -2
- package/Artifact.js +3 -3
- package/BlobStore.githubCache.js +2 -2
- package/BlobStore.js +4 -4
- package/CacheKey.js +2 -2
- package/CheckDocument.js +1 -1
- package/Checkout.js +361 -0
- package/DetachedProcess.js +4 -4
- package/DryRun.js +1 -1
- package/GitHubMarkdown.js +1 -1
- package/GitHubToken.js +2 -2
- package/ManagedDocument.js +1 -1
- package/OidcTokenIssuer.js +7 -7
- package/PackageManagerInstaller.js +3 -3
- package/README.md +2 -1
- package/Secret.js +1 -1
- package/ToolInstaller.js +4 -4
- package/index.d.ts +569 -103
- package/index.js +3 -2
- package/internal/actionsResults.js +1 -1
- package/internal/blobCause.js +1 -1
- package/internal/blobTransport.js +2 -2
- package/internal/cacheService.js +1 -1
- package/internal/checkout/asciiTrim.js +18 -0
- package/internal/checkout/credentials.js +563 -0
- package/internal/checkout/directory.js +119 -0
- package/internal/checkout/inputs.js +130 -0
- package/internal/checkout/refs.js +143 -0
- package/internal/checkout/settings.js +144 -0
- package/internal/checkout/source.js +418 -0
- package/internal/checkout/unsafePullRequest.js +62 -0
- package/internal/digest.js +1 -1
- package/internal/pnpmExe.js +1 -1
- package/internal/stepLog.js +225 -0
- package/internal/twirp.js +1 -1
- package/package.json +2 -1
package/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { WorkflowCommand } from "@effected/github-commands";
|
|
1
2
|
import { Action, ActionRuntime, describeCause } from "./Action.js";
|
|
2
3
|
import { ActionCache, ActionCacheError } from "./ActionCache.js";
|
|
3
4
|
import { ActionEnvironment, ActionEnvironmentError, GitHubContext, RunnerContext } from "./ActionEnvironment.js";
|
|
@@ -16,6 +17,7 @@ import { BlobStore, BlobStoreError } from "./BlobStore.js";
|
|
|
16
17
|
import { BlobTransferError } from "./BlobTransfer.js";
|
|
17
18
|
import { CacheKey, CacheKeyBadPatternError, CacheKeyReadError } from "./CacheKey.js";
|
|
18
19
|
import { CheckDocument, CheckDocumentError, CheckDocumentStamp, CheckReport } from "./CheckDocument.js";
|
|
20
|
+
import { Checkout, CheckoutAuth, CheckoutAuthError, CheckoutCommitMismatchError, CheckoutDefaultBranchError, CheckoutGitTooOldError, CheckoutPathError, CheckoutRef, CheckoutRefNotFoundError, CheckoutResult, CheckoutServerUrlError, CheckoutStateKeyInUseError, CheckoutUnqualifiedRefPinError, CheckoutUnsafePullRequestError } from "./Checkout.js";
|
|
19
21
|
import { CheckState, projectCheckState } from "./CheckState.js";
|
|
20
22
|
import { ChildEnv } from "./ChildEnv.js";
|
|
21
23
|
import { DetachedLogUnavailableError, DetachedNotReadyError, DetachedProcess, DetachedSignalFailedError, DetachedSpawnFailedError, InvalidPidError, ProcessId } from "./DetachedProcess.js";
|
|
@@ -27,6 +29,5 @@ import { OidcTokenError, OidcTokenIssuer } from "./OidcTokenIssuer.js";
|
|
|
27
29
|
import { AmbientPackageManager, CachedPackageManager, InstalledPackageManager, PackageManagerInstaller, PackageManagerInstallerError } from "./PackageManagerInstaller.js";
|
|
28
30
|
import { Secret } from "./Secret.js";
|
|
29
31
|
import { ToolInstaller, ToolInstallerError } from "./ToolInstaller.js";
|
|
30
|
-
import { WorkflowCommand } from "@effected/github-commands";
|
|
31
32
|
|
|
32
|
-
export { Action, ActionCache, ActionCacheError, ActionEnvironment, ActionEnvironmentError, ActionInput, ActionLogger, ActionManifest, ActionManifestBranding, ActionManifestCompositeRuns, ActionManifestDecodeError, ActionManifestDiff, ActionManifestDockerRuns, ActionManifestInput, ActionManifestNodeRuns, ActionManifestOutput, ActionManifestReadError, ActionOutputs, ActionRuntime, ActionState, ActionStateError, ActionsIdentityToken, ActionsProvenance, ActionsRegistryCredential, AmbientPackageManager, Artifact, ArtifactError, BlobEnvelope, BlobMetadataDecodeError, BlobMetadataEncodeError, BlobStore, BlobStoreError, BlobTransferError, CacheKey, CacheKeyBadPatternError, CacheKeyReadError, CachedPackageManager, CheckDocument, CheckDocumentError, CheckDocumentStamp, CheckReport, CheckState, ChildEnv, DetachedLogUnavailableError, DetachedNotReadyError, DetachedOutputError, DetachedProcess, DetachedSignalFailedError, DetachedSpawnFailedError, DryRun, GitHubCacheBlobStore, GitHubContext, GitHubMarkdown, GitHubToken, GitHubTokenError, InstalledPackageManager, InvalidOutputNameError, InvalidPidError, ManagedDocument, ManagedDocumentError, NotABlobEnvelopeError, OidcTokenError, OidcTokenIssuer, OutputEncodeError, PackageManagerInstaller, PackageManagerInstallerError, ProcessId, RecordedOutput, RunnerContext, RunnerFileUnavailableError, RunnerFileWriteError, Secret, ToolInstaller, ToolInstallerError, TruncatedBlobEnvelopeError, UnsupportedBlobEnvelopeVersionError, WorkflowCommand, describeCause, projectCheckState };
|
|
33
|
+
export { Action, ActionCache, ActionCacheError, ActionEnvironment, ActionEnvironmentError, ActionInput, ActionLogger, ActionManifest, ActionManifestBranding, ActionManifestCompositeRuns, ActionManifestDecodeError, ActionManifestDiff, ActionManifestDockerRuns, ActionManifestInput, ActionManifestNodeRuns, ActionManifestOutput, ActionManifestReadError, ActionOutputs, ActionRuntime, ActionState, ActionStateError, ActionsIdentityToken, ActionsProvenance, ActionsRegistryCredential, AmbientPackageManager, Artifact, ArtifactError, BlobEnvelope, BlobMetadataDecodeError, BlobMetadataEncodeError, BlobStore, BlobStoreError, BlobTransferError, CacheKey, CacheKeyBadPatternError, CacheKeyReadError, CachedPackageManager, CheckDocument, CheckDocumentError, CheckDocumentStamp, CheckReport, CheckState, Checkout, CheckoutAuth, CheckoutAuthError, CheckoutCommitMismatchError, CheckoutDefaultBranchError, CheckoutGitTooOldError, CheckoutPathError, CheckoutRef, CheckoutRefNotFoundError, CheckoutResult, CheckoutServerUrlError, CheckoutStateKeyInUseError, CheckoutUnqualifiedRefPinError, CheckoutUnsafePullRequestError, ChildEnv, DetachedLogUnavailableError, DetachedNotReadyError, DetachedOutputError, DetachedProcess, DetachedSignalFailedError, DetachedSpawnFailedError, DryRun, GitHubCacheBlobStore, GitHubContext, GitHubMarkdown, GitHubToken, GitHubTokenError, InstalledPackageManager, InvalidOutputNameError, InvalidPidError, ManagedDocument, ManagedDocumentError, NotABlobEnvelopeError, OidcTokenError, OidcTokenIssuer, OutputEncodeError, PackageManagerInstaller, PackageManagerInstallerError, ProcessId, RecordedOutput, RunnerContext, RunnerFileUnavailableError, RunnerFileWriteError, Secret, ToolInstaller, ToolInstallerError, TruncatedBlobEnvelopeError, UnsupportedBlobEnvelopeVersionError, WorkflowCommand, describeCause, projectCheckState };
|
package/internal/blobCause.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BlobTransferError } from "../BlobTransfer.js";
|
|
2
|
-
import { blobUrl } from "./blobCause.js";
|
|
3
1
|
import { Effect, PlatformError, Schedule, Stream } from "effect";
|
|
4
2
|
import { HttpBody, HttpClientRequest } from "effect/http";
|
|
3
|
+
import { BlobTransferError } from "../BlobTransfer.js";
|
|
4
|
+
import { blobUrl } from "./blobCause.js";
|
|
5
5
|
|
|
6
6
|
// src/internal/blobTransport.ts
|
|
7
7
|
/**
|
package/internal/cacheService.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CONFLICT, isOk, stringField } from "./twirp.js";
|
|
2
1
|
import { Effect, Option } from "effect";
|
|
2
|
+
import { CONFLICT, isOk, stringField } from "./twirp.js";
|
|
3
3
|
|
|
4
4
|
// src/internal/cacheService.ts
|
|
5
5
|
/** The Twirp service the Actions cache protocol lives under. @internal */
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/internal/checkout/asciiTrim.ts
|
|
2
|
+
const isAsciiWhitespace = (code) => code === 32 || code >= 9 && code <= 13;
|
|
3
|
+
/**
|
|
4
|
+
* Strips only the ASCII whitespace (`\t`, `\n`, `\v`, `\f`, `\r` and space) from both ends of a value. A BOM or an NBSP
|
|
5
|
+
* is valid inside a git ref name, so a wider trim would reclassify a fork branch named `"<BOM><sha>"` as a bare commit
|
|
6
|
+
* and slip past the unsafe pull request guard. A two-ended index scan, linear in the value's length.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
const asciiTrim = (value) => {
|
|
11
|
+
let start = 0;
|
|
12
|
+
let end = value.length;
|
|
13
|
+
while (start < end && isAsciiWhitespace(value.charCodeAt(start))) start++;
|
|
14
|
+
while (end > start && isAsciiWhitespace(value.charCodeAt(end - 1))) end--;
|
|
15
|
+
return start === 0 && end === value.length ? value : value.slice(start, end);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { asciiTrim };
|
|
@@ -0,0 +1,563 @@
|
|
|
1
|
+
import { Git } from "@effected/git";
|
|
2
|
+
import { Effect, Exit, FileSystem, Option, Path, PlatformError, Redacted, Schema } from "effect";
|
|
3
|
+
import { SecureRandom } from "effect/crypto";
|
|
4
|
+
import { Base64 } from "effect/encoding";
|
|
5
|
+
import { ChildProcess } from "effect/process";
|
|
6
|
+
import { ActionEnvironment } from "../../ActionEnvironment.js";
|
|
7
|
+
import { ActionLogger } from "../../ActionLogger.js";
|
|
8
|
+
import { Secret } from "../../Secret.js";
|
|
9
|
+
import { isWindowsRunner } from "../runner.js";
|
|
10
|
+
import { serverOrigin } from "./refs.js";
|
|
11
|
+
|
|
12
|
+
// src/internal/checkout/credentials.ts
|
|
13
|
+
const SSH_COMMAND_KEY = "core.sshCommand";
|
|
14
|
+
const TOKEN_PLACEHOLDER = "AUTHORIZATION: basic ***";
|
|
15
|
+
const CREDENTIALS_FILE = /git-credentials-[0-9a-f-]+\.config$/i;
|
|
16
|
+
const KNOWN_GITHUB_HOST = "github.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCj7ndNxQowgcQnjshcLrqPEiiphnt+VTTvDP6mHBL9j1aNUkY4Ue1gvwnGLVlOhGeYrnZaMgRK6+PKCUXaDbC7qtbW8gIkhL7aGCsOr/C56SJMy/BCZfxd1nWzAOxSDPgVsmerOBYfNqltV9/hWCqBywINIR+5dIg6JTJ72pcEpEjcYgXkE2YEFXV1JHnsKgbLWNlhScqb2UmyRkQyytRLtL+38TGxkxCflmO+5Z8CSSNY7GidjMIZ7Q4zMjA2n1nGrlTDkzwDCsw+wqFPGQA179cnfGWOWRVruj16z6XyvxvjJwbz0wQZ75XK5tKSb7FNyeIEs4TT4jk+S4dhPeAUC5y+bDYirYgM4GC7uEnztnZyaVWQ7B381AK4Qdrwt51ZqExKbQpTUNn+EjqoTwvqNj4kqx5QUCI0ThS/YkOxJCXmPUWZbhjpCg56i+2aB6CmK2JGhn57K5mj0MNdBXA4/WnwH6XoPWJzK5Nyu2zB3nAZp+S5hpQs+p1vN1/wsjk=";
|
|
17
|
+
/**
|
|
18
|
+
* What a checkout wrote to authenticate, so it can be removed later: from a
|
|
19
|
+
* scope finalizer, before `checkout` returns, or from the post step, which
|
|
20
|
+
* reads it back from `ActionState`.
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* Encodes to plain JSON: every optional path is `OptionFromNullOr`.
|
|
24
|
+
*
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
var CredentialRecord = class extends Schema.Class("CredentialRecord")({
|
|
28
|
+
/** The checked-out repository's working directory. */
|
|
29
|
+
repositoryPath: Schema.String,
|
|
30
|
+
/** The server's `SCHEME://HOST[:PORT]`, which names the extraheader and `insteadOf` keys. */
|
|
31
|
+
origin: Schema.String,
|
|
32
|
+
/** The credentials file `includeIf` points at, when a token was configured. */
|
|
33
|
+
credentialsFile: Schema.OptionFromNullOr(Schema.String),
|
|
34
|
+
/** The SSH private key file. */
|
|
35
|
+
sshKeyPath: Schema.OptionFromNullOr(Schema.String),
|
|
36
|
+
/** The SSH known-hosts file. */
|
|
37
|
+
knownHostsPath: Schema.OptionFromNullOr(Schema.String),
|
|
38
|
+
/** The temporary global config (`GIT_CONFIG_GLOBAL`), discarded after the run. */
|
|
39
|
+
temporaryGlobalConfig: Schema.OptionFromNullOr(Schema.String),
|
|
40
|
+
/** Whether the repository was marked a `safe.directory`. */
|
|
41
|
+
safeDirectory: Schema.Boolean,
|
|
42
|
+
/** Whether submodules were checked out, so removal walks them. */
|
|
43
|
+
submodules: Schema.Boolean
|
|
44
|
+
}) {};
|
|
45
|
+
const forward = (value) => value.replace(/\\/g, "/");
|
|
46
|
+
const basename = (value) => forward(value).split("/").pop() ?? value;
|
|
47
|
+
/** A pure POSIX `relative`, tolerant of a Windows drive's letter case. */
|
|
48
|
+
const relativeTo = (from, to) => {
|
|
49
|
+
const drive = /^[A-Za-z]:/.test(from);
|
|
50
|
+
const fromParts = from.split("/").filter((part) => part.length > 0);
|
|
51
|
+
const toParts = to.split("/").filter((part) => part.length > 0);
|
|
52
|
+
const same = (a, b) => drive ? a?.toLowerCase() === b?.toLowerCase() : a === b;
|
|
53
|
+
let common = 0;
|
|
54
|
+
while (common < fromParts.length && common < toParts.length && same(fromParts[common], toParts[common])) common += 1;
|
|
55
|
+
return [...fromParts.slice(common).map(() => ".."), ...toParts.slice(common)].join("/");
|
|
56
|
+
};
|
|
57
|
+
/** `/github/workspace` joined with a relative path, `..` segments resolved. */
|
|
58
|
+
const containerPath = (relative) => {
|
|
59
|
+
const parts = ["github", "workspace"];
|
|
60
|
+
for (const part of relative.split("/")) {
|
|
61
|
+
if (part === "" || part === ".") continue;
|
|
62
|
+
if (part === "..") parts.pop();
|
|
63
|
+
else parts.push(part);
|
|
64
|
+
}
|
|
65
|
+
return `/${parts.join("/")}`;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* The `includeIf` entries checkout writes so a git directory reads the
|
|
69
|
+
* credentials file: the host directory and its worktrees, then the same pair
|
|
70
|
+
* as a container job sees them under `/github/workspace`, pointing at
|
|
71
|
+
* `/github/runner_temp/<basename>`.
|
|
72
|
+
*
|
|
73
|
+
* @remarks
|
|
74
|
+
* Pure. Backslashes become `/` in every key on every OS, as checkout does; the
|
|
75
|
+
* host value is the credentials file exactly as given. `worktrees: false`
|
|
76
|
+
* drops the worktree pair, as checkout's submodule entries do.
|
|
77
|
+
*
|
|
78
|
+
* @internal
|
|
79
|
+
*/
|
|
80
|
+
const includeIfKeys = (input) => {
|
|
81
|
+
const gitDir = forward(input.gitDir);
|
|
82
|
+
const container = containerPath(relativeTo(forward(input.workspace), gitDir));
|
|
83
|
+
const containerFile = `/github/runner_temp/${basename(input.credentialsFile)}`;
|
|
84
|
+
const worktrees = input.worktrees ?? true;
|
|
85
|
+
return [
|
|
86
|
+
{
|
|
87
|
+
key: `includeIf.gitdir:${gitDir}.path`,
|
|
88
|
+
value: input.credentialsFile
|
|
89
|
+
},
|
|
90
|
+
...worktrees ? [{
|
|
91
|
+
key: `includeIf.gitdir:${gitDir}/worktrees/*.path`,
|
|
92
|
+
value: input.credentialsFile
|
|
93
|
+
}] : [],
|
|
94
|
+
{
|
|
95
|
+
key: `includeIf.gitdir:${container}.path`,
|
|
96
|
+
value: containerFile
|
|
97
|
+
},
|
|
98
|
+
...worktrees ? [{
|
|
99
|
+
key: `includeIf.gitdir:${container}/worktrees/*.path`,
|
|
100
|
+
value: containerFile
|
|
101
|
+
}] : []
|
|
102
|
+
];
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Creates the temporary global config, `$RUNNER_TEMP/<uuid>/.gitconfig`,
|
|
106
|
+
* seeded from `<home>/.gitconfig` when one exists, as checkout's
|
|
107
|
+
* `configureTempGlobalConfig` does.
|
|
108
|
+
*
|
|
109
|
+
* @remarks
|
|
110
|
+
* Point git at it with `GIT_CONFIG_GLOBAL`; write into it with `-f`. Removing
|
|
111
|
+
* its directory discards it.
|
|
112
|
+
*
|
|
113
|
+
* @internal
|
|
114
|
+
*/
|
|
115
|
+
const temporaryGlobalConfig = (home, runnerTemp) => Effect.gen(function* () {
|
|
116
|
+
const fs = yield* FileSystem.FileSystem;
|
|
117
|
+
const path = yield* Path.Path;
|
|
118
|
+
const random = yield* SecureRandom.SecureRandom;
|
|
119
|
+
const directory = path.join(runnerTemp, yield* random.uuidV4());
|
|
120
|
+
yield* fs.makeDirectory(directory, { recursive: true });
|
|
121
|
+
const file = path.join(directory, ".gitconfig");
|
|
122
|
+
const source = Option.map(home, (dir) => path.join(dir, ".gitconfig"));
|
|
123
|
+
yield* Effect.gen(function* () {
|
|
124
|
+
if (Option.isSome(source) && (yield* fs.exists(source.value))) {
|
|
125
|
+
yield* Effect.logInfo(`Copying '${source.value}' to '${file}'`);
|
|
126
|
+
yield* fs.copyFile(source.value, file);
|
|
127
|
+
} else yield* fs.writeFileString(file, "");
|
|
128
|
+
}).pipe(Effect.onExit((exit) => Exit.isSuccess(exit) ? Effect.void : fs.remove(directory, {
|
|
129
|
+
recursive: true,
|
|
130
|
+
force: true
|
|
131
|
+
}).pipe(Effect.ignore)));
|
|
132
|
+
return file;
|
|
133
|
+
});
|
|
134
|
+
/** `HOME`, or `USERPROFILE` where Windows leaves `HOME` unset. */
|
|
135
|
+
const homeDirectory = (env) => Effect.flatMap(env.getOptional("HOME"), (home) => Option.isSome(home) ? Effect.succeed(home) : env.getOptional("USERPROFILE"));
|
|
136
|
+
/**
|
|
137
|
+
* Creates the temporary global config a checkout runs under and, when
|
|
138
|
+
* `settings.safeDirectory`, marks the repository a `safe.directory` in it, as
|
|
139
|
+
* checkout does before it touches an existing directory. A failed
|
|
140
|
+
* `safe.directory` write is logged and the run continues, as checkout's is.
|
|
141
|
+
*
|
|
142
|
+
* @internal
|
|
143
|
+
*/
|
|
144
|
+
const prepareGlobalConfig = (settings, git) => Effect.gen(function* () {
|
|
145
|
+
const env = yield* ActionEnvironment;
|
|
146
|
+
const path = yield* Path.Path;
|
|
147
|
+
const file = yield* temporaryGlobalConfig(yield* homeDirectory(env), yield* env.get("RUNNER_TEMP"));
|
|
148
|
+
if (settings.safeDirectory) {
|
|
149
|
+
yield* Effect.logInfo("Adding repository directory to the temporary git global config as a safe directory");
|
|
150
|
+
yield* git.configAdd(path.dirname(file), "safe.directory", settings.path, { file }).pipe(Effect.catch((error) => Effect.logInfo(`Failed to initialize safe directory with error: ${error.message}`)));
|
|
151
|
+
}
|
|
152
|
+
return file;
|
|
153
|
+
});
|
|
154
|
+
/** The values checkout rewrites to HTTPS: `git@<host>:` and, from the event payload, `org-<id>@github.com:`. */
|
|
155
|
+
const insteadOfValues = (env, serverUrl) => Effect.gen(function* () {
|
|
156
|
+
const values = [`git@${new URL(serverUrl).hostname}:`];
|
|
157
|
+
const id = (yield* env.payload.pipe(Effect.orElseSucceed(() => void 0)))?.repository?.owner?.id;
|
|
158
|
+
if (typeof id === "number") values.push(`org-${id}@github.com:`);
|
|
159
|
+
return values;
|
|
160
|
+
});
|
|
161
|
+
const insteadOfKey = (origin) => `url.${origin}/.insteadOf`;
|
|
162
|
+
const extraheaderKey = (origin) => `http.${origin}/.extraheader`;
|
|
163
|
+
/**
|
|
164
|
+
* The `ssh` program checkout names in its SSH command: the first `ssh` (`ssh.exe`
|
|
165
|
+
* on Windows) on `PATH`, as checkout's `io.which("ssh")` finds it, else a bare
|
|
166
|
+
* `ssh` when `PATH` has none.
|
|
167
|
+
*/
|
|
168
|
+
const resolveSsh = (env) => Effect.gen(function* () {
|
|
169
|
+
const fs = yield* FileSystem.FileSystem;
|
|
170
|
+
const path = yield* Path.Path;
|
|
171
|
+
const windows = yield* isWindowsRunner(env);
|
|
172
|
+
const found = yield* env.getOptional("PATH");
|
|
173
|
+
const entries = Option.isSome(found) ? found : yield* env.getOptional("Path");
|
|
174
|
+
if (Option.isNone(entries)) return Option.none();
|
|
175
|
+
const program = windows ? "ssh.exe" : "ssh";
|
|
176
|
+
for (const directory of entries.value.split(windows ? ";" : ":")) {
|
|
177
|
+
if (directory.trim() === "") continue;
|
|
178
|
+
const candidate = path.join(directory, program);
|
|
179
|
+
if (yield* fs.exists(candidate).pipe(Effect.orElseSucceed(() => false))) return Option.some(candidate);
|
|
180
|
+
}
|
|
181
|
+
return Option.none();
|
|
182
|
+
});
|
|
183
|
+
/**
|
|
184
|
+
* The SSH command, as checkout builds it: the program quoted by its absolute
|
|
185
|
+
* path when one was found, else a bare `ssh`. `form: "persisted"` spells the
|
|
186
|
+
* files as `$RUNNER_TEMP/<basename>`, checkout's own form, so a later step (or
|
|
187
|
+
* a container job) resolves them in its own temp directory; `form: "run"` uses
|
|
188
|
+
* the absolute paths, so the run never depends on an ambient `RUNNER_TEMP`.
|
|
189
|
+
*/
|
|
190
|
+
const sshCommand = (program, keyPath, knownHostsPath, strict, form) => {
|
|
191
|
+
const file = (value) => form === "run" ? forward(value) : `$RUNNER_TEMP/${basename(value)}`;
|
|
192
|
+
const strictness = strict ? " -o StrictHostKeyChecking=yes -o CheckHostIP=no" : "";
|
|
193
|
+
return `${Option.match(program, {
|
|
194
|
+
onNone: () => "ssh",
|
|
195
|
+
onSome: (value) => `"${value}"`
|
|
196
|
+
})} -i "${file(keyPath)}"${strictness} -o "UserKnownHostsFile=${file(knownHostsPath)}"`;
|
|
197
|
+
};
|
|
198
|
+
const sshStrict = (settings) => settings.auth._tag !== "Ssh" || (settings.auth.strict ?? true);
|
|
199
|
+
/** The token the extraheader carries: a `Token`'s, or an `Ssh` auth's optional one. */
|
|
200
|
+
const tokenOf = (settings) => settings.auth._tag === "Token" ? Option.some(settings.auth.token) : Option.fromUndefinedOr(settings.auth.token);
|
|
201
|
+
/** Runs `icacls`, failing typed on a non-zero exit. */
|
|
202
|
+
const icacls = (args) => Effect.flatMap(ActionLogger.command(ChildProcess.make("icacls", [...args])), ({ exitCode }) => exitCode === 0 ? Effect.void : Effect.fail(PlatformError.systemError({
|
|
203
|
+
_tag: "PermissionDenied",
|
|
204
|
+
module: "Checkout",
|
|
205
|
+
method: "icacls",
|
|
206
|
+
pathOrDescriptor: args[0],
|
|
207
|
+
description: `icacls exited ${exitCode}`
|
|
208
|
+
})));
|
|
209
|
+
/**
|
|
210
|
+
* Writes checkout's v6+ credential layout for `settings`, as its
|
|
211
|
+
* `configureAuth` does, and returns what was written with the environment the
|
|
212
|
+
* rest of the run's git must see.
|
|
213
|
+
*
|
|
214
|
+
* @remarks
|
|
215
|
+
* The token and its `x-access-token` base64 are masked before any git runs.
|
|
216
|
+
* The extraheader goes into `$RUNNER_TEMP/git-credentials-<uuid>.config` as a
|
|
217
|
+
* placeholder written by `git config -f`, then the placeholder is replaced
|
|
218
|
+
* through `FileSystem`, so the credential never reaches a command line; the
|
|
219
|
+
* repository's `.git/config` holds only the `includeIf` entries naming the
|
|
220
|
+
* file. An SSH key lands under `RUNNER_TEMP` with mode `0600` (and `icacls`
|
|
221
|
+
* on Windows), beside checkout's known-hosts file, and `GIT_SSH_COMMAND` is in
|
|
222
|
+
* `runEnv`; `core.sshCommand` is persisted under `"job"` and `"action"`. A temporary
|
|
223
|
+
* global config holds `safe.directory` (and later the submodule auth) and is
|
|
224
|
+
* in `runEnv` as `GIT_CONFIG_GLOBAL`. Any previous credential layout is
|
|
225
|
+
* removed first. A failure part way removes everything written so far, the
|
|
226
|
+
* token file and the SSH key included, before the failure propagates, and
|
|
227
|
+
* discards a temporary global config this call made (one passed in is the
|
|
228
|
+
* caller's).
|
|
229
|
+
*
|
|
230
|
+
* Pass `existing.temporaryGlobalConfig` when the caller already made the
|
|
231
|
+
* temporary global config (and wrote `safe.directory` into it), as checkout
|
|
232
|
+
* does before it prepares an existing directory; it is then used as is.
|
|
233
|
+
*
|
|
234
|
+
* @internal
|
|
235
|
+
*/
|
|
236
|
+
const configure = (settings, git, existing) => Effect.gen(function* () {
|
|
237
|
+
const env = yield* ActionEnvironment;
|
|
238
|
+
const fs = yield* FileSystem.FileSystem;
|
|
239
|
+
const path = yield* Path.Path;
|
|
240
|
+
const random = yield* SecureRandom.SecureRandom;
|
|
241
|
+
const runnerTemp = yield* env.get("RUNNER_TEMP");
|
|
242
|
+
const workspace = yield* env.get("GITHUB_WORKSPACE");
|
|
243
|
+
const origin = serverOrigin(settings.serverUrl);
|
|
244
|
+
const repositoryPath = settings.path;
|
|
245
|
+
let basicCredential = Option.none();
|
|
246
|
+
const token = tokenOf(settings);
|
|
247
|
+
if (Option.isSome(token)) {
|
|
248
|
+
const plaintext = yield* Secret.forRunnerFile(token.value);
|
|
249
|
+
const encoded = Base64.encode(`x-access-token:${plaintext}`);
|
|
250
|
+
yield* Secret.mask(Redacted.make(encoded));
|
|
251
|
+
basicCredential = Option.some(encoded);
|
|
252
|
+
}
|
|
253
|
+
const sshKey = settings.auth._tag === "Ssh" ? Option.some(yield* Secret.forRunnerFile(settings.auth.key)) : Option.none();
|
|
254
|
+
const runEnv = {};
|
|
255
|
+
let globalConfig = Option.none();
|
|
256
|
+
if (existing?.temporaryGlobalConfig !== void 0) {
|
|
257
|
+
globalConfig = Option.some(existing.temporaryGlobalConfig);
|
|
258
|
+
runEnv.GIT_CONFIG_GLOBAL = existing.temporaryGlobalConfig;
|
|
259
|
+
} else if (settings.safeDirectory || settings.submodules) {
|
|
260
|
+
const file = yield* temporaryGlobalConfig(yield* homeDirectory(env), runnerTemp);
|
|
261
|
+
globalConfig = Option.some(file);
|
|
262
|
+
runEnv.GIT_CONFIG_GLOBAL = file;
|
|
263
|
+
if (settings.safeDirectory) yield* git.configAdd(path.dirname(file), "safe.directory", repositoryPath, { file });
|
|
264
|
+
}
|
|
265
|
+
const base = CredentialRecord.make({
|
|
266
|
+
repositoryPath,
|
|
267
|
+
origin,
|
|
268
|
+
credentialsFile: Option.none(),
|
|
269
|
+
sshKeyPath: Option.none(),
|
|
270
|
+
knownHostsPath: Option.none(),
|
|
271
|
+
temporaryGlobalConfig: Option.none(),
|
|
272
|
+
safeDirectory: settings.safeDirectory,
|
|
273
|
+
submodules: false
|
|
274
|
+
});
|
|
275
|
+
let partial = base;
|
|
276
|
+
const write = Effect.gen(function* () {
|
|
277
|
+
yield* removeLayout(base, git);
|
|
278
|
+
let sshKeyPath = Option.none();
|
|
279
|
+
let knownHostsPath = Option.none();
|
|
280
|
+
if (Option.isSome(sshKey)) {
|
|
281
|
+
const id = yield* random.uuidV4();
|
|
282
|
+
const keyPath = path.join(runnerTemp, id);
|
|
283
|
+
const hostsPath = path.join(runnerTemp, `${id}_known_hosts`);
|
|
284
|
+
partial = CredentialRecord.make({
|
|
285
|
+
...partial,
|
|
286
|
+
sshKeyPath: Option.some(keyPath),
|
|
287
|
+
knownHostsPath: Option.some(hostsPath)
|
|
288
|
+
});
|
|
289
|
+
yield* fs.makeDirectory(runnerTemp, { recursive: true });
|
|
290
|
+
yield* fs.writeFileString(keyPath, `${sshKey.value.trim()}\n`, { mode: 384 });
|
|
291
|
+
yield* fs.chmod(keyPath, 384);
|
|
292
|
+
if (yield* isWindowsRunner(env)) {
|
|
293
|
+
const domain = yield* env.get("USERDOMAIN");
|
|
294
|
+
const user = yield* env.get("USERNAME");
|
|
295
|
+
yield* icacls([
|
|
296
|
+
keyPath,
|
|
297
|
+
"/grant:r",
|
|
298
|
+
`${domain}\\${user}:F`
|
|
299
|
+
]);
|
|
300
|
+
yield* icacls([keyPath, "/inheritance:r"]);
|
|
301
|
+
}
|
|
302
|
+
const home = yield* homeDirectory(env);
|
|
303
|
+
const userKnownHostsPath = Option.map(home, (dir) => path.join(dir, ".ssh", "known_hosts"));
|
|
304
|
+
const userKnownHosts = Option.isSome(userKnownHostsPath) && (yield* fs.exists(userKnownHostsPath.value)) ? yield* fs.readFileString(userKnownHostsPath.value) : "";
|
|
305
|
+
let knownHosts = "";
|
|
306
|
+
if (userKnownHosts && Option.isSome(userKnownHostsPath)) {
|
|
307
|
+
const from = userKnownHostsPath.value;
|
|
308
|
+
knownHosts += `# Begin from ${from}\n${userKnownHosts}\n# End from ${from}\n`;
|
|
309
|
+
}
|
|
310
|
+
if (settings.auth._tag === "Ssh" && settings.auth.knownHosts) knownHosts += `# Begin from input known hosts\n${settings.auth.knownHosts}\n# end from input known hosts\n`;
|
|
311
|
+
knownHosts += `# Begin implicitly added github.com\n${KNOWN_GITHUB_HOST}\n# End implicitly added github.com\n`;
|
|
312
|
+
yield* fs.writeFileString(hostsPath, knownHosts);
|
|
313
|
+
sshKeyPath = Option.some(keyPath);
|
|
314
|
+
knownHostsPath = Option.some(hostsPath);
|
|
315
|
+
const program = yield* resolveSsh(env);
|
|
316
|
+
runEnv.GIT_SSH_COMMAND = sshCommand(program, keyPath, hostsPath, sshStrict(settings), "run");
|
|
317
|
+
if (settings.credentials !== "none") yield* git.configSet(repositoryPath, SSH_COMMAND_KEY, sshCommand(program, keyPath, hostsPath, sshStrict(settings), "persisted"));
|
|
318
|
+
}
|
|
319
|
+
let credentialsFile = Option.none();
|
|
320
|
+
if (Option.isSome(basicCredential)) {
|
|
321
|
+
const file = path.join(runnerTemp, `git-credentials-${yield* random.uuidV4()}.config`);
|
|
322
|
+
partial = CredentialRecord.make({
|
|
323
|
+
...partial,
|
|
324
|
+
credentialsFile: Option.some(file)
|
|
325
|
+
});
|
|
326
|
+
yield* Effect.logDebug(`Credentials config path: ${file}`);
|
|
327
|
+
yield* git.configSet(runnerTemp, extraheaderKey(origin), TOKEN_PLACEHOLDER, { file });
|
|
328
|
+
const content = yield* fs.readFileString(file);
|
|
329
|
+
const at = content.indexOf(TOKEN_PLACEHOLDER);
|
|
330
|
+
if (at < 0 || at !== content.lastIndexOf(TOKEN_PLACEHOLDER)) return yield* Effect.die(/* @__PURE__ */ new Error(`Unable to replace auth placeholder in ${file}`));
|
|
331
|
+
yield* fs.chmod(file, 384);
|
|
332
|
+
yield* fs.writeFileString(file, content.replace(TOKEN_PLACEHOLDER, `AUTHORIZATION: basic ${basicCredential.value}`), { mode: 384 });
|
|
333
|
+
credentialsFile = Option.some(file);
|
|
334
|
+
for (const entry of includeIfKeys({
|
|
335
|
+
gitDir: path.join(repositoryPath, ".git"),
|
|
336
|
+
workspace,
|
|
337
|
+
credentialsFile: file
|
|
338
|
+
})) yield* git.configSet(repositoryPath, entry.key, entry.value);
|
|
339
|
+
}
|
|
340
|
+
return CredentialRecord.make({
|
|
341
|
+
...base,
|
|
342
|
+
credentialsFile,
|
|
343
|
+
sshKeyPath,
|
|
344
|
+
knownHostsPath,
|
|
345
|
+
temporaryGlobalConfig: globalConfig,
|
|
346
|
+
submodules: settings.submodules
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
return {
|
|
350
|
+
record: yield* Git.withRunOptions(write.pipe(Effect.onError(() => Effect.suspend(() => Effect.andThen(removeLayout(partial, git), existing?.temporaryGlobalConfig === void 0 && Option.isSome(globalConfig) ? removeUnderTemp(Option.some(runnerTemp), "temporary global config", path.dirname(globalConfig.value), { recursive: true }) : Effect.void)))), { env: { ...runEnv } }),
|
|
351
|
+
runEnv
|
|
352
|
+
};
|
|
353
|
+
});
|
|
354
|
+
/**
|
|
355
|
+
* Writes the submodule auth into the temporary global config before a
|
|
356
|
+
* submodule update, as checkout's `configureGlobalAuth` does: an
|
|
357
|
+
* `include.path` naming the credentials file and, for a token, the
|
|
358
|
+
* SSH-to-HTTPS `insteadOf` values.
|
|
359
|
+
*
|
|
360
|
+
* @remarks
|
|
361
|
+
* A separate step rather than part of {@link configure}: while the global
|
|
362
|
+
* config includes the credentials file, the repository reads the extraheader
|
|
363
|
+
* twice (through its `includeIf` and through the global include), so it is
|
|
364
|
+
* written only after the repository's own fetch, as checkout writes it. A
|
|
365
|
+
* no-op when {@link configure} made no temporary global config.
|
|
366
|
+
*
|
|
367
|
+
* @internal
|
|
368
|
+
*/
|
|
369
|
+
const configureGlobalAuth = (settings, record, git) => Effect.gen(function* () {
|
|
370
|
+
if (Option.isNone(record.temporaryGlobalConfig)) return;
|
|
371
|
+
const env = yield* ActionEnvironment;
|
|
372
|
+
const path = yield* Path.Path;
|
|
373
|
+
const file = record.temporaryGlobalConfig.value;
|
|
374
|
+
const cwd = path.dirname(file);
|
|
375
|
+
if (Option.isSome(record.credentialsFile)) yield* git.configSet(cwd, "include.path", record.credentialsFile.value, { file });
|
|
376
|
+
yield* unsetPresent(git, cwd, file, [insteadOfKey(record.origin)]);
|
|
377
|
+
if (settings.auth._tag === "Token") for (const value of yield* insteadOfValues(env, settings.serverUrl)) yield* git.configAdd(cwd, insteadOfKey(record.origin), value, { file });
|
|
378
|
+
});
|
|
379
|
+
/** Each submodule's absolute git directory, from `git submodule foreach`. */
|
|
380
|
+
const submoduleGitDirs = (git, repositoryPath, recursive) => Effect.map(git.submoduleForeach(repositoryPath, "git rev-parse --absolute-git-dir", { recursive }), (output) => output.split(/\r?\n/).map((line) => line.trim()).filter((line) => line.length > 0 && !line.startsWith("Entering '")));
|
|
381
|
+
/**
|
|
382
|
+
* Persists the credentials into each submodule after `submodule update`, as
|
|
383
|
+
* checkout's `configureSubmoduleAuth` does: the `includeIf` entries in each
|
|
384
|
+
* submodule's config, then `core.sshCommand` for an SSH key or
|
|
385
|
+
* the `insteadOf` values for a token.
|
|
386
|
+
*
|
|
387
|
+
* @remarks
|
|
388
|
+
* A no-op under `"none"`, whose credentials do not outlive the call.
|
|
389
|
+
*
|
|
390
|
+
* @internal
|
|
391
|
+
*/
|
|
392
|
+
const configureSubmodules = (settings, record, git) => Effect.gen(function* () {
|
|
393
|
+
if (settings.credentials === "none") return;
|
|
394
|
+
const env = yield* ActionEnvironment;
|
|
395
|
+
const path = yield* Path.Path;
|
|
396
|
+
const workspace = yield* env.get("GITHUB_WORKSPACE");
|
|
397
|
+
const key = insteadOfKey(record.origin);
|
|
398
|
+
const values = yield* insteadOfValues(env, settings.serverUrl);
|
|
399
|
+
for (const gitDir of yield* submoduleGitDirs(git, record.repositoryPath, settings.nestedSubmodules)) {
|
|
400
|
+
const file = path.join(gitDir, "config");
|
|
401
|
+
yield* unsetPresent(git, record.repositoryPath, file, [key]);
|
|
402
|
+
if (Option.isSome(record.credentialsFile)) for (const entry of includeIfKeys({
|
|
403
|
+
gitDir,
|
|
404
|
+
workspace,
|
|
405
|
+
credentialsFile: record.credentialsFile.value,
|
|
406
|
+
worktrees: false
|
|
407
|
+
})) yield* git.configSet(record.repositoryPath, entry.key, entry.value, { file });
|
|
408
|
+
if (Option.isSome(record.sshKeyPath) && Option.isSome(record.knownHostsPath)) {
|
|
409
|
+
const command = sshCommand(yield* resolveSsh(env), record.sshKeyPath.value, record.knownHostsPath.value, sshStrict(settings), "persisted");
|
|
410
|
+
yield* git.configSet(record.repositoryPath, SSH_COMMAND_KEY, command, { file });
|
|
411
|
+
} else for (const value of values) yield* git.configAdd(record.repositoryPath, key, value, { file });
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
/** Unsets every key in `keys` that `file` (or the local config) holds; absent keys are skipped. */
|
|
415
|
+
const unsetPresent = (git, cwd, file, keys) => Effect.gen(function* () {
|
|
416
|
+
const entries = yield* git.configList(cwd, file === void 0 ? { scope: "local" } : { file });
|
|
417
|
+
const present = new Set(entries.map((entry) => entry.key.toLowerCase()));
|
|
418
|
+
for (const key of keys) if (present.has(key.toLowerCase())) yield* git.configUnset(cwd, key, {
|
|
419
|
+
...file === void 0 ? {} : { file },
|
|
420
|
+
all: true
|
|
421
|
+
});
|
|
422
|
+
});
|
|
423
|
+
/**
|
|
424
|
+
* Removes the `includeIf.gitdir:` values naming a `git-credentials-<uuid>.config`
|
|
425
|
+
* file from one config, keeping any other value of the same key, and returns
|
|
426
|
+
* the files they named.
|
|
427
|
+
*/
|
|
428
|
+
const removeIncludeIfCredentials = (git, cwd, file) => Effect.gen(function* () {
|
|
429
|
+
const target = file === void 0 ? {} : { file };
|
|
430
|
+
const entries = yield* git.configList(cwd, file === void 0 ? { scope: "local" } : { file });
|
|
431
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
432
|
+
for (const entry of entries) {
|
|
433
|
+
const lower = entry.key.toLowerCase();
|
|
434
|
+
if (!lower.startsWith("includeif.gitdir:") || !lower.endsWith(".path")) continue;
|
|
435
|
+
byKey.set(entry.key, [...byKey.get(entry.key) ?? [], entry.value]);
|
|
436
|
+
}
|
|
437
|
+
const found = [];
|
|
438
|
+
for (const [key, values] of byKey) {
|
|
439
|
+
const matching = values.filter((value) => CREDENTIALS_FILE.test(value));
|
|
440
|
+
if (matching.length === 0) continue;
|
|
441
|
+
found.push(...matching);
|
|
442
|
+
yield* git.configUnset(cwd, key, {
|
|
443
|
+
...target,
|
|
444
|
+
all: true
|
|
445
|
+
});
|
|
446
|
+
for (const value of values.filter((value) => !CREDENTIALS_FILE.test(value))) yield* git.configAdd(cwd, key, value, target);
|
|
447
|
+
}
|
|
448
|
+
return found;
|
|
449
|
+
});
|
|
450
|
+
/** Runs one removal step; a failure logs a warning and the removal continues. */
|
|
451
|
+
const bestEffort = (description, effect) => Effect.catch(effect, (error) => Effect.logWarning(`Failed to remove ${description}: ${error instanceof Error ? error.message : String(error)}`));
|
|
452
|
+
/**
|
|
453
|
+
* Whether `candidate` lies strictly inside `root`, both resolved first, so
|
|
454
|
+
* neither a sibling sharing the prefix (`<root>-other`) nor a `..` escape
|
|
455
|
+
* passes. `root` itself does not pass: nothing here may delete `RUNNER_TEMP`.
|
|
456
|
+
*/
|
|
457
|
+
const strictlyInside = (path, root, candidate) => {
|
|
458
|
+
const base = path.resolve(root);
|
|
459
|
+
const target = path.resolve(candidate);
|
|
460
|
+
return target !== base && target.startsWith(base.endsWith(path.sep) ? base : base + path.sep);
|
|
461
|
+
};
|
|
462
|
+
/**
|
|
463
|
+
* Removes one file under `RUNNER_TEMP`, best-effort; a path outside it, or no
|
|
464
|
+
* `RUNNER_TEMP`, is skipped with a debug line.
|
|
465
|
+
*/
|
|
466
|
+
const removeUnderTemp = (runnerTemp, description, target, options) => Effect.gen(function* () {
|
|
467
|
+
const fs = yield* FileSystem.FileSystem;
|
|
468
|
+
const path = yield* Path.Path;
|
|
469
|
+
if (Option.isNone(runnerTemp) || !strictlyInside(path, runnerTemp.value, target)) {
|
|
470
|
+
yield* Effect.logDebug(`Skipping removal of ${description} '${target}' - not under RUNNER_TEMP`);
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
yield* Effect.logInfo(`Removing ${description} '${target}'`);
|
|
474
|
+
yield* bestEffort(`${description} '${target}'`, fs.remove(target, {
|
|
475
|
+
force: true,
|
|
476
|
+
...options?.recursive ? { recursive: true } : {}
|
|
477
|
+
}));
|
|
478
|
+
});
|
|
479
|
+
/**
|
|
480
|
+
* The removal itself, run with whatever global config the caller has in
|
|
481
|
+
* force: every git step of {@link remove} and of {@link configure}'s
|
|
482
|
+
* pre-cleanup, which supplies its own temporary global config. Leaves the
|
|
483
|
+
* temporary global config alone.
|
|
484
|
+
*/
|
|
485
|
+
const removeLayout = (record, git) => Effect.gen(function* () {
|
|
486
|
+
const env = yield* ActionEnvironment;
|
|
487
|
+
const path = yield* Path.Path;
|
|
488
|
+
const runnerTemp = yield* env.getOptional("RUNNER_TEMP");
|
|
489
|
+
const repo = record.repositoryPath;
|
|
490
|
+
const configKeys = [SSH_COMMAND_KEY, extraheaderKey(record.origin)];
|
|
491
|
+
if (Option.isSome(record.sshKeyPath)) yield* removeUnderTemp(runnerTemp, "SSH key", record.sshKeyPath.value);
|
|
492
|
+
if (Option.isSome(record.knownHostsPath)) yield* removeUnderTemp(runnerTemp, "SSH known hosts", record.knownHostsPath.value);
|
|
493
|
+
const credentialFiles = new Set(Option.toArray(record.credentialsFile));
|
|
494
|
+
const collect = (cwd, file) => Effect.map(removeIncludeIfCredentials(git, cwd, file), (found) => {
|
|
495
|
+
for (const value of found) credentialFiles.add(value);
|
|
496
|
+
});
|
|
497
|
+
yield* bestEffort("the repository's credential config", unsetPresent(git, repo, void 0, configKeys));
|
|
498
|
+
yield* bestEffort("the repository's includeIf entries", collect(repo, void 0));
|
|
499
|
+
const gitDirs = yield* submoduleGitDirs(git, repo, true).pipe(Effect.catch((error) => Effect.as(Effect.logWarning(`Failed to list submodules: ${error.message}`), [])));
|
|
500
|
+
for (const gitDir of gitDirs) {
|
|
501
|
+
const file = path.join(gitDir, "config");
|
|
502
|
+
yield* bestEffort(`the credential config of '${gitDir}'`, unsetPresent(git, repo, file, [...configKeys, insteadOfKey(record.origin)]));
|
|
503
|
+
yield* bestEffort(`the includeIf entries of '${gitDir}'`, collect(repo, file));
|
|
504
|
+
}
|
|
505
|
+
for (const file of credentialFiles) yield* removeUnderTemp(runnerTemp, "credentials config", file);
|
|
506
|
+
});
|
|
507
|
+
/**
|
|
508
|
+
* Removes everything {@link configure}, {@link configureGlobalAuth} and
|
|
509
|
+
* {@link configureSubmodules} wrote, as checkout's `removeAuth` does.
|
|
510
|
+
*
|
|
511
|
+
* @remarks
|
|
512
|
+
* The SSH files; `core.sshCommand`, the extraheader and the `includeIf.gitdir:`
|
|
513
|
+
* values naming a `git-credentials-<uuid>.config` file, in the repository and
|
|
514
|
+
* every submodule, recursively; the submodules' `insteadOf` values, which
|
|
515
|
+
* checkout leaves behind; each named credentials file; and the temporary
|
|
516
|
+
* global config's directory. A file is deleted only when it resolves strictly
|
|
517
|
+
* inside `RUNNER_TEMP`.
|
|
518
|
+
*
|
|
519
|
+
* Every git step runs with `GIT_CONFIG_GLOBAL` set: the record's temporary
|
|
520
|
+
* global config when it still has one, otherwise (when the record marked the
|
|
521
|
+
* repository a `safe.directory`) a fresh one holding `safe.directory`, deleted
|
|
522
|
+
* afterwards, as checkout's post step does, so a repository owned by another
|
|
523
|
+
* user (a container job) is still cleaned. Best-effort throughout: each
|
|
524
|
+
* failure logs a warning and the rest still runs, so this never fails. A
|
|
525
|
+
* repository whose `.git/config` is gone runs no git at all, as checkout's post
|
|
526
|
+
* step returns early: only the files under `RUNNER_TEMP` are deleted.
|
|
527
|
+
*
|
|
528
|
+
* @internal
|
|
529
|
+
*/
|
|
530
|
+
const remove = (record, git) => Effect.gen(function* () {
|
|
531
|
+
const env = yield* ActionEnvironment;
|
|
532
|
+
const fs = yield* FileSystem.FileSystem;
|
|
533
|
+
const path = yield* Path.Path;
|
|
534
|
+
const runnerTemp = yield* env.getOptional("RUNNER_TEMP");
|
|
535
|
+
const repositoryConfig = path.join(record.repositoryPath, ".git", "config");
|
|
536
|
+
if (!(yield* fs.exists(repositoryConfig).pipe(Effect.orElseSucceed(() => false)))) {
|
|
537
|
+
yield* Effect.logDebug(`Skipping the git cleanup: '${repositoryConfig}' does not exist`);
|
|
538
|
+
for (const [description, file] of [
|
|
539
|
+
["SSH key", record.sshKeyPath],
|
|
540
|
+
["SSH known hosts", record.knownHostsPath],
|
|
541
|
+
["credentials config", record.credentialsFile]
|
|
542
|
+
]) if (Option.isSome(file)) yield* removeUnderTemp(runnerTemp, description, file.value);
|
|
543
|
+
for (const file of Option.toArray(record.temporaryGlobalConfig)) yield* removeUnderTemp(runnerTemp, "temporary global config", path.dirname(file), { recursive: true });
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
let globalConfig = record.temporaryGlobalConfig;
|
|
547
|
+
let fresh = Option.none();
|
|
548
|
+
if (Option.isNone(globalConfig) && record.safeDirectory && Option.isSome(runnerTemp)) {
|
|
549
|
+
fresh = yield* Effect.gen(function* () {
|
|
550
|
+
const file = yield* temporaryGlobalConfig(yield* homeDirectory(env), runnerTemp.value);
|
|
551
|
+
yield* git.configAdd(path.dirname(file), "safe.directory", record.repositoryPath, { file }).pipe(Effect.tapError(() => removeUnderTemp(runnerTemp, "temporary global config", path.dirname(file), { recursive: true })));
|
|
552
|
+
return file;
|
|
553
|
+
}).pipe(Effect.map(Option.some), Effect.catch((error) => Effect.as(Effect.logWarning(`Failed to create a temporary global config for safe.directory: ${error.message}`), Option.none())));
|
|
554
|
+
globalConfig = fresh;
|
|
555
|
+
}
|
|
556
|
+
yield* Option.match(globalConfig, {
|
|
557
|
+
onNone: () => removeLayout(record, git),
|
|
558
|
+
onSome: (file) => Git.withRunOptions(removeLayout(record, git), { env: { GIT_CONFIG_GLOBAL: file } })
|
|
559
|
+
});
|
|
560
|
+
for (const file of [...Option.toArray(record.temporaryGlobalConfig), ...Option.toArray(fresh)]) yield* removeUnderTemp(runnerTemp, "temporary global config", path.dirname(file), { recursive: true });
|
|
561
|
+
});
|
|
562
|
+
|
|
563
|
+
export { CredentialRecord, configure, configureGlobalAuth, configureSubmodules, includeIfKeys, prepareGlobalConfig, remove, temporaryGlobalConfig };
|