Skip to content

Commit

Permalink
Set Git to ignore Cygwin local package directory
Browse files Browse the repository at this point in the history
Signed-off-by: Sora Morimoto <[email protected]>
  • Loading branch information
smorimoto committed Aug 5, 2024
1 parent 9b25141 commit 33f6f5c
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 39 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]

### Changed

- Set Git to ignore Cygwin local package directory.

## [3.0.4]

### Changed
Expand Down
43 changes: 31 additions & 12 deletions dist/index.js

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

26 changes: 13 additions & 13 deletions dist/post/index.js

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

22 changes: 9 additions & 13 deletions packages/setup-ocaml/src/cache.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as crypto from "node:crypto";
import * as path from "node:path";
import * as process from "node:process";
import * as cache from "@actions/cache";
import * as core from "@actions/core";
import { exec } from "@actions/exec";
Expand All @@ -9,9 +8,10 @@ import * as system from "systeminformation";
import {
ARCHITECTURE,
CACHE_PREFIX,
CYGWIN_MIRROR,
CYGWIN_LOCAL_PACKAGE_DIRECTORY,
CYGWIN_ROOT,
DUNE_CACHE_ROOT,
GITHUB_WORKSPACE,
OPAM_DISABLE_SANDBOXING,
OPAM_REPOSITORIES,
OPAM_ROOT,
Expand Down Expand Up @@ -64,14 +64,12 @@ async function composeOpamCacheKeys() {
}

function composeCygwinCachePaths() {
const paths = [];
const githubWorkspace = process.env.GITHUB_WORKSPACE ?? process.cwd();
paths.push(CYGWIN_ROOT);
const cygwinRootSymlinkPath = path.posix.join("/cygdrive", "d", "cygwin");
paths.push(cygwinRootSymlinkPath);
const cygwinEncodedUri = encodeURIComponent(CYGWIN_MIRROR).toLowerCase();
const cygwinPackageRoot = path.join(githubWorkspace, cygwinEncodedUri);
paths.push(cygwinPackageRoot);
const paths = [
CYGWIN_LOCAL_PACKAGE_DIRECTORY,
CYGWIN_ROOT,
cygwinRootSymlinkPath,
];
return paths;
}

Expand All @@ -81,7 +79,8 @@ function composeDuneCachePaths() {
}

function composeOpamCachePaths() {
const paths = [OPAM_ROOT];
const opamLocalCachePath = path.join(GITHUB_WORKSPACE, "_opam");
const paths = [OPAM_ROOT, opamLocalCachePath];
if (PLATFORM === "windows") {
const {
repo: { repo },
Expand All @@ -96,9 +95,6 @@ function composeOpamCachePaths() {
);
paths.push(opamCygwinLocalCachePath);
}
const githubWorkspace = process.env.GITHUB_WORKSPACE ?? process.cwd();
const opamLocalCachePath = path.join(githubWorkspace, "_opam");
paths.push(opamLocalCachePath);
return paths;
}

Expand Down
8 changes: 8 additions & 0 deletions packages/setup-ocaml/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ export const PLATFORM = (() => {

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);
})();

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

Expand Down
28 changes: 27 additions & 1 deletion packages/setup-ocaml/src/windows.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import * as fs from "node:fs/promises";
import * as os from "node:os";
import * as path from "node:path";
import * as core from "@actions/core";
import { exec } from "@actions/exec";
import { HttpClient } from "@actions/http-client";
import * as io from "@actions/io";
import * as toolCache from "@actions/tool-cache";
import * as cheerio from "cheerio";
import * as semver from "semver";
import { CYGWIN_MIRROR, CYGWIN_ROOT } from "./constants.js";
import {
CYGWIN_LOCAL_PACKAGE_DIRECTORY,
CYGWIN_MIRROR,
CYGWIN_ROOT,
} from "./constants.js";

function createHttpClient() {
return new HttpClient(
Expand All @@ -30,8 +37,27 @@ export async function getCygwinVersion() {
return version;
}

async function setGitToIgnoreCygwinLocalPackageDirectory() {
const xdgConfigHome = process.env.XDG_CONFIG_HOME;
const homeDir = os.homedir();
const globalGitConfigDir = xdgConfigHome
? path.join(xdgConfigHome, "git")
: 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", "--local", "core.excludesfile", globalGitIgnorePath],
{ windowsVerbatimArguments: true },
);
}

export async function setupCygwin() {
await core.group("Prepare the Cygwin environment", async () => {
await setGitToIgnoreCygwinLocalPackageDirectory();
const version = await getCygwinVersion();
const cachedPath = toolCache.find("cygwin", version, "x86_64");
if (cachedPath === "") {
Expand Down

0 comments on commit 33f6f5c

Please sign in to comment.