|
1 | 1 | 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 | +} |
2 | 44 |
|
3 | 45 | async function run() { |
4 | 46 | const target_repo = core.getInput("repo"); |
5 | 47 | const target_branch = core.getInput("branch"); |
6 | 48 | const cf_token = core.getInput("token"); |
7 | 49 |
|
| 50 | + const docs_path = "documentation"; |
| 51 | + const pkg_path = "packages"; |
| 52 | + |
8 | 53 | if (target_branch !== "main" && target_branch !== "master") { |
9 | 54 | core.setFailed("Branch deploys are not yet supported."); |
10 | 55 | } |
11 | 56 |
|
12 | 57 | // 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 | + |
13 | 67 | // read docs in |
14 | 68 | // format them |
15 | 69 | // transform to cf format (batch keys) |
|
0 commit comments