Skip to content

Commit e2670ac

Browse files
authored
Merge pull request #949 from ocaml/local-package-dir
Keep the build directory clean with the `--local-package-dir` argument
2 parents 928a230 + 5480d9a commit e2670ac

File tree

5 files changed

+13
-98
lines changed

5 files changed

+13
-98
lines changed

dist/index.js

+4-40
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/post/index.js

+3-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/setup-ocaml/src/cache.ts

+2-11
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import * as system from "systeminformation";
99
import {
1010
ARCHITECTURE,
1111
CACHE_PREFIX,
12-
CYGWIN_MIRROR_ENCODED_URI,
1312
CYGWIN_ROOT,
1413
DUNE_CACHE_ROOT,
1514
GITHUB_WORKSPACE,
@@ -24,7 +23,7 @@ import { cygwinVersion } from "./windows.js";
2423

2524
async function composeCygwinCacheKeys() {
2625
const version = await cygwinVersion;
27-
const key = `${CACHE_PREFIX}-setup-ocaml-cygwin-${CYGWIN_MIRROR_ENCODED_URI}-${version}`;
26+
const key = `${CACHE_PREFIX}-setup-ocaml-cygwin-${version}`;
2827
const restoreKeys = [key];
2928
return { key, restoreKeys };
3029
}
@@ -68,15 +67,7 @@ async function composeOpamCacheKeys() {
6867

6968
function composeCygwinCachePaths() {
7069
const cygwinRootSymlinkPath = path.posix.join("/cygdrive", "d", "cygwin");
71-
const cygwinLocalPackageDirectory = path.join(
72-
GITHUB_WORKSPACE,
73-
CYGWIN_MIRROR_ENCODED_URI,
74-
);
75-
const paths = [
76-
CYGWIN_ROOT,
77-
cygwinLocalPackageDirectory,
78-
cygwinRootSymlinkPath,
79-
];
70+
const paths = [CYGWIN_ROOT, cygwinRootSymlinkPath];
8071
return paths;
8172
}
8273

packages/setup-ocaml/src/constants.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,13 @@ export const CYGWIN_MIRROR = "https://mirrors.kernel.org/sourceware/cygwin/";
5858

5959
export const GITHUB_WORKSPACE = process.env.GITHUB_WORKSPACE ?? process.cwd();
6060

61-
export const CYGWIN_MIRROR_ENCODED_URI =
62-
encodeURIComponent(CYGWIN_MIRROR).toLowerCase();
63-
6461
// [HACK] https://github.com/ocaml/setup-ocaml/pull/55
6562
export const CYGWIN_ROOT = path.join("D:", "cygwin");
6663

6764
export const CYGWIN_ROOT_BIN = path.join(CYGWIN_ROOT, "bin");
6865

66+
export const CYGWIN_LOCAL_PACKAGE_DIR = path.join(CYGWIN_ROOT, "packages");
67+
6968
export const CYGWIN_BASH_ENV = path.join(CYGWIN_ROOT, "bash_env");
7069

7170
export const DUNE_CACHE_ROOT = (() => {

packages/setup-ocaml/src/windows.ts

+2-36
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import * as fs from "node:fs/promises";
2-
import * as os from "node:os";
3-
import * as path from "node:path";
41
import * as core from "@actions/core";
52
import { exec } from "@actions/exec";
63
import { HttpClient } from "@actions/http-client";
@@ -9,8 +6,8 @@ import * as toolCache from "@actions/tool-cache";
96
import * as cheerio from "cheerio";
107
import * as semver from "semver";
118
import {
9+
CYGWIN_LOCAL_PACKAGE_DIR,
1210
CYGWIN_MIRROR,
13-
CYGWIN_MIRROR_ENCODED_URI,
1411
CYGWIN_ROOT,
1512
} from "./constants.js";
1613

@@ -37,40 +34,8 @@ export const cygwinVersion = (async () => {
3734
return version;
3835
})();
3936

40-
async function setGitToIgnoreCygwinLocalPackageDirectory() {
41-
const xdgConfigHome = process.env.XDG_CONFIG_HOME;
42-
const homeDir = os.homedir();
43-
const globalGitConfigDir = xdgConfigHome
44-
? path.join(xdgConfigHome, "git")
45-
: path.join(homeDir, ".config", "git");
46-
await fs.mkdir(globalGitConfigDir, { recursive: true });
47-
const globalGitIgnorePath = path.join(globalGitConfigDir, "ignore");
48-
try {
49-
await fs.access(globalGitIgnorePath, fs.constants.R_OK);
50-
const contents = await fs.readFile(globalGitIgnorePath, {
51-
encoding: "utf8",
52-
});
53-
if (!contents.includes(CYGWIN_MIRROR_ENCODED_URI)) {
54-
await fs.appendFile(globalGitIgnorePath, CYGWIN_MIRROR_ENCODED_URI, {
55-
encoding: "utf8",
56-
});
57-
}
58-
} catch {
59-
await fs.writeFile(globalGitIgnorePath, CYGWIN_MIRROR_ENCODED_URI, {
60-
encoding: "utf8",
61-
});
62-
} finally {
63-
await exec(
64-
"git",
65-
["config", "--add", "--global", "core.excludesfile", globalGitIgnorePath],
66-
{ windowsVerbatimArguments: true },
67-
);
68-
}
69-
}
70-
7137
export async function setupCygwin() {
7238
await core.group("Setting up Cygwin environment", async () => {
73-
await setGitToIgnoreCygwinLocalPackageDirectory();
7439
const version = await cygwinVersion;
7540
const cachedPath = toolCache.find("cygwin", version, "x86_64");
7641
if (cachedPath === "") {
@@ -106,6 +71,7 @@ export async function setupCygwin() {
10671
"--quiet-mode",
10772
"--symlink-type=sys",
10873
"--upgrade-also",
74+
`--local-package-dir=${CYGWIN_LOCAL_PACKAGE_DIR}`,
10975
`--packages=${packages}`,
11076
`--root=${CYGWIN_ROOT}`,
11177
`--site=${CYGWIN_MIRROR}`,

0 commit comments

Comments
 (0)