Skip to content

Commit ba4ad5e

Browse files
committed
clone repo
1 parent f45f415 commit ba4ad5e

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"homepage": "https://github.com/sveltejs/action-deploy-docs#readme",
2222
"devDependencies": {
2323
"@actions/core": "^1.2.6",
24+
"@actions/exec": "^1.0.4",
2425
"@rollup/plugin-commonjs": "^17.1.0",
2526
"@rollup/plugin-node-resolve": "^11.2.0",
2627
"@sindresorhus/slugify": "^1.1.0",

pnpm-lock.yaml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,69 @@
11
import core from "@actions/core";
2+
import exec from "@actions/exec";
3+
import fs from "fs";
4+
import path from "path";
5+
6+
async function get_repo(
7+
target_repo: string,
8+
target_branch: string,
9+
docs_path: string,
10+
pkg_path: string
11+
): Promise<void> {
12+
const tmp_dir_name = `__tmp_repo_path`;
13+
14+
// we want to clone the necessary branch and only that branch
15+
// but we don't want files because we want to sparsely checkout the branch later
16+
// we also don't want any history, we only care about files
17+
// this is basically magic
18+
await exec.exec("git", [
19+
"clone",
20+
`https://github.com/sveltejs/${target_repo}.git`,
21+
"--no-checkout",
22+
"--branch",
23+
target_branch,
24+
"--single-branch",
25+
tmp_dir_name,
26+
"--depth",
27+
"1",
28+
"--verbose",
29+
]);
30+
31+
process.chdir(tmp_dir_name);
32+
33+
await exec.exec("git", ["sparse-checkout", "init"]);
34+
35+
// we only care about the documentation folder and any package readmes + package.jsons
36+
fs.writeFileSync(
37+
path.join(process.cwd(), ".git/info/sparse-checkout"),
38+
`/${docs_path}/\n/${pkg_path}/*/README.md\n/packages/*/package.json"`
39+
);
40+
41+
await exec.exec("git", ["sparse-checkout", "reapply"]);
42+
await exec.exec("git", ["switch", target_branch]);
43+
}
244

345
async function run() {
446
const target_repo = core.getInput("repo");
547
const target_branch = core.getInput("branch");
648
const cf_token = core.getInput("token");
749

50+
const docs_path = "documentation";
51+
const pkg_path = "packages";
52+
853
if (target_branch !== "main" && target_branch !== "master") {
954
core.setFailed("Branch deploys are not yet supported.");
1055
}
1156

1257
// get repo
58+
59+
try {
60+
await get_repo(target_repo, target_branch, docs_path, pkg_path);
61+
} catch (e) {
62+
core.setFailed(
63+
`Failed to clone repository: https://github.com/sveltejs/${target_repo}.git#${target_branch}`
64+
);
65+
}
66+
1367
// read docs in
1468
// format them
1569
// transform to cf format (batch keys)

0 commit comments

Comments
 (0)