Skip to content

Commit 931c810

Browse files
authored
Merge pull request #843 from ocaml/fix-global-ignore-for-self-hosted-runner
Fix global Git ignore for self-hosted runner
2 parents e72529f + 26d24f4 commit 931c810

File tree

6 files changed

+59
-30
lines changed

6 files changed

+59
-30
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+
### Fixed
12+
13+
- Fix global Git ignore for self-hosted runner.
14+
1115
## [3.0.5]
1216

1317
### Changed

dist/index.js

Lines changed: 22 additions & 9 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: 3 additions & 5 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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as system from "systeminformation";
88
import {
99
ARCHITECTURE,
1010
CACHE_PREFIX,
11-
CYGWIN_LOCAL_PACKAGE_DIRECTORY,
11+
CYGWIN_MIRROR_ENCODED_URI,
1212
CYGWIN_ROOT,
1313
DUNE_CACHE_ROOT,
1414
GITHUB_WORKSPACE,
@@ -65,9 +65,13 @@ async function composeOpamCacheKeys() {
6565

6666
function composeCygwinCachePaths() {
6767
const cygwinRootSymlinkPath = path.posix.join("/cygdrive", "d", "cygwin");
68+
const cygwinLocalPackageDirectory = path.join(
69+
GITHUB_WORKSPACE,
70+
CYGWIN_MIRROR_ENCODED_URI,
71+
);
6872
const paths = [
69-
CYGWIN_LOCAL_PACKAGE_DIRECTORY,
7073
CYGWIN_ROOT,
74+
cygwinLocalPackageDirectory,
7175
cygwinRootSymlinkPath,
7276
];
7377
return paths;

packages/setup-ocaml/src/constants.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,8 @@ export const CYGWIN_MIRROR = "https://cygwin.mirror.constant.com/";
5252

5353
export const GITHUB_WORKSPACE = process.env.GITHUB_WORKSPACE ?? process.cwd();
5454

55-
export const CYGWIN_LOCAL_PACKAGE_DIRECTORY = (() => {
56-
const cygwinMirrorEncodedUri =
57-
encodeURIComponent(CYGWIN_MIRROR).toLowerCase();
58-
return path.join(GITHUB_WORKSPACE, cygwinMirrorEncodedUri);
59-
})();
55+
export const CYGWIN_MIRROR_ENCODED_URI =
56+
encodeURIComponent(CYGWIN_MIRROR).toLowerCase();
6057

6158
// [HACK] https://github.com/ocaml/setup-ocaml/pull/55
6259
export const CYGWIN_ROOT = path.join("D:", "cygwin");

packages/setup-ocaml/src/windows.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import * as toolCache from "@actions/tool-cache";
99
import * as cheerio from "cheerio";
1010
import * as semver from "semver";
1111
import {
12-
CYGWIN_LOCAL_PACKAGE_DIRECTORY,
1312
CYGWIN_MIRROR,
13+
CYGWIN_MIRROR_ENCODED_URI,
1414
CYGWIN_ROOT,
1515
} from "./constants.js";
1616

@@ -45,14 +45,27 @@ async function setGitToIgnoreCygwinLocalPackageDirectory() {
4545
: path.join(homeDir, ".config", "git");
4646
await fs.mkdir(globalGitConfigDir, { recursive: true });
4747
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-
);
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", "--local", "core.excludesfile", globalGitIgnorePath],
66+
{ windowsVerbatimArguments: true },
67+
);
68+
}
5669
}
5770

5871
export async function setupCygwin() {

0 commit comments

Comments
 (0)