@effected/github-actions 0.35.0 → 0.36.1
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 +3 -2
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
import { Git, GitVersion, UnknownRefError } from "@effected/git";
|
|
2
|
+
import { GitHubClient } from "@effected/github";
|
|
3
|
+
import { Cause, Context, Duration, Effect, FileSystem, Option, Path, Random, Redacted, Schedule, Schema } from "effect";
|
|
4
|
+
import { Base64 } from "effect/encoding";
|
|
5
|
+
import { ActionEnvironment } from "../../ActionEnvironment.js";
|
|
6
|
+
import { ActionLogger } from "../../ActionLogger.js";
|
|
7
|
+
import { ActionState } from "../../ActionState.js";
|
|
8
|
+
import { CheckoutAuthError, CheckoutCommitMismatchError, CheckoutDefaultBranchError, CheckoutGitTooOldError, CheckoutRefNotFoundError, CheckoutResult, CheckoutStateKeyInUseError } from "../../Checkout.js";
|
|
9
|
+
import { Secret } from "../../Secret.js";
|
|
10
|
+
import { CredentialRecord, configure, configureGlobalAuth, configureSubmodules, prepareGlobalConfig, remove } from "./credentials.js";
|
|
11
|
+
import { ensureDirectory, prepareExistingDirectory } from "./directory.js";
|
|
12
|
+
import { checkoutInfo, fetchUrl, refSpec, refSpecForAllHistory, testRef } from "./refs.js";
|
|
13
|
+
import { lower } from "./settings.js";
|
|
14
|
+
|
|
15
|
+
// src/internal/checkout/source.ts
|
|
16
|
+
/**
|
|
17
|
+
* The retry policy of a checkout's network steps: 3 attempts, a random 10–20
|
|
18
|
+
* second delay between them, as checkout's `retry-helper` does.
|
|
19
|
+
*
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
const CheckoutRetry = Context.Reference("@effected/github-actions/CheckoutRetry", { defaultValue: () => Schedule.recurs(2).pipe(Schedule.modifyDelay(() => Effect.map(Random.nextIntBetween(10, 20), (seconds) => Duration.seconds(seconds)))) });
|
|
23
|
+
/**
|
|
24
|
+
* Builds the API client a checkout uses from its own token and API base: a
|
|
25
|
+
* live {@link GitHubClient.layerFromToken} client by default; a test replaces
|
|
26
|
+
* it to stay off the network.
|
|
27
|
+
*
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
const CheckoutApiClient = Context.Reference("@effected/github-actions/CheckoutApiClient", { defaultValue: () => (options) => Effect.provide(Effect.gen(function* () {
|
|
31
|
+
return yield* GitHubClient;
|
|
32
|
+
}), GitHubClient.layerFromToken(options)) });
|
|
33
|
+
/** The oldest git a checkout runs on. */
|
|
34
|
+
const MINIMUM_GIT = new GitVersion({
|
|
35
|
+
major: 2,
|
|
36
|
+
minor: 39,
|
|
37
|
+
patch: 0
|
|
38
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* The ceiling of every git spawn a checkout makes: a fetch of a real repository's full history is slow, and so is a
|
|
41
|
+
* checkout after a partial-clone fetch, a sparse set on a partial clone, an LFS smudge, or a clean of a big tree.
|
|
42
|
+
*/
|
|
43
|
+
const NETWORK_TIMEOUT = "30 minutes";
|
|
44
|
+
/** git's hints, silenced for every run so they reach neither the log nor the transcript. */
|
|
45
|
+
const QUIET_CONFIG = {
|
|
46
|
+
"advice.defaultBranchName": "false",
|
|
47
|
+
"advice.detachedHead": "false",
|
|
48
|
+
"advice.ignoredHook": "false"
|
|
49
|
+
};
|
|
50
|
+
/** stderr phrases git and ssh use when the remote refused the credentials. */
|
|
51
|
+
const AUTH_FAILURES = [
|
|
52
|
+
"Authentication failed",
|
|
53
|
+
"could not read Username",
|
|
54
|
+
"Permission denied (publickey)",
|
|
55
|
+
"terminal prompts disabled"
|
|
56
|
+
];
|
|
57
|
+
/**
|
|
58
|
+
* The state keys `"job"` checkouts saved, per `ActionState` service (one per action run), each with the path whose
|
|
59
|
+
* credentials it records. The runner keeps one value per key, so a second checkout of another path under the same key
|
|
60
|
+
* would leave the first one's credentials behind at cleanup.
|
|
61
|
+
*/
|
|
62
|
+
const savedStateKeys = /* @__PURE__ */ new WeakMap();
|
|
63
|
+
const short = (sha) => sha.slice(0, 7);
|
|
64
|
+
/** A ref as a reader names it: `main` for `refs/heads/main`, `pull/40/merge` for `refs/pull/40/merge`. */
|
|
65
|
+
const displayRef = (ref) => ref.replace(/^refs\/(?:heads\/|tags\/)?/, "");
|
|
66
|
+
const firstLine = (text) => text.split(/\r\n|\r|\n/)[0] ?? "";
|
|
67
|
+
/** Whether a server is GitHub Enterprise Server, as checkout's `url-helper` decides it. */
|
|
68
|
+
const isGhes = (serverUrl) => {
|
|
69
|
+
const hostname = new URL(serverUrl).hostname.trimEnd().toUpperCase();
|
|
70
|
+
return hostname !== "GITHUB.COM" && !hostname.endsWith(".GHE.COM") && !hostname.endsWith(".LOCALHOST");
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* The REST API root for a server, as checkout's `getServerApiUrl` derives it:
|
|
74
|
+
* the workflow's own `GITHUB_API_URL` for the workflow's server, otherwise
|
|
75
|
+
* `<origin>/api/v3` on GitHub Enterprise Server and `api.<host>` elsewhere.
|
|
76
|
+
*
|
|
77
|
+
* @internal
|
|
78
|
+
*/
|
|
79
|
+
const serverApiUrl = (serverUrl, workflow) => {
|
|
80
|
+
if (serverUrl.trim() === "" || serverUrl === workflow.serverUrl) return workflow.apiUrl || "https://api.github.com";
|
|
81
|
+
const url = new URL(serverUrl);
|
|
82
|
+
if (isGhes(serverUrl)) url.pathname = "api/v3";
|
|
83
|
+
else url.hostname = `api.${url.hostname}`;
|
|
84
|
+
const text = url.toString();
|
|
85
|
+
return text.endsWith("/") ? text.slice(0, -1) : text;
|
|
86
|
+
};
|
|
87
|
+
const tokenOf = (settings) => settings.auth._tag === "Token" ? Option.some(settings.auth.token) : Option.fromUndefinedOr(settings.auth.token);
|
|
88
|
+
/**
|
|
89
|
+
* The API client: one built from the checkout's own token against its own
|
|
90
|
+
* server's API base, as checkout always uses; the ambient one only when the
|
|
91
|
+
* checkout has no token.
|
|
92
|
+
*/
|
|
93
|
+
const apiClient = (settings, apiUrl) => {
|
|
94
|
+
const token = tokenOf(settings);
|
|
95
|
+
if (Option.isNone(token)) return Effect.serviceOption(GitHubClient);
|
|
96
|
+
return Effect.flatMap(CheckoutApiClient, (build) => Effect.map(build({
|
|
97
|
+
token: token.value,
|
|
98
|
+
baseUrl: apiUrl
|
|
99
|
+
}), Option.some));
|
|
100
|
+
};
|
|
101
|
+
/** Registers every secret with the runner's log filter before any git runs. */
|
|
102
|
+
const maskSecrets = (settings) => Effect.gen(function* () {
|
|
103
|
+
const token = tokenOf(settings);
|
|
104
|
+
if (Option.isSome(token)) {
|
|
105
|
+
const plaintext = yield* Secret.forRunnerFile(token.value);
|
|
106
|
+
yield* Secret.mask(Redacted.make(Base64.encode(`x-access-token:${plaintext}`)));
|
|
107
|
+
}
|
|
108
|
+
if (settings.auth._tag === "Ssh") yield* Secret.mask(settings.auth.key);
|
|
109
|
+
});
|
|
110
|
+
/**
|
|
111
|
+
* Retries an effect under {@link CheckoutRetry}. A pre-spawn refusal and a
|
|
112
|
+
* missing ref are never retried: neither changes on a second attempt.
|
|
113
|
+
*/
|
|
114
|
+
const retried = (effect) => Effect.gen(function* () {
|
|
115
|
+
const schedule = yield* CheckoutRetry;
|
|
116
|
+
return yield* Effect.retry(effect, {
|
|
117
|
+
schedule,
|
|
118
|
+
while: (error) => !(error instanceof CheckoutRefNotFoundError) && !(typeof error === "object" && error !== null && error.kind === "refused")
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
/** The repository's object format: from the pinned commit's length, else the API, else git's default. */
|
|
122
|
+
const objectFormat = (settings, client) => {
|
|
123
|
+
if (/^[0-9a-fA-F]{64}$/.test(settings.commit)) return Effect.succeed(Option.some("sha256"));
|
|
124
|
+
if (/^[0-9a-fA-F]{40}$/.test(settings.commit)) return Effect.succeed(Option.some("sha1"));
|
|
125
|
+
if (Option.isNone(client)) return Effect.succeed(Option.none());
|
|
126
|
+
return client.value.requestDecoded("GET /repos/{owner}/{repo}/hash-algorithm", {
|
|
127
|
+
owner: settings.owner,
|
|
128
|
+
repo: settings.name
|
|
129
|
+
}, Schema.Struct({ hash_algorithm: Schema.String })).pipe(Effect.map(({ hash_algorithm }) => hash_algorithm === "sha256" || hash_algorithm === "sha1" ? Option.some(hash_algorithm) : Option.none()), Effect.tap((format) => Option.isNone(format) ? Effect.logDebug("Unable to determine repository object format from hash-algorithm endpoint") : Effect.void), Effect.catch((error) => Effect.as(Effect.logDebug(`Unable to determine repository object format from hash-algorithm endpoint: ${error.message}`), Option.none())));
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* The default branch, `refs/heads/`-prefixed: `ls-remote` for an SSH key or a `remoteUrl`, the API otherwise, as checkout
|
|
133
|
+
* looks it up.
|
|
134
|
+
* A failure carries the reason, with `scrub` applied so the token never reaches it.
|
|
135
|
+
*/
|
|
136
|
+
const defaultBranch = (settings, git, client, scrub) => {
|
|
137
|
+
const repository = `${settings.owner}/${settings.name}`;
|
|
138
|
+
const failed = (detail) => new CheckoutDefaultBranchError({
|
|
139
|
+
repository,
|
|
140
|
+
detail: scrub(detail)
|
|
141
|
+
});
|
|
142
|
+
return (settings.auth._tag === "Ssh" || Option.isSome(settings.remoteUrl) ? Effect.flatMap(retried(git.remoteHead(settings.path, "origin")), (head) => Option.match(head, {
|
|
143
|
+
onNone: () => Effect.fail(failed("the remote names no HEAD")),
|
|
144
|
+
onSome: Effect.succeed
|
|
145
|
+
})) : Option.match(client, {
|
|
146
|
+
onNone: () => Effect.fail(failed("no GitHub API client to ask")),
|
|
147
|
+
onSome: (api) => retried(Effect.gen(function* () {
|
|
148
|
+
yield* Effect.logInfo("Retrieving the default branch name");
|
|
149
|
+
const name = yield* api.request("GET /repos/{owner}/{repo}", {
|
|
150
|
+
owner: settings.owner,
|
|
151
|
+
repo: settings.name
|
|
152
|
+
}).pipe(Effect.map((repo) => repo.default_branch), Effect.catch((error) => error.status === 404 && settings.name.toUpperCase().endsWith(".WIKI") ? Effect.succeed("master") : Effect.fail(error)));
|
|
153
|
+
if (!name) return yield* Effect.fail(failed("the API reported no default branch"));
|
|
154
|
+
return name;
|
|
155
|
+
}))
|
|
156
|
+
})).pipe(Effect.tap((name) => Effect.logInfo(`Default branch '${name}'`)), Effect.map((name) => name.startsWith("refs/") ? name : `refs/heads/${name}`), Effect.mapError((error) => error instanceof CheckoutDefaultBranchError ? error : failed(error instanceof Error ? error.message : String(error))));
|
|
157
|
+
};
|
|
158
|
+
/** Whether exactly `ref` exists locally. */
|
|
159
|
+
const refExists = (git, cwd, ref) => git.forEachRef(cwd, { patterns: [ref] }).pipe(Effect.map((entries) => entries.some((entry) => entry.ref === ref)), Effect.orElseSucceed(() => false));
|
|
160
|
+
/** The lookups `checkoutInfo` and `testRef` ask of the repository. */
|
|
161
|
+
const lookups = (git, cwd) => ({
|
|
162
|
+
branchExists: (remoteName) => refExists(git, cwd, `refs/remotes/${remoteName}`),
|
|
163
|
+
tagExists: (name) => refExists(git, cwd, `refs/tags/${name}`),
|
|
164
|
+
shaExists: (sha) => git.refExists(cwd, `${sha}^{object}`).pipe(Effect.orElseSucceed(() => false)),
|
|
165
|
+
revParse: (ref) => git.revParse(cwd, ref).pipe(Effect.orElseSucceed(() => ""))
|
|
166
|
+
});
|
|
167
|
+
/**
|
|
168
|
+
* A fetch failure in checkout's terms: a missing ref, or refused credentials.
|
|
169
|
+
*
|
|
170
|
+
* @remarks
|
|
171
|
+
* `ref` is the ref being fetched, after default-branch resolution, so a missing
|
|
172
|
+
* default branch is named rather than reported as `""`. A shallow fetch whose
|
|
173
|
+
* refspecs are all globs (an unqualified ref) and match nothing exits 1 with no
|
|
174
|
+
* output at all; that silence is a missing ref too.
|
|
175
|
+
*/
|
|
176
|
+
const classifyFetch = (settings, ref, refspecs) => (error) => {
|
|
177
|
+
if (error instanceof UnknownRefError) return new CheckoutRefNotFoundError({ ref });
|
|
178
|
+
const tagged = error;
|
|
179
|
+
if (tagged._tag === "GitCommandError" && typeof tagged.stderr === "string") {
|
|
180
|
+
const stderr = tagged.stderr;
|
|
181
|
+
if (tagged.exitCode === 1 && stderr.trim() === "" && refspecs.every((spec) => spec.includes("*"))) return new CheckoutRefNotFoundError({ ref });
|
|
182
|
+
const match = AUTH_FAILURES.find((phrase) => stderr.includes(phrase));
|
|
183
|
+
if (match !== void 0) return new CheckoutAuthError({
|
|
184
|
+
repository: `${settings.owner}/${settings.name}`,
|
|
185
|
+
detail: match
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
return error;
|
|
189
|
+
};
|
|
190
|
+
/** The fetch step's red line. */
|
|
191
|
+
const fetchFailure = (cause) => {
|
|
192
|
+
const error = Option.getOrUndefined(Cause.findErrorOption(cause));
|
|
193
|
+
if (error instanceof CheckoutRefNotFoundError) return `fetch failed · branch or tag '${displayRef(error.ref)}' not found`;
|
|
194
|
+
if (error instanceof CheckoutCommitMismatchError) return `fetch failed · ref moved past ${short(error.expected)}`;
|
|
195
|
+
if (error instanceof CheckoutAuthError) return "fetch failed · authentication refused";
|
|
196
|
+
const squashed = Cause.squash(cause);
|
|
197
|
+
return `fetch failed · ${firstLine(squashed instanceof Error ? squashed.message : String(squashed))}`;
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* Checks a repository out the way checkout v7's `getSource` does, one step per
|
|
201
|
+
* phase of work under one phase heading.
|
|
202
|
+
*
|
|
203
|
+
* @internal
|
|
204
|
+
*/
|
|
205
|
+
const getSource = (options) => Effect.gen(function* () {
|
|
206
|
+
const env = yield* ActionEnvironment;
|
|
207
|
+
const git = yield* Git;
|
|
208
|
+
const logger = yield* ActionLogger;
|
|
209
|
+
const state = yield* ActionState;
|
|
210
|
+
const fs = yield* FileSystem.FileSystem;
|
|
211
|
+
const path = yield* Path.Path;
|
|
212
|
+
const github = yield* env.github;
|
|
213
|
+
const workspace = yield* env.get("GITHUB_WORKSPACE");
|
|
214
|
+
const payload = github.eventName === "pull_request_target" || github.eventName === "workflow_run" ? yield* env.payload : yield* env.payload.pipe(Effect.orElseSucceed(() => ({})));
|
|
215
|
+
const settings = yield* lower(options, {
|
|
216
|
+
github,
|
|
217
|
+
workspace,
|
|
218
|
+
payload
|
|
219
|
+
});
|
|
220
|
+
if (settings.credentials === "job") {
|
|
221
|
+
const recorded = savedStateKeys.get(state)?.get(settings.stateKey);
|
|
222
|
+
if (recorded !== void 0 && recorded !== settings.path) return yield* new CheckoutStateKeyInUseError({
|
|
223
|
+
stateKey: settings.stateKey,
|
|
224
|
+
path: recorded
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
const repositoryUrl = Option.getOrElse(settings.remoteUrl, () => fetchUrl(settings));
|
|
228
|
+
const client = yield* apiClient(settings, serverApiUrl(settings.serverUrl, github));
|
|
229
|
+
const token = tokenOf(settings);
|
|
230
|
+
const plaintext = Option.isSome(token) ? yield* Secret.forRunnerFile(token.value) : "";
|
|
231
|
+
/** Removes the token from text bound for an error. */
|
|
232
|
+
const scrub = (text) => plaintext === "" ? text : text.replaceAll(plaintext, "***");
|
|
233
|
+
const target = settings.ref ? displayRef(settings.ref) : settings.commit ? short(settings.commit) : "default branch";
|
|
234
|
+
/** The run environment so far: `GIT_CONFIG_GLOBAL` once it exists, `GIT_SSH_COMMAND` once configured. */
|
|
235
|
+
let runEnv = {};
|
|
236
|
+
const withRun = (effect) => Effect.suspend(() => Git.withRunOptions(effect, { env: { ...runEnv } }));
|
|
237
|
+
let temporaryConfig = Option.none();
|
|
238
|
+
/** What removal removes, set once the credentials are written. */
|
|
239
|
+
let credentials = Option.none();
|
|
240
|
+
const discardGlobalConfig = Effect.suspend(() => Option.match(temporaryConfig, {
|
|
241
|
+
onNone: () => Effect.void,
|
|
242
|
+
onSome: (file) => fs.remove(path.dirname(file), {
|
|
243
|
+
recursive: true,
|
|
244
|
+
force: true
|
|
245
|
+
}).pipe(Effect.ignore)
|
|
246
|
+
}));
|
|
247
|
+
const removeCredentials = Effect.suspend(() => Option.match(credentials, {
|
|
248
|
+
onNone: () => Effect.void,
|
|
249
|
+
onSome: (record) => logger.step("credentials removed", remove(record, git), { window: "10 seconds" })
|
|
250
|
+
}));
|
|
251
|
+
if (settings.credentials === "action") yield* Effect.addFinalizer(() => removeCredentials);
|
|
252
|
+
const prepare = Effect.gen(function* () {
|
|
253
|
+
const existing = yield* ensureDirectory(settings.path);
|
|
254
|
+
const version = yield* git.version(settings.path);
|
|
255
|
+
if (!GitVersion.atLeast(version, MINIMUM_GIT)) return yield* new CheckoutGitTooOldError({
|
|
256
|
+
found: version.toString(),
|
|
257
|
+
required: MINIMUM_GIT.toString()
|
|
258
|
+
});
|
|
259
|
+
if (settings.safeDirectory || settings.submodules) yield* Effect.uninterruptible(Effect.tap(prepareGlobalConfig(settings, git), (file) => Effect.sync(() => {
|
|
260
|
+
temporaryConfig = Option.some(file);
|
|
261
|
+
runEnv = {
|
|
262
|
+
...runEnv,
|
|
263
|
+
GIT_CONFIG_GLOBAL: file
|
|
264
|
+
};
|
|
265
|
+
})));
|
|
266
|
+
return yield* withRun(Effect.gen(function* () {
|
|
267
|
+
const prepared = existing ? yield* prepareExistingDirectory(git, settings.path, repositoryUrl, settings.clean, settings.ref) : {
|
|
268
|
+
reused: false,
|
|
269
|
+
cleaned: false
|
|
270
|
+
};
|
|
271
|
+
if (!(yield* fs.exists(path.join(settings.path, ".git")))) {
|
|
272
|
+
const format = yield* objectFormat(settings, client);
|
|
273
|
+
if (Option.contains(format, "sha256")) yield* Effect.logInfo("Detected SHA-256 repository object format");
|
|
274
|
+
yield* git.init(settings.path, settings.path, Option.match(format, {
|
|
275
|
+
onNone: () => ({}),
|
|
276
|
+
onSome: (objectFormat) => ({ objectFormat })
|
|
277
|
+
}));
|
|
278
|
+
yield* git.remoteAdd(settings.path, "origin", repositoryUrl);
|
|
279
|
+
}
|
|
280
|
+
yield* git.configSet(settings.path, "gc.auto", "0").pipe(Effect.catch(() => Effect.logWarning("Unable to turn off git automatic garbage collection. The git fetch operation may trigger garbage collection and cause a delay.")));
|
|
281
|
+
const written = yield* Effect.uninterruptible(Effect.gen(function* () {
|
|
282
|
+
const configured = yield* configure(settings, git, Option.isSome(temporaryConfig) ? { temporaryGlobalConfig: temporaryConfig.value } : void 0);
|
|
283
|
+
const lasting = CredentialRecord.make({
|
|
284
|
+
...configured.record,
|
|
285
|
+
temporaryGlobalConfig: Option.none()
|
|
286
|
+
});
|
|
287
|
+
if (settings.credentials === "job") {
|
|
288
|
+
yield* state.save(settings.stateKey, lasting, CredentialRecord).pipe(Effect.onError(() => remove(configured.record, git)));
|
|
289
|
+
const keys = savedStateKeys.get(state) ?? /* @__PURE__ */ new Map();
|
|
290
|
+
savedStateKeys.set(state, keys.set(settings.stateKey, settings.path));
|
|
291
|
+
}
|
|
292
|
+
credentials = Option.some(settings.credentials === "none" ? configured.record : lasting);
|
|
293
|
+
return configured;
|
|
294
|
+
}));
|
|
295
|
+
runEnv = {
|
|
296
|
+
...runEnv,
|
|
297
|
+
...written.runEnv
|
|
298
|
+
};
|
|
299
|
+
return {
|
|
300
|
+
version,
|
|
301
|
+
prepared,
|
|
302
|
+
record: written.record
|
|
303
|
+
};
|
|
304
|
+
}));
|
|
305
|
+
});
|
|
306
|
+
/** Fetches `refspecs` for `ref`, the resolved ref every failure names. */
|
|
307
|
+
const fetch = (ref, refspecs, filter) => Effect.gen(function* () {
|
|
308
|
+
const shallow = yield* fs.exists(path.join(settings.path, ".git", "shallow"));
|
|
309
|
+
yield* retried(git.fetchRefspecs(settings.path, {
|
|
310
|
+
refspecs,
|
|
311
|
+
...settings.depth > 0 ? { depth: settings.depth } : shallow ? { unshallow: true } : {},
|
|
312
|
+
...Option.isSome(filter) ? { filter: filter.value } : {},
|
|
313
|
+
noTags: true,
|
|
314
|
+
prune: true,
|
|
315
|
+
noRecurseSubmodules: true,
|
|
316
|
+
protocolVersion: 2
|
|
317
|
+
}).pipe(Effect.mapError(classifyFetch(settings, ref, refspecs))));
|
|
318
|
+
});
|
|
319
|
+
const fetchRef = withRun(Effect.gen(function* () {
|
|
320
|
+
const ref = !settings.ref && !settings.commit ? yield* defaultBranch(settings, git, client, scrub) : settings.ref;
|
|
321
|
+
const commit = settings.commit;
|
|
322
|
+
if (settings.lfs) yield* git.lfsInstall(settings.path, { local: true });
|
|
323
|
+
const filter = Option.isSome(settings.filter) ? settings.filter : Option.isSome(settings.sparse) ? Option.some("blob:none") : Option.none();
|
|
324
|
+
const lookup = lookups(git, settings.path);
|
|
325
|
+
const mismatch = () => new CheckoutCommitMismatchError({
|
|
326
|
+
ref,
|
|
327
|
+
expected: commit
|
|
328
|
+
});
|
|
329
|
+
if (settings.depth <= 0) {
|
|
330
|
+
yield* fetch(ref, refSpecForAllHistory(ref, commit), filter);
|
|
331
|
+
if (!(yield* testRef(lookup, ref, commit))) {
|
|
332
|
+
yield* fetch(ref, refSpec(ref, commit, false), filter);
|
|
333
|
+
if (!(yield* testRef(lookup, ref, commit))) return yield* mismatch();
|
|
334
|
+
}
|
|
335
|
+
} else {
|
|
336
|
+
yield* fetch(ref, refSpec(ref, commit, settings.fetchTags), filter);
|
|
337
|
+
if (!(yield* testRef(lookup, ref, commit))) return yield* mismatch();
|
|
338
|
+
}
|
|
339
|
+
const info = yield* checkoutInfo(lookup, ref, commit);
|
|
340
|
+
return {
|
|
341
|
+
ref,
|
|
342
|
+
info,
|
|
343
|
+
fetched: yield* git.revParse(settings.path, `${Option.getOrElse(info.startPoint, () => info.ref)}^{commit}`)
|
|
344
|
+
};
|
|
345
|
+
}));
|
|
346
|
+
const checkoutRef = (info) => withRun(Effect.gen(function* () {
|
|
347
|
+
if (Option.isSome(settings.sparse)) yield* git.sparseCheckoutSet(settings.path, settings.sparse.value.patterns, { cone: settings.sparse.value.cone });
|
|
348
|
+
else yield* git.sparseCheckoutDisable(settings.path);
|
|
349
|
+
if (Option.isSome(info.startPoint)) yield* git.checkout(settings.path, info.startPoint.value, {
|
|
350
|
+
force: true,
|
|
351
|
+
branch: info.ref
|
|
352
|
+
});
|
|
353
|
+
else yield* git.checkout(settings.path, info.ref, { force: true });
|
|
354
|
+
return {
|
|
355
|
+
commit: yield* git.revParse(settings.path, "HEAD"),
|
|
356
|
+
subject: firstLine((yield* git.commitInfo(settings.path, "HEAD")).message),
|
|
357
|
+
branch: Option.map(info.startPoint, () => info.ref)
|
|
358
|
+
};
|
|
359
|
+
}));
|
|
360
|
+
const updateSubmodules = (record) => withRun(Effect.gen(function* () {
|
|
361
|
+
const recursive = settings.nestedSubmodules;
|
|
362
|
+
yield* configureGlobalAuth(settings, record, git);
|
|
363
|
+
yield* git.submoduleSync(settings.path, { recursive });
|
|
364
|
+
yield* git.submoduleUpdate(settings.path, {
|
|
365
|
+
init: true,
|
|
366
|
+
force: true,
|
|
367
|
+
...settings.depth > 0 ? { depth: settings.depth } : {},
|
|
368
|
+
recursive,
|
|
369
|
+
protocolVersion: 2
|
|
370
|
+
});
|
|
371
|
+
yield* git.submoduleForeach(settings.path, "git config --local gc.auto 0", { recursive });
|
|
372
|
+
yield* configureSubmodules(settings, record, git);
|
|
373
|
+
return (yield* git.submoduleStatus(settings.path, { recursive })).length;
|
|
374
|
+
}));
|
|
375
|
+
const sequence = Effect.gen(function* () {
|
|
376
|
+
const setup = yield* logger.step("prepare", prepare, {
|
|
377
|
+
window: "10 seconds",
|
|
378
|
+
summary: ({ version, prepared }) => `git ${version} · ${prepared.reused ? prepared.cleaned ? "reused, cleaned" : "reused" : "fresh clone"}`
|
|
379
|
+
});
|
|
380
|
+
const fetched = yield* logger.step("fetch", fetchRef, {
|
|
381
|
+
window: "2 minutes",
|
|
382
|
+
summary: ({ fetched }) => `fetched ${short(fetched)} · ${settings.depth > 0 ? `depth ${settings.depth}` : "full history"}`,
|
|
383
|
+
failure: fetchFailure
|
|
384
|
+
});
|
|
385
|
+
if (settings.lfs && Option.isNone(settings.sparse)) yield* logger.step("lfs", withRun(retried(git.lfsFetch(settings.path, { ref: Option.getOrElse(fetched.info.startPoint, () => fetched.info.ref) }))), {
|
|
386
|
+
window: "2 minutes",
|
|
387
|
+
summary: () => "fetched LFS objects"
|
|
388
|
+
});
|
|
389
|
+
const checkedOut = yield* logger.step("checkout", checkoutRef(fetched.info), {
|
|
390
|
+
window: "10 seconds",
|
|
391
|
+
summary: ({ commit, subject, branch }) => `checked out ${short(commit)} (${Option.getOrElse(branch, () => "detached")}) "${subject}"`
|
|
392
|
+
});
|
|
393
|
+
if (settings.submodules) yield* logger.step("submodules", updateSubmodules(setup.record), {
|
|
394
|
+
window: "2 minutes",
|
|
395
|
+
summary: (count) => `${count} submodule${count === 1 ? "" : "s"} checked out`
|
|
396
|
+
});
|
|
397
|
+
if (settings.credentials === "job") yield* logger.step("credentials kept for the job", Effect.void);
|
|
398
|
+
else if (settings.credentials === "action") yield* logger.step("credentials removed when the action ends", Effect.void);
|
|
399
|
+
return CheckoutResult.make({
|
|
400
|
+
ref: fetched.ref,
|
|
401
|
+
commit: checkedOut.commit,
|
|
402
|
+
path: settings.path,
|
|
403
|
+
repository: {
|
|
404
|
+
owner: settings.owner,
|
|
405
|
+
name: settings.name
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
});
|
|
409
|
+
yield* maskSecrets(settings);
|
|
410
|
+
const body = settings.credentials === "none" ? Effect.ensuring(sequence, removeCredentials) : sequence;
|
|
411
|
+
return yield* logger.phase(`Checkout ${settings.owner}/${settings.name} @ ${target}`, Effect.ensuring(body, discardGlobalConfig));
|
|
412
|
+
}).pipe(Git.withRunOptions({
|
|
413
|
+
env: options.lfs === true ? {} : { GIT_LFS_SKIP_SMUDGE: "1" },
|
|
414
|
+
config: QUIET_CONFIG,
|
|
415
|
+
timeout: NETWORK_TIMEOUT
|
|
416
|
+
}));
|
|
417
|
+
|
|
418
|
+
export { CheckoutApiClient, CheckoutRetry, getSource, serverApiUrl };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { CheckoutUnsafePullRequestError } from "../../Checkout.js";
|
|
3
|
+
|
|
4
|
+
// src/internal/checkout/unsafePullRequest.ts
|
|
5
|
+
const PR_REF_PATTERN = /^refs\/pull\/[0-9]+\/(?:head|merge)$/;
|
|
6
|
+
/**
|
|
7
|
+
* Reads a dotted path out of an unknown JSON payload, tolerating any shape.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
const fromPayload = (payload, path) => {
|
|
12
|
+
let current = payload;
|
|
13
|
+
for (const key of path.split(".")) {
|
|
14
|
+
if (current === null || current === void 0 || typeof current !== "object") return;
|
|
15
|
+
current = current[key];
|
|
16
|
+
}
|
|
17
|
+
return current;
|
|
18
|
+
};
|
|
19
|
+
const pushIfSha = (target, value) => {
|
|
20
|
+
if (typeof value === "string" && value.length > 0) target.push(value.toLowerCase());
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Refuses to check out fork pull request code from a privileged event, as
|
|
24
|
+
* `assertSafePrCheckout` of the stock checkout action does.
|
|
25
|
+
*
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
const assertSafePullRequest = (input, event) => {
|
|
29
|
+
if (input.allowUnsafe) return Effect.void;
|
|
30
|
+
const eventName = event.name;
|
|
31
|
+
if (eventName !== "pull_request_target" && eventName !== "workflow_run") return Effect.void;
|
|
32
|
+
const baseRepoId = fromPayload(event.payload, "repository.id");
|
|
33
|
+
if (typeof baseRepoId !== "number") return Effect.void;
|
|
34
|
+
let prHeadRepoId;
|
|
35
|
+
let prHeadRepoFullName;
|
|
36
|
+
const prShas = [];
|
|
37
|
+
if (eventName === "pull_request_target") {
|
|
38
|
+
prHeadRepoId = fromPayload(event.payload, "pull_request.head.repo.id");
|
|
39
|
+
prHeadRepoFullName = fromPayload(event.payload, "pull_request.head.repo.full_name");
|
|
40
|
+
pushIfSha(prShas, fromPayload(event.payload, "pull_request.head.sha"));
|
|
41
|
+
pushIfSha(prShas, fromPayload(event.payload, "pull_request.merge_commit_sha"));
|
|
42
|
+
} else {
|
|
43
|
+
const wrEvent = fromPayload(event.payload, "workflow_run.event");
|
|
44
|
+
if (typeof wrEvent !== "string" || !wrEvent.startsWith("pull_request")) return Effect.void;
|
|
45
|
+
prHeadRepoId = fromPayload(event.payload, "workflow_run.head_repository.id");
|
|
46
|
+
prHeadRepoFullName = fromPayload(event.payload, "workflow_run.head_repository.full_name");
|
|
47
|
+
pushIfSha(prShas, fromPayload(event.payload, "workflow_run.head_commit.id"));
|
|
48
|
+
if (wrEvent !== "pull_request_target") pushIfSha(prShas, fromPayload(event.payload, "workflow_run.head_sha"));
|
|
49
|
+
}
|
|
50
|
+
if (prHeadRepoId === baseRepoId) return Effect.void;
|
|
51
|
+
const repositoryMatchesPrHead = typeof prHeadRepoFullName === "string" && input.repository.toLowerCase() === prHeadRepoFullName.toLowerCase();
|
|
52
|
+
const refMatchesPullPattern = PR_REF_PATTERN.test(input.ref);
|
|
53
|
+
const commitMatchesPrHeadSha = !!input.commit && prShas.includes(input.commit.toLowerCase());
|
|
54
|
+
if (!repositoryMatchesPrHead && !refMatchesPullPattern && !commitMatchesPrHeadSha) return Effect.void;
|
|
55
|
+
return Effect.fail(new CheckoutUnsafePullRequestError({
|
|
56
|
+
event: eventName,
|
|
57
|
+
repository: input.repository,
|
|
58
|
+
ref: input.ref
|
|
59
|
+
}));
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export { assertSafePullRequest, fromPayload };
|
package/internal/digest.js
CHANGED
package/internal/pnpmExe.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Option, Result } from "effect";
|
|
2
|
-
import * as Hex from "effect/encoding/Hex";
|
|
3
2
|
import * as Base64 from "effect/encoding/Base64";
|
|
3
|
+
import * as Hex from "effect/encoding/Hex";
|
|
4
4
|
|
|
5
5
|
// src/internal/pnpmExe.ts
|
|
6
6
|
/** The prefix every native-binary package name carries. @internal */
|