Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix global Git ignore for self-hosted runner #843

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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