Skip to content

Commit 08721db

Browse files
authored
Merge pull request #842 from ocaml/set-git-to-ignore-cygwin-local-package-directory
Set Git to ignore Cygwin local package directory
2 parents c43f397 + f9084f0 commit 08721db

File tree

6 files changed

+92
-39
lines changed

6 files changed

+92
-39
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ and this project adheres to
88

99
## [unreleased]
1010

11+
### Changed
12+
13+
- Set Git to ignore Cygwin local package directory.
14+
1115
## [3.0.4]
1216

1317
### Changed

dist/index.js

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

dist/post/index.js

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

packages/setup-ocaml/src/cache.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as crypto from "node:crypto";
22
import * as path from "node:path";
3-
import * as process from "node:process";
43
import * as cache from "@actions/cache";
54
import * as core from "@actions/core";
65
import { exec } from "@actions/exec";
@@ -9,9 +8,10 @@ import * as system from "systeminformation";
98
import {
109
ARCHITECTURE,
1110
CACHE_PREFIX,
12-
CYGWIN_MIRROR,
11+
CYGWIN_LOCAL_PACKAGE_DIRECTORY,
1312
CYGWIN_ROOT,
1413
DUNE_CACHE_ROOT,
14+
GITHUB_WORKSPACE,
1515
OPAM_DISABLE_SANDBOXING,
1616
OPAM_REPOSITORIES,
1717
OPAM_ROOT,
@@ -64,14 +64,12 @@ async function composeOpamCacheKeys() {
6464
}
6565

6666
function composeCygwinCachePaths() {
67-
const paths = [];
68-
const githubWorkspace = process.env.GITHUB_WORKSPACE ?? process.cwd();
69-
paths.push(CYGWIN_ROOT);
7067
const cygwinRootSymlinkPath = path.posix.join("/cygdrive", "d", "cygwin");
71-
paths.push(cygwinRootSymlinkPath);
72-
const cygwinEncodedUri = encodeURIComponent(CYGWIN_MIRROR).toLowerCase();
73-
const cygwinPackageRoot = path.join(githubWorkspace, cygwinEncodedUri);
74-
paths.push(cygwinPackageRoot);
68+
const paths = [
69+
CYGWIN_LOCAL_PACKAGE_DIRECTORY,
70+
CYGWIN_ROOT,
71+
cygwinRootSymlinkPath,
72+
];
7573
return paths;
7674
}
7775

@@ -81,7 +79,8 @@ function composeDuneCachePaths() {
8179
}
8280

8381
function composeOpamCachePaths() {
84-
const paths = [OPAM_ROOT];
82+
const opamLocalCachePath = path.join(GITHUB_WORKSPACE, "_opam");
83+
const paths = [OPAM_ROOT, opamLocalCachePath];
8584
if (PLATFORM === "windows") {
8685
const {
8786
repo: { repo },
@@ -96,9 +95,6 @@ function composeOpamCachePaths() {
9695
);
9796
paths.push(opamCygwinLocalCachePath);
9897
}
99-
const githubWorkspace = process.env.GITHUB_WORKSPACE ?? process.cwd();
100-
const opamLocalCachePath = path.join(githubWorkspace, "_opam");
101-
paths.push(opamLocalCachePath);
10298
return paths;
10399
}
104100

packages/setup-ocaml/src/constants.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ export const PLATFORM = (() => {
5050

5151
export const CYGWIN_MIRROR = "https://cygwin.mirror.constant.com/";
5252

53+
export const GITHUB_WORKSPACE = process.env.GITHUB_WORKSPACE ?? process.cwd();
54+
55+
export const CYGWIN_LOCAL_PACKAGE_DIRECTORY = (() => {
56+
const cygwinMirrorEncodedUri =
57+
encodeURIComponent(CYGWIN_MIRROR).toLowerCase();
58+
return path.join(GITHUB_WORKSPACE, cygwinMirrorEncodedUri);
59+
})();
60+
5361
// [HACK] https://github.com/ocaml/setup-ocaml/pull/55
5462
export const CYGWIN_ROOT = path.join("D:", "cygwin");
5563

packages/setup-ocaml/src/windows.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1+
import * as fs from "node:fs/promises";
2+
import * as os from "node:os";
3+
import * as path from "node:path";
14
import * as core from "@actions/core";
25
import { exec } from "@actions/exec";
36
import { HttpClient } from "@actions/http-client";
47
import * as io from "@actions/io";
58
import * as toolCache from "@actions/tool-cache";
69
import * as cheerio from "cheerio";
710
import * as semver from "semver";
8-
import { CYGWIN_MIRROR, CYGWIN_ROOT } from "./constants.js";
11+
import {
12+
CYGWIN_LOCAL_PACKAGE_DIRECTORY,
13+
CYGWIN_MIRROR,
14+
CYGWIN_ROOT,
15+
} from "./constants.js";
916

1017
function createHttpClient() {
1118
return new HttpClient(
@@ -30,8 +37,27 @@ export async function getCygwinVersion() {
3037
return version;
3138
}
3239

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+
await fs.appendFile(globalGitIgnorePath, CYGWIN_LOCAL_PACKAGE_DIRECTORY, {
49+
encoding: "utf8",
50+
});
51+
await exec(
52+
"git",
53+
["config", "--add", "--global", "core.excludesfile", globalGitIgnorePath],
54+
{ windowsVerbatimArguments: true },
55+
);
56+
}
57+
3358
export async function setupCygwin() {
3459
await core.group("Prepare the Cygwin environment", async () => {
60+
await setGitToIgnoreCygwinLocalPackageDirectory();
3561
const version = await getCygwinVersion();
3662
const cachedPath = toolCache.find("cygwin", version, "x86_64");
3763
if (cachedPath === "") {

0 commit comments

Comments
 (0)