Skip to content

Commit

Permalink
Merge pull request #843 from ocaml/fix-global-ignore-for-self-hosted-…
Browse files Browse the repository at this point in the history
…runner

Fix global Git ignore for self-hosted runner
  • Loading branch information
smorimoto committed Aug 5, 2024
2 parents e72529f + 26d24f4 commit 931c810
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 30 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to

## [unreleased]

### Fixed

- Fix global Git ignore for self-hosted runner.

## [3.0.5]

### Changed
Expand Down
31 changes: 22 additions & 9 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions dist/post/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions packages/setup-ocaml/src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as system from "systeminformation";
import {
ARCHITECTURE,
CACHE_PREFIX,
CYGWIN_LOCAL_PACKAGE_DIRECTORY,
CYGWIN_MIRROR_ENCODED_URI,
CYGWIN_ROOT,
DUNE_CACHE_ROOT,
GITHUB_WORKSPACE,
Expand Down Expand Up @@ -65,9 +65,13 @@ async function composeOpamCacheKeys() {

function composeCygwinCachePaths() {
const cygwinRootSymlinkPath = path.posix.join("/cygdrive", "d", "cygwin");
const cygwinLocalPackageDirectory = path.join(
GITHUB_WORKSPACE,
CYGWIN_MIRROR_ENCODED_URI,
);
const paths = [
CYGWIN_LOCAL_PACKAGE_DIRECTORY,
CYGWIN_ROOT,
cygwinLocalPackageDirectory,
cygwinRootSymlinkPath,
];
return paths;
Expand Down
7 changes: 2 additions & 5 deletions packages/setup-ocaml/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,8 @@ export const CYGWIN_MIRROR = "https://cygwin.mirror.constant.com/";

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

export const CYGWIN_LOCAL_PACKAGE_DIRECTORY = (() => {
const cygwinMirrorEncodedUri =
encodeURIComponent(CYGWIN_MIRROR).toLowerCase();
return path.join(GITHUB_WORKSPACE, cygwinMirrorEncodedUri);
})();
export const CYGWIN_MIRROR_ENCODED_URI =
encodeURIComponent(CYGWIN_MIRROR).toLowerCase();

// [HACK] https://github.com/ocaml/setup-ocaml/pull/55
export const CYGWIN_ROOT = path.join("D:", "cygwin");
Expand Down
31 changes: 22 additions & 9 deletions packages/setup-ocaml/src/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import * as toolCache from "@actions/tool-cache";
import * as cheerio from "cheerio";
import * as semver from "semver";
import {
CYGWIN_LOCAL_PACKAGE_DIRECTORY,
CYGWIN_MIRROR,
CYGWIN_MIRROR_ENCODED_URI,
CYGWIN_ROOT,
} from "./constants.js";

Expand Down Expand Up @@ -45,14 +45,27 @@ async function setGitToIgnoreCygwinLocalPackageDirectory() {
: path.join(homeDir, ".config", "git");
await fs.mkdir(globalGitConfigDir, { recursive: true });
const globalGitIgnorePath = path.join(globalGitConfigDir, "ignore");
await fs.appendFile(globalGitIgnorePath, CYGWIN_LOCAL_PACKAGE_DIRECTORY, {
encoding: "utf8",
});
await exec(
"git",
["config", "--add", "--global", "core.excludesfile", globalGitIgnorePath],
{ windowsVerbatimArguments: true },
);
try {
await fs.access(globalGitIgnorePath, fs.constants.R_OK);
const contents = await fs.readFile(globalGitIgnorePath, {
encoding: "utf8",
});
if (!contents.includes(CYGWIN_MIRROR_ENCODED_URI)) {
await fs.appendFile(globalGitIgnorePath, CYGWIN_MIRROR_ENCODED_URI, {
encoding: "utf8",
});
}
} catch {
await fs.writeFile(globalGitIgnorePath, CYGWIN_MIRROR_ENCODED_URI, {
encoding: "utf8",
});
} finally {
await exec(
"git",
["config", "--add", "--local", "core.excludesfile", globalGitIgnorePath],
{ windowsVerbatimArguments: true },
);
}
}

export async function setupCygwin() {
Expand Down

0 comments on commit 931c810

Please sign in to comment.